This:
FORMAT MEANING 000 Stops the Computer - the Little Man rests. 1xx Adds the contents of mailbox xx to the calculator display. 2xx Subtracts the contents of mailbox xx from the calculator display. 3xx Stores the calculator value into mailbox xx. 4xx Stores the address portion of the calculator value (last 2 digits) into the address portion of the instruction in mailbox xx. 5xx Loads the contents of mailbox xx into the calculator. 6xx This instruction sets the instruction counter to the number xx, thus effectively branching to mailbox xx 7xx IF the calculator value is zero, THEN set the instruction counter to the number xx, thus effectively branching to mailbox xx. 8xx IF the calculator value is positive (or zero), THEN set the instruction counter to the number xx, thus effectively branching to mailbox xx. 901 Read a number from the IN basket and key it into the calculator. 902 Copy the number in the calculator onto a slip of paper and place it into the OUT basket.
is not part of the LMC-code. It's just description of the opcodes.
main:
; INPUT (1st number input)
li $v0, 5 # service #5 – input an integer
syscall
; STO 99 (to mailbox no 99)
move $t0, $v0
; INPUT (2nd number input)
li $v0, 5
syscall
; STO 98 (store to mailbox no 98)
move $t1, $v0
; SUB 99 (subtract 2nd number from 1st) - different subtraction order
sub $t2, $t1, $t0 # [t2]<- [t1]-[t0]
; BRANCH 09 (Branch to 09 if 2nd > 1st ) - maybe should be BRANCH 08?
bgtz $t2, BRCH # branch to BRCH if [t2]>0
; move result in "accu" (subtract again)
sub $a0, $t0, $t1
; continue to "08" using another branch (why?)
b CNT # branch to CNT
; LOAD 99 (load 1st)
; SUB 99 (subtract 2nd number from 1st) - should be SUB 98
BRCH: sub $a0, $t1, $t0
; continue to "09" (why?)
b CNT
; OUTOUT (output)
CNT: li $v0, 1 # service #1 – print integer
syscall
li $v0, 10 # service #10 – exit system
syscall
Like you see, the LMC code has errors, but basically here I commented the MIPS code with more or less equivalent pieces of LMC-code. Also both codes could be written somewhat better.
Does that help?