Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote