-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.bin
119 lines (88 loc) · 1.97 KB
/
temp.bin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
.ORIG x3000
GETC
ADD R5, R0, #0
GETC
ADD R6, R0, #0
LEA R1, ADDR_CHARACTERS
FETCH_CHARACTER:
GETC
STR R0, R1, #0
ADD R1, R1, #1
ADD R3, R0, #-13
BRz END_LOOP_ADDR_CHARACTERS
BRnzp FETCH_CHARACTER
END_LOOP_ADDR_CHARACTERS:
LEA R1, ADDR_CHARACTERS
LD R4, BLOCK
AND R0, R0, #0
FIND_NEXT_CHAR:
LDR R3, R1, #0
ADD R2, R3, #-13 ; Dummy R2 for intermediate newline calculation
BRz START_PRINT
LD R0, BASE_ADDR
FIND_CHAR:
ADD R3, R3, #-1
BRzp SKIP
STR R0, R1, #0
ADD R1, R1, #1
BRnzp FIND_NEXT_CHAR
SKIP:
ADD R0, R0, R4
BRnzp FIND_CHAR
;RO for OUT and temp -7 op
;R1 for address
;R2 for store for bit shift
;R3 for column count
;R4 for row count
;R5-R6
;R7 not used because of JSR
START_PRINT:
ADD R2, R2, #-1 ; Since R2 = 0 and I want -1
STR R2, R1, #0 ; So newline not printed as char
LEA R1, ADDR_CHARACTERS
LOOP_COLUMN:
AND R3, R3, #0
LDR R2, R1, #0
BRn NEXT_LINE ; If it's a newline character, skip
; Offset calculation - 10-R4
NOT R7, R4
ADD R7, R7, #1
ADD R7, R7, #15
ADD R7, R7, #1
LDR R2,R1,#0 ;Use LDI
ADD R2, R2, R7 ; Offset for next string for characters
LDR R2,R2,#0
BRzp SET_OUTPUT_R5
BRn SET_OUTPUT_R6
LOOP_SAME_LINE:
ADD R3, R3, #1
ADD R2, R2, R2
BRzp SET_OUTPUT_R5
BRn SET_OUTPUT_R6
SET_OUTPUT_R5:
ADD R0, R5, #0
BRnzp OUTPUT
SET_OUTPUT_R6:
ADD R0, R6, #0
OUTPUT:
OUT
SHOULD_END_SUB_LOOP:
ADD R0, R3, #-7
BRz NEXT_CHAR
BRn LOOP_SAME_LINE
NEXT_CHAR:
ADD R1, R1, #1
BRnzp LOOP_COLUMN
NEXT_LINE:
LD R0, NEWLINE
OUT
LEA R1, ADDR_CHARACTERS
ADD R4, R4, #-1
BRp LOOP_COLUMN
HALT
BASE_ADDR .FILL x4000
BLOCK .FILL x0010
NEWLINE .FILL x000A
ADDR_CHARACTERS .BLKW 10
ADDRESSES .BLKW x0000
.END