;========================================= ; LMC Sample Program #1 - add and subtract ;========================================= ; - 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. ; ; The "ORG" (origin) mnemonic is not an LMC instruction. It is used by ; assembly language programmers to indicate that the next instructions ; or data will be placed into memory starting at the given address. ; ; 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. ; ; Output: 7 - 15 + 2 = 994 (using 3-digit odometer math; no negative numbers) ; ;Loc. Code Label Mnemon. Operand Comments ;---- ---- ----- ------- ------- ------------------------- 00 162 LDA 62 ; load first number 01 463 SUB 63 ; subract second number 02 364 ADD 64 ; add third number 03 600 OUT ; output result 04 700 HLT ; put LMC to sleep (stop execution) ORG 62 ; place next data starting at box 62 62 007 DAT 007 ; first number (constant) 63 015 DAT 015 ; second number (constant) 64 002 DAT 002 ; third number (constant) ; 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 162 DAT 162 ; load first number 01 463 DAT 463 ; subract second number 02 364 DAT 364 ; add third number 03 600 DAT 600 ; output result 04 700 DAT 700 ; put LMC to sleep (stop execution) ORG 62 ; place next data starting at box 62 62 007 DAT 007 ; first number (constant) 63 015 DAT 015 ; second number (constant) 64 002 DAT 002 ; third number (constant)