source: branches/CpuSingleSize/Sample.asm

Last change on this file was 220, checked in by chronos, 4 years ago
  • Added: Devices form with tree view of connected devices. Device control form can be opened by double click.
  • Modifid: IN/OUT instructions now use also device group index to directly specify which device should be read/written.
File size: 2.0 KB
Line 
1 DB Start, KeyInterrupt, 'ABC', 123
2 NOP
3 NOP
4 NOP
5
6 VAR DeviceConsole 1
7 VAR ConsoleReadChar 0
8 VAR ConsoleWriteChar 0
9
10 VAR DeviceKeyboard 2
11
12 VAR DeviceScreen 3
13 VAR ScreenGetWidth 0
14 VAR ScreenGetHeight 1
15 VAR ScreenSetAddr 0
16 VAR ScreenWrite 1
17
18 ORG 16
19Start:
20
21; Example code
22; NOP
23;LOOP:
24 ;SET R0, 123
25 ;SET R1, 1024
26 ;SET R2, 32
27 ;ST R2, R1
28 ;JNZ R0, LOOP
29 ;SET R0, 124
30 ;JNZ R0, LOOP2
31 ;SET R0, 6
32LOOP2:
33 SET R0, Hello
34 SET R1, 12
35 CALL WriteStr
36
37; SET R0, 0
38; SET R1, 128
39; SET R2, 16
40; CALL LDIR
41
42; SET R0, 256
43; SET R1, 16
44; SET R2, 127
45; CALL SETR
46
47 CALL ClearScreen
48
49System:
50 HALT
51 JP System
52
53
54
55LDIR:
56 PUSH R3
57LDIR_LOOP:
58 LD R3, (R0)
59 ST (R1), R3
60 INC R0
61 INC R1
62 DEC R2
63 JNZ R2, LDIR_LOOP
64 POP R3
65 RET
66
67SETR:
68 ST (R0), R2
69 INC R0
70 DEC R1
71 JNZ R1, SETR
72 RET
73
74WriteStr:
75 PUSH R2
76 PUSH R3
77 PUSH R4
78 SET R3, ConsoleWriteChar
79 SET R4, DeviceConsole
80WriteStrLoop:
81 LD R2, (R0)
82 OUT (R4: R3), R2
83 INC R0
84 DEC R1
85 JNZ R1, WriteStrLoop
86 POP R4
87 POP R3
88 POP R2
89 RET
90
91ClearScreen:
92 PUSH R0
93 PUSH R1
94 PUSH R2
95 PUSH R3
96 SET R0, ScreenSetAddr
97 SET R1, 0
98 SET R3, DeviceScreen
99 OUT (R3: R0), R1
100 SET R0, ScreenGetWidth
101 IN R1, (R3: R0)
102 SET R0, ScreenGetHeight
103 IN R2, (R3: R0)
104 MUL R2, R1
105 SET R0, ScreenWrite
106 SET R1, 120
107ClearScreenLoop:
108 OUT (R3: R0), R1
109 DEC R2
110 JNZ R2, ClearScreenLoop
111 POP R3
112 POP R2
113 POP R1
114 POP R0
115 RET
116
117Hello:
118 DB 'Hello friend'
119
120KeyInterrupt:
121 ; Echo key
122 PUSH R3
123 PUSH R2
124 PUSH R4
125 SET R4, DeviceConsole
126 SET R3, ConsoleReadChar
127 IN R2, (R4: R3)
128 SET R3, ConsoleWriteChar
129 OUT (R4: R3), R2
130 POP R4
131 POP R2
132 POP R3
133 RET
134
135Test:
136 LDI R0, (R1 + 1)
137 STI (R1 + 12), R2
Note: See TracBrowser for help on using the repository browser.