Question: The following LC-3 program checks if the integer stored at memory location x5000 is divisible by 3. If yes, it stores the value 1 at

The following LC-3 program checks if the integer stored at memory location x5000" is divisible by 3. If yes, it stores the value 1 at memory location x5001, else it does nothing. Assume all the registers and the memory location x5001 have an initial value of 0.

a) (4 Points) Fill in the missing instructions of the code. Suggestion: Verify your solution by running it in PennSim.

0011 0000 0000 0000 ; Program starts at x3000

(i) ____ ____ ____ ____ ; Load value at x5000 into R0

(ii) ____ ____ ____ ____ ; Initialize R1 to 3

(iii) ____ ____ ____ ____ ; LOOP: calculate R0 - R1

(iv) ____ ____ ____ ____ ; Branch if positive to LOOP

(v) ____ ____ ____ ____ ; Branch if negative to HALT

(vi) ____ ____ ____ ____ ; Initialize R2 to 1

(vii) ____ ____ ____ ____; Store R2 to x5001

1111 0000 0010 0101 ; HALT

0101 0000 0000 0000 ; DATA1: x5000

(viii)____ ____ ____ ____; DATA2: x5001

b) (2 points) After the above program finishes execution, a value of 0 would mean that the integer at x5000 is not a multiple of 3. Does this program correctly identify all integers which are multiples of 3? If not, specify the integer(s) for which the program doesnt work, and why it does not work for those value(s).

c) (2 points) Briefly explain how you can fix the bug(s) identified in part b) ? Mention the names of the LC3 instructions, you would use to fix the bug

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!