006F
00 | STACKADDR: word 0F000           ; beginning of stack area
F0 | 
00 | INBUFADDR: word 0E000           ; beginning of input buffer area
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 | 
61 | LOWER_A:        byte 61              ; 61h = 97
41 | UPPER_A:        byte 41              ; 41h = 65
7A | LOWER_Z:        byte 7A              ; 7Ah = 122
5A | UPPER_Z:        byte 5A              ; 5Ah = 90 (unused; see TOLOWER)
20 | TOUPPER_STR:    LDBA R2 LOWER_A      ; void toupper_str (char *s)
21 | 
43 | 
00 | 
30 |                 LDBA R3 LOWER_Z
21 | 
45 | 
00 | 
40 |                 LDBA R4 UPPER_A
21 | 
44 | 
00 | 
51 | TOUPSTR_L1:     LDBR R5 R1
31 | 
16 |                 JMPZ TOUPSTR_END
C2 | 
5A |                 MV R5 R10
04 | 
2A |                 SUB R2 R10
41 | 
0C |                 JMPN TOUPSTR_NOLOW   ; s[i] < 'a'?
C4 | 
3A |                 MV R3 R10
04 | 
5A |                 SUB R5 R10
41 | 
06 |                 JMPN TOUPSTR_NOLOW   ; s[i] > 'z'?
C4 | 
25 |                 SUB R2 R5
41 | 
45 |                 ADD R4 R5
40 | 
51 |                 STBR R5 R1
33 | 
10 | TOUPSTR_NOLOW:  INC R1
48 | 
E6 |                 JMP TOUPSTR_L1
C1 | 
00 | TOUPSTR_END:    RET
C9 | 
F0 | START:     LDWA R15 STACKADDR   ; stack initialization
20 | 
00 | 
00 | 
F0 |            SPWR R15             ; NOTE: every function receives input
0E | 
10 |            LDWA R1 INBUFADDR
20 | 
02 | 
00 | 
10 |            PUSH R1
08 | 
00 |            CALL GETS
C8 | 
04 | 
00 | 
10 |            POP R1
09 | 
10 |            PUSH R1
08 | 
00 |            CALL TOUPPER_STR
C8 | 
47 | 
00 | 
10 |            POP R1
09 | 
10 |            PUSH R1
08 | 
00 |            CALL PUTS
C8 | 
22 | 
00 | 
10 |            POP R1
09 | 
00 |            HLT
CF | 
