;------------------------------------------ ; LMC Sample Program #4 - input, IF, output ;------------------------------------------ ; -Ian! D. Allen - idallen@idallen.ca - www.idallen.com ; ; Some simple random C++ code, translated to LMC assembly language. ; ; int first; ; int second; ; cin >> first; ; cin >> second; ; if ( second <= first ) { ; cout << ++first + second; ; } ; cout << second-- + first + 3; ; ;Label Mnem. Operand Comments............. ;----- ----- ------- --------------------- ; cin >> first; IN ; read and store first number STO FIRST ; cin >> second; IN ; read and store second number STO SECOND ; if ( second <= first ) { LDA FIRST ; if second is <= first SUB SECOND SKP ; skip *into* IF statement if second is <= first JMP ENDIF ; go to ENDIF if second > first ; cout << ++first + second; LDA FIRST ; pre-increment of FIRST ADD ONE STO FIRST LDA FIRST ; addition of FIRST and SECOND and output ADD SECOND OUT ; } ; cout << second-- + first + 3; ENDIF LDA SECOND ; addition of SECOND, FIRST, and 3 and output ADD FIRST ADD THREE OUT LDA SECOND ; post-decrement of SECOND SUB ONE STO SECOND HLT ; constants: ONE DAT 001 ; constant 1 THREE DAT 003 ; constant 3 ; variables: FIRST DAT ? ; int first; SECOND DAT ? ; int second;