0043
00 | STACKADDR: word 0F000           ; beginning of stack area
F0 | 
00 | STR:       word 0E000
E0 | 
00 | GETS:      LDBI R0 0A           ; void gets (char *str)
11 | 
0A | 
20 | L_GETS:    INB R2 0001
81 | 
01 | 
00 | 
00 |            TSTI 0001     
84 | 
01 | 
00 | 
F6 |            JMPNZ L_GETS
C3 | 
21 |            STBR R2 R1    
33 | 
02 |            SUB R0 R2
41 | 
04 |            JMPZ END_GETS   
C2 | 
10 |            INC R1
48 | 
EC |            JMP L_GETS
C1 | 
20 | END_GETS:  LDBI R2 0
11 | 
00 | 
21 |            STBR R2 R1    
33 | 
00 |            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 | 
F0 | START:     LDWA R15 STACKADDR   ; stack initialization
20 | 
00 | 
00 | 
F0 |            SPWR R15             ; NOTE: every function receives input
0E | 
10 |            LDWA R1 STR
20 | 
02 | 
00 | 
00 |            CALL GETS
C8 | 
04 | 
00 | 
10 |            LDWA R1 STR
20 | 
02 | 
00 | 
00 |            CALL REVERSE
C8 | 
63 | 
00 | 
10 |            LDWA R1 STR
20 | 
02 | 
00 | 
00 |            CALL PUTS
C8 | 
22 | 
00 | 
00 |            HLT
CF | 
1A | REVERSE:   MV R1 R10            ; make a copy of the string address
04 | 
00 |            XOR R0 R0
45 | 
00 |            PUSH R0              ; place a terminator in the stack
08 | 
2A | REV_L1:    LDBR R2 R10
31 | 
06 |            JMPZ REV_L2
C2 | 
20 |            PUSH R2
08 | 
A0 |            INC R10
48 | 
F6 |            JMP REV_L1
C1 | 
1A | REV_L2:    MV R1 R10
04 | 
20 | REV_L3:    POP R2
09 | 
06 |            JMPZ REV_END
C2 | 
2A |            STBR R2 R10
33 | 
A0 |            INC R10
48 | 
F6 |            JMP REV_L3
C1 | 
00 | REV_END:   RET
C9 | 
