Write MIPS code to search through array X of word size unsigned integers to find
ID: 3768620 • Letter: W
Question
Write MIPS code to search through array X of word size unsigned integers to find how many of the values are divisible by 4. Place the result is $s2 and print to screen. The array X ends with a zero. Include code that counts the number of ones in the binary number stored in $s2 from part A. Place the result in $s3. Print to screen. Example: X:. word 5, 4, 8,12,13,16,18, 20, 24,23,0 After execution $s2= 6 $s3 = 2 Printed to the screen: The number of values that are divisible by 4 = 6 The number of ones in the binary number = 2Explanation / Answer
.model small
.stack
.data
word db 4,8,12,13,16,18,20,24,23,0
message db "The number of values that are divisible by 4:", "$"
message_ones db "The number of ones in the binary number:", "$"
.code
main proc
mov ax,sef message
mov ds,ax
N equ 20
org $1000
total rmb 1
org $1500 ;just adding starting address
clr total ;initializing with zero
ldx #word ;use index registers x as array pointer
ldab #N
loop brclr 0,x,$03,yes
bra check
yes inc total ; incrementing total
check inx ;moving array pointer
dbne b.loop
forever bra forever
lea dx,message
int 21h
mov ax,total
int 21h
mov ax,seg message_ones
mov ds,ax
mov ah,total
lea dx,message_ones
int 21h
mov ax,4c00h
int 21h
main endp
end main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.