LC-3 Programming in assembly 1. Assume a sequence of positive numbers is stored
ID: 2265913 • Letter: L
Question
LC-3 Programming in assembly 1. Assume a sequence of positive numbers is stored in consecutive memory locations, starting at memory address x3000. The sequence terminates with the value #-1 (xFFFF) a. What does this program do? What does it print to screen? We will not read more than 30 words ORIG x5000 LEA LD LDR NOT BRz ADD AND BRz PUTS BRnzp LOOP HALT RO, MESSAGE R1, TABLE R2 , R1 , #0 R3, R2 FINISH R1, R1, #1 R2 , R2 , #1 LOOP 4 LOOP 10 12 13 14 FINISH MESSAGE TABLE STRINGZ "Found! " FILL x3000 END b. Write a symbol table for the code above. Your symbol table should be similar in nature to that produced by the LC-3 assembler: for each label that appears in the code, your table should list the label and associate the label with an address in LC-3 memory. For an example, see P&P; Section 7.3.3, pp. 186-187.Explanation / Answer
Answer:-a) The above program is displaying a message "Found!" for each odd number present in sequence. The program gets terminated when a value -1 is found.
AND R2, R2, #1 ; This instruction is being used to check for even odd. This will give us the LSB bit value. If bit is zero then even number else odd number.
BRz is used to jump to label "LOOP" is even i.e zero flag has been set. Note zero flag sets only when result of an operation is zero.
Instruction, NOT R3, R2 is used for checking whether value read is -1, if value read is -1 then it's inverted value will be zero since -1 has all bits 1 in it's binary.
For part b please post the example. Be feel.free to ask doubt if any. Thanks.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.