Analyze the following program. When run, what does this program do? Your friend
ID: 3595541 • Letter: A
Question
Analyze the following program. When run, what does this program do? Your friend reviews the code and telling you there is a bug in the code. Can you identify the bug? What can you do to fix it?
PC: 35
Memory Location
Value
35
901 (INPUT)
36
381 (STORE 81)
37
901 (INPUT)
38
382 (STORE 82)
39
581 (LDA 81)
39
282 (SUB 82)
40
383 (STORE 83)
41
747 (BRZ 47)
42
845 (BRP 45)
43
582 (LDA 82)
44
902 (OUTPUT A)
45
581 (LDA 81)
46
902 (OUTPUT A)
47
549 (LDA 49)
48
902 (OUTPUT A)
49
HALT
81
000
82
000
83
000
Memory Location
Value
35
901 (INPUT)
36
381 (STORE 81)
37
901 (INPUT)
38
382 (STORE 82)
39
581 (LDA 81)
39
282 (SUB 82)
40
383 (STORE 83)
41
747 (BRZ 47)
42
845 (BRP 45)
43
582 (LDA 82)
44
902 (OUTPUT A)
45
581 (LDA 81)
46
902 (OUTPUT A)
47
549 (LDA 49)
48
902 (OUTPUT A)
49
HALT
81
000
82
000
83
000
Explanation / Answer
There is a small error in given program.As per code BRZ condition is false,even it will still produce same for BRP. That means weather the condition is true or false it will output the same value.So to rectify this just put HALT after each OUTPUT A
747 (BRZ 47)
845 (BRP 45)
582 (LDA 82)
902 (OUTPUT A)
HALT
581 (LDA 81)
902 (OUTPUT A)
HALT
549 (LDA 49)
902 (OUTPUT A)
HALT
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.