Command code | Command type | Actions |
---|---|---|
1xx | ADD | Add a number from the box xx to the battery. Raise the flag ZERO or POSITIVE NUMBER. If the result is greater than 999, then finish the job with an error. |
2xx | SUB | Subtract the number from the box xx from the battery. Raise the flag ZERO or POSITIVE NUMBER. If the result is less than 0, the battery does not change and the flags go down. |
3xx | Sta | Save the contents of the battery in the box xx. |
5xx | Lda | Load the number from box xx into the battery. Raise the flag ZERO or POSITIVE NUMBER. |
6xx | Bra | Set the command counter to xx. |
7xx | BRZ | If the flag is ZERO, then set the command counter to xx. |
8xx | BRP | If the flag is ZERO or POSITIVE NUMBER, then set the command counter to xx. |
901 | INP | Select the number from the INP window and write to the battery. Raise the flag ZERO or POSITIVE NUMBER. If the number does not fall in the range from 0 to 999, then finish the work with an error. |
902 | Out | Write the number of the battery on a piece of paper and put it in the OUT window. |
000 | Hlt | Finish the job. |
awk -f lmc.awk
LOAD ### [### ...] - load the program in codes DUMP - show memory contents RUN - run the program ASM <file name> - compile the program in assembler and download
LOAD 901 902 000 - copy the number from INP to OUT, stop LOAD 901 104 902 000 1 - add 1 to the number of INP, write to OUT, stop LOAD 901 902 704 600 000 - we copy numbers from INP to OUT, and stop working after printing 0
LOAD 901 902 0 DUMP 00: 901 902 0 0 0 0 0 0 0 0 10: 0 0 0 0 0 0 0 0 0 0 20: 0 0 0 0 0 0 0 0 0 0 30: 0 0 0 0 0 0 0 0 0 0 40: 0 0 0 0 0 0 0 0 0 0 50: 0 0 0 0 0 0 0 0 0 0 60: 0 0 0 0 0 0 0 0 0 0 70: 0 0 0 0 0 0 0 0 0 0 80: 0 0 0 0 0 0 0 0 0 0 90: 0 0 0 0 0 0 0 0 0 0 RUN INP: 100 OUT: 100
awk -f lmc.awk asm fib.lma 00: #Print fibonacci numbers 00: LDA ONE #Load init values 01: STA FIB1 #First number 02: STA FIB2 #Second number 03: OUT #Print first 04: OUT #Print second 05: LOOP LDA MAX #ACC=MAX 06: SUB FIB1 #ACC=ACC-FIB1 07: SUB FIB2 #ACC=ACC-FIB2 08: BRP CONT #ACC positive ? Continue 09: BRA END #Negative : goto end of program 10: CONT LDA FIB1 #ACC=FIB1 11: ADD FIB2 #ACC=ACC+FIB2 12: STA FIBN #Store FIBN - next number 13: OUT #Print it 14: LDA FIB2 #FIB1=FIB2 15: STA FIB1 16: LDA FIBN #FIB2=FIBN 17: STA FIB2 18: BRA LOOP #Next LOOP 19: END HLT 20: ONE DAT 1 #Init value 21: FIB1 DAT #First fib number 22: FIB2 DAT #Second fib number 23: FIBN DAT #Next fib number 24: MAX DAT 999 #Max computer number Labels: LOOP 05 MAX 24 FIB1 21 FIB2 22 FIBN 23 ONE 20 END 19 CONT 10 Xrefs: LOOP 18 MAX 5 FIB1 1 6 10 15 FIB2 2 7 11 14 17 FIBN 12 16 ONE 0 END 9 CONT 8 LOAD 520 321 322 902 902 524 221 222 810 619 521 122 323 902 522 321 523 322 605 0 1 0 0 0 999
Source: https://habr.com/ru/post/257331/
All Articles