0086
00 | STACKADDR: word 0F000           ; beginning of stack area
F0 | 
00 | DIV:       LDWI R0 0            ; int div (int a, int b)
10 | 
00 | 
00 | 
1F |            MV R1 R15
04 | 
F3 | L_DIV:     MV R15 R3
04 | 
23 |            SUB R2 R3
41 | 
06 |            JMPN END_DIV
C4 | 
2F |            SUB R2 R15
41 | 
00 |            INC R0
48 | 
F4 |            JMP L_DIV
C1 | 
00 | END_DIV:   RET
C9 | 
A0 | WRITENUM:  LDWI R10 1           ; void writenum (int n)
10 | 
01 | 
00 | 
B0 | L1_WRNUM:  LDWI R11 09
10 | 
09 | 
00 | 
1B |            SUB R1 R11
41 | 
14 |            JMPNN L2_WRNUM
C5 | 
20 |            LDWI R2 0A
10 | 
0A | 
00 | 
A0 |            PUSH R10
08 | 
00 |            CALL DIV
C8 | 
02 | 
00 | 
A0 |            POP R10
09 | 
01 |            MV R0 R1
04 | 
F0 |            PUSH R15
08 | 
A0 |            INC R10
48 | 
E4 |            JMP L1_WRNUM
C1 | 
B0 | L2_WRNUM:  LDWI R11 30
10 | 
30 | 
00 | 
1B |            ADD R1 R11
40 | 
B0 | L3_WRNUM:  OUTB R11 0000
83 | 
00 | 
00 | 
00 |            TSTO 0000
85 | 
00 | 
00 | 
A0 |            DEC R10
49 | 
04 |            JMPZ E_WRNUM
C2 | 
10 |            POP R1               ; was R15, stored in the stack
09 | 
EA |            JMP L2_WRNUM
C1 | 
00 | E_WRNUM:   RET
C9 | 
21 | PUTS:      LDBR R2 R1           ; void puts (char *str)
31 | 
0E |            JMPZ END_PUTS
C2 | 
20 | L_PUTS:    OUTB R2 0000
83 | 
00 | 
00 | 
00 |            TSTO 0000     
85 | 
00 | 
00 | 
F6 |            JMPNZ L_PUTS
C3 | 
10 |            INC R1
48 | 
EE |            JMP PUTS
C1 | 
20 | END_PUTS:  LDBI R2 0A
11 | 
0A | 
20 | LEND_PUTS: OUTB R2 0000
83 | 
00 | 
00 | 
00 |            TSTO 0000     
85 | 
00 | 
00 | 
F6 |            JMPNZ LEND_PUTS
C3 | 
00 |            RET
C9 | 
10 | ABS:       MV R1 R0          ; int abs (int a)
04 | 
02 |            JMPN ABS_NEG
C4 | 
06 |            JMP END_ABS
C1 | 
00 | ABS_NEG:   LDWI R0 0
10 | 
00 | 
00 | 
10 |            SUB R1 R0
41 | 
00 | END_ABS:   RET
C9 | 
01 | N1:        word 08001
80 | 
01 | N2:        word 00001
00 | 
FF | N3:        word 0FFFF
FF | 
F0 | N4:        word 0FFF0
FF | 
20 | SPACE:     byte 020
F0 | START:     LDWA R15 STACKADDR   ; stack initialization
20 | 
00 | 
00 | 
F0 |            SPWR R15             ; NOTE: every function receives input
0E | 
10 |            LDWA R1 N1
20 | 
7D | 
00 | 
00 |            CALL ABS
C8 | 
6F | 
00 | 
01 |            MV R0 R1
04 | 
00 |            CALL WRITENUM
C8 | 
16 | 
00 | 
10 |            LDBA R1 SPACE
21 | 
85 | 
00 | 
00 |            CALL PUTS
C8 | 
4E | 
00 | 
10 |            LDWA R1 N2
20 | 
7F | 
00 | 
00 |            CALL ABS
C8 | 
6F | 
00 | 
01 |            MV R0 R1
04 | 
00 |            CALL WRITENUM
C8 | 
16 | 
00 | 
10 |            LDBA R1 SPACE
21 | 
85 | 
00 | 
00 |            CALL PUTS
C8 | 
4E | 
00 | 
10 |            LDWA R1 N3
20 | 
81 | 
00 | 
00 |            CALL ABS
C8 | 
6F | 
00 | 
01 |            MV R0 R1
04 | 
00 |            CALL WRITENUM
C8 | 
16 | 
00 | 
10 |            LDBA R1 SPACE
21 | 
85 | 
00 | 
00 |            CALL PUTS
C8 | 
4E | 
00 | 
10 |            LDWA R1 N4
20 | 
83 | 
00 | 
00 |            CALL ABS
C8 | 
6F | 
00 | 
01 |            MV R0 R1
04 | 
00 |            CALL WRITENUM
C8 | 
16 | 
00 | 
10 |            LDBA R1 SPACE
21 | 
85 | 
00 | 
00 |            CALL PUTS
C8 | 
4E | 
00 | 
00 |            HLT
CF | 
