;=========================================== ; LMC Sample Program #2 - input, add, output ;=========================================== ; - Ian! D. Allen - idallen@idallen.ca - www.idallen.com ; ; We will use this 6-column format for all LMC programs. ; (We won't use the Label column yet.) ; Start by filling in the Mnemonic and Operand columns, then go back ; and "hand-assemble" the mnemonics into actual numbers in mailboxes. ; ; The "DAT" (data) mnemonic is not an LMC instruction. It is used by ; assembly language programmers to indicate that the given operand is data ; to be placed in memory at the current memory location. ; ; Note that the Negative light will come on after the subtraction. ; It will go off after the addition, because only subtracting a big ; number from a small number sets the Negative light. Addition can ; never set the Negative light. ; ; Note that this LMC program never accesses memory locations past 06. ; The numbers in mailboxes 07, 08, and 09 are never touched by the LMC. ; ; Input Queue (for "IN" statements): ; 024 ; 351 ; ; Output: 351 + 024 = 375 (using 3-digit odometer math; no negative numbers) ; ;Loc. Code Label Mnemon. Operand Comments ;---- ---- ----- ------- ------- ------------------------- 00 500 IN ; input first number 01 206 STO 06 ; save in memory 02 500 IN ; input second number 03 306 ADD 06 ; add first number 04 600 OUT ; output sum 05 700 HLT ; go to sleep 06 942 DAT 942 ; initialize memory with junk 07 600 DAT 600 ; initialize memory with junk 08 123 DAT 123 ; initialize memory with junk 09 132 DAT 132 ; initialize memory with junk ; Note that this program could have been written this way, though it is ; much harder to read since no helpful mnemonics are used: ; ;Loc. Code Label Mnemon. Operand Comments ;---- ---- ----- ------- ------- ------------------------- 00 500 DAT 500 ; input first number 01 206 DAT 206 ; save in memory 02 500 DAT 500 ; input second number 03 306 DAT 306 ; add first number 04 600 DAT 600 ; output sum 05 700 DAT 700 ; put LMC to sleep (stop execution) 06 942 DAT 942 ; initialize memory with junk 07 600 DAT 600 ; initialize memory with junk 08 123 DAT 123 ; initialize memory with junk 09 132 DAT 132 ; initialize memory with junk