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

Write a little man computer that accepts three values as input and outputs them

ID: 3801982 • Letter: W

Question

Write a little man computer that accepts three values as input and outputs them in order of size, largest to smallest.

Here is code that I have that accepts three values and outputs the largest. Can you modify this code so that it outputs all 3 values in order of size, largest to smallest?

00      INP

01      STA 20

02      INP

03      STA 21

04      INP

05      STA 22

06      LDA 20

07      SUB 21

08      BRP 11

09      LDA 21

10      BRA 12

11      LDA 20

12      STA 23

13      SUB 22

14      BRP 17

15      LDA 22

16      BRA 18

17      LDA 23

18      OUT

19      HLT

20      DAT 00

21      DAT 00

22      DAT 00

23      DAT 00

Explanation / Answer

"//" this represents a comment to help you understand

00 INP
01 STA 20 // 20=A, 21=B, 22=C
02 INP
03 STA 21
04 INP
05 STA 22
06       LDA 21
07       SUB 22
08       BRP 15 // compare B and C,if C>B, swap B and C
09       LDA 21
10       STA 30 // temp storage 30=TEMP
11       LDA 22
12       STA 21
13       LDA 30
14       STA 22

15       LDA 20
16       SUB 21
17       BRP 24 // compare A and B, if B>A, A and B
18       LDA 20
19       STA 30
20       LDA 21
21       STA 20
22       LDA 30
23       STA 21

24       LDA 21
25       SUB 22
26       BRP 33 // compare B and C, if C>B, swap B and C
27       LDA 21
28       STA 30
29       LDA 22
30       STA 21
31       LDA 30
32       STA 22
      
33       LDA 20 // output the numbers in order A,B,C i.e. largest to smallest
34       OUT
35       LDA 21
36       OUT
37       LDA 22
38       OUT
39       HLT
40       DAT 00
41       DAT 00
42       DAT 00
43       DAT 00

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