Question

In: Computer Science

Write an assembly code the counts the number of accuracies of the byte AAh in memory...

Write an assembly code the counts the number of accuracies of the byte AAh in memory from address 120Ah to address 130Ah. You need to use a subroutine and call it 'COUNT' to do so. You also need to provide the count in BCD if it was less than 64h so that you need to include another subroutine called 'ToBCD' to do so.
assembly 8086

Solutions

Expert Solution

Greetings!!

Code:

;MAIN STARTS HERE

.CODE
MOV AX,@DATA
MOV DS,AX
  
CALL COUNT ;calling COUNT procedure to count the occurance of AA
  
HLT

;MAIN ENDS HERE

;procedure count definition
PROC COUNT NEAR
  
MOV AX,0 ;initialize AX with 0 for counting
MOV CX,100 ;load count into CX register[130A-120A=100].
MOV SI,120AH ;load the starting address into SI for reading the element from the memory
NEXT:
MOV BL,[SI] ;load the number into BL
INC SI ;point to next element in the memory
CMP AL,99H ;check the count less than 99
JNE CONTINUE ;if not 99 then continue   
CALL TOBCD ;if 99 call TOBCD procedure
CONTINUE:   
CMP BL,0AAH ;compare the number loaded from memory is AA or not
JNZ SKIP ;if not AA then skip
ADD AL,1 ;if AA, then increment the COUNT in AL
DAA ;adjust to BCD after each addition
SKIP:   
LOOP NEXT ;repeat the process
  
RET


;DEFINITION OF TOBCD FUNCTION   
PROC TOBCD NEAR

INC AH ;increment AH if the count in AL is 99
MOV AL,00 ;clear the AL count and start from 0 again
RET

Output screenshot:

Tested with more than 100 elements Iin an array and the count is shown below

Hope this helps


Related Solutions

Please write a pep/9 assembly code that checks if a word or number is a palindrome
Please write a pep/9 assembly code that checks if a word or number is a palindrome
Assume a 222 byte memory: a. What are the lowest and highest addresses if memory is...
Assume a 222 byte memory: a. What are the lowest and highest addresses if memory is byte-addressable? b. What are the lowest and highest addresses if memory is word-addressable, assuming a 16-bit word? c. What are the lowest and highest addresses if memory is word-addressable, assuming a 32-bit word? Explain with Steps please
arduino c code only write a code that counts down a timer on serial monitor and...
arduino c code only write a code that counts down a timer on serial monitor and if A1 is typed into serial monitor prints the timer counting down and writes at 1 second hello and at 5 secs goodbye and repeats every 5 secs A2 is typed as above at 2 seconds writes hello and 3 seconds writes goodbye A3 same as above but at 3 seconds says hello and 2 seconds goodbye This continues until c is pressed to...
How to write fill.asm code (hack assembly)
How to write fill.asm code (hack assembly)
C code required * byteSwap - swaps the nth byte and the mth byte * Examples:...
C code required * byteSwap - swaps the nth byte and the mth byte * Examples: byteSwap(0x12345678, 1, 3) = 0x56341278 * byteSwap(0xDEADBEEF, 0, 2) = 0xDEEFBEAD * You may assume that 0 <= n <= 3, 0 <= m <= 3 * Legal ops: ! ~ & ^ | + << >> * Max ops: 25 * Rating: 2 */
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code that transmits a single character and lights the red LED upon receiving that character. The board will "talk" to itself. The green LED should turn on whenever a message is sent and the LCD will display the message being received.
Write assembly code for the following machine code. Assume that the segment is placed starting at...
Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual memory addresses represented by such labels. 0010 1010 0000 1000 0000 0000 0000 1010 0001 0001 0000 0000 0000 0000 0000 0010 0000 0010 0001 0001 1000 0000 0010 0000 0000 1000 0000 0000 0100 1110 0010 0101 0000 0010 0001 0010 1000 0000 0010 0000
a. Write machine code for the following assembly code. Assume that the segment is placed starting...
a. Write machine code for the following assembly code. Assume that the segment is placed starting at location 80000. Use decimal numbers to represent each instruction. loop:         beq $s3, $s1, endwhile                  add $t0, $s3, $s4                  lw $t1, 0($t0)                  add $s0, $s0, $t1                  addi $s3, $s3, 4                  j loop endwhile: b. Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual...
write a verilog code to implement a digital system that has an odd counter that counts...
write a verilog code to implement a digital system that has an odd counter that counts from 1 to 11. Also, this system has an output Y that detects a specific number in the odd counter. Test your code when you detect the number 3, the output Y is 1, if the counter value is set to 3, otherwise 0.
Write a C program that counts the number of repeated characters in a phrase entered by...
Write a C program that counts the number of repeated characters in a phrase entered by the user and prints them. If none of the characters are repeated, then print “No character is repeated” For example: If the phrase is “full proof” then the output will be Number of characters repeated: 3 Characters repeated: f, l, o Note: Assume the length of the string is 10. ###Note: the output should print exactly as it is stated in the example if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT