Needing help with this assignment. It needs to be in LC-3 assembly language. Wri
ID: 3916543 • Letter: N
Question
Needing help with this assignment. It needs to be in LC-3 assembly language.
Write an LC-3 assembly language program that counts the number of positive and negative numbers in a sequence of numbers that are stored beginning at address x3300. The last number in the sequence is 0. Your program must start at address x3000 The program's output must be the following 2 lines: Count of negative numbers: n Count of positive numbers: mmmm Where nnnn and mmm are the number of negative and positive numbers respectively Number of digits in nnnn and mmmm is not fixed. You can not assume any upper bounds on nnnn and nnnExplanation / Answer
.orig x6000
LD R2, SEQUENCE ; R2 = x3300
AND R1, R1, 0 ; R1 = 0 (clear before add) positive number
AND R3, R3, 0 ; R3 = 0 (clear before add) negative number
LOOP LDR R0, R2, 0 ; R0 <-- mem[R2 + 0] ;
CMPI R0, R0, 0
BRz LOOP_DONE
CMPI R0, R0, 0
BRn NEG ; if R0 < 0 then NEG
ADD R1, R1, 1 ; R1++
BR NEXT
NEG ADD R3, R3, 1 ; R3++
NEXT ADD R2, R2, 4
BR LOOP ; loop
LOOP_DONE LEA R0, msg_pos ;load the address of the msg_pos
PUTS ;Prints the message string
ADD R0, R1, 0
OUT
LOOP_DONE LEA R0, msg_neg ;load the address of the msg_pos
PUTS ;Prints the message string
ADD R0, R3, 0
OUT
HALT ; halt
SEQUENCE .fill x3300
msg_pos .STRINGZ " Count of negative numbers: "
msg_neg .STRINGZ " Count of positive numbers: "
.end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.