What does the following LMC program do?
901 310 901 311 110 902 510 211 902 000
What about this one?
604 060 040 001 501 108 308 502 300 902 203 717 302 508 103 308 607 000
Maximum of two numbers.
INP
STA x
INP
STA y
SUB x
BRP second
LDA x
BRA done
second LDA y
done OUT
HLT
x DAT
y DAT
00 901 INP
01 311 STA x
02 901 INP
03 312 STA y
04 211 SUB x
05 808 BRP second
06 511 LDA x
07 609 BRA done
08 512 second LDA y
09 902 done OUT
10 000 HLT
11 x DAT
12 y DAT
901 311 901 312 211 808 511 609 512 902 000
INP
STA x
INP
STA y
loop BRZ done
LDA ans
ADD x
STA ans
LDA y
SUB one
STA y
BRA loop
done LDA ans
OUT
HLT
one DAT 1
ans DAT 0
x DAT
y DAT
Modify the program above to compute the minimum of the two numbers. Create a new "Markdown" cell below this cell, and enter your program there. Include both the assembler code and machine code for your program. (The idea is for you to practice working with the jupyter notebook interface as well as thinking about the algorithm.) The Little Man instruction set can be found here and the Little Man simulator here.
(HINT: To edit a Markdown cell, double click it. To stop editing and typeset the cell, press SHIFT+ENTER. You can learn more about the Markdown format under the "Help" menu above. See the above cell for formatting ideas for the program.)
00 INP
01 STA 11
02 INP
03 STA 12
04 SUB 11
05 BRP 08
06 BRZ 08
07 LDA 11
08 BRA 09
09 LDA 12
10 OUT
11 HLT
12 DAT 00
13 DAT 00
901 311 901 312 211 808 708 511 609 512 902 000