-
Notifications
You must be signed in to change notification settings - Fork 0
/
asm.s43
253 lines (198 loc) · 5.2 KB
/
asm.s43
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include "msp430.h" ; #define controlled include file
NAME main ; module name
PUBLIC main ; make the main label vissible
; outside this module
ORG 0FFFEh
DC16 init ; set reset vector to 'init' label
RSEG CSTACK ; pre-declaration of segment
RSEG CODE ; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP ; set up stack
main: NOP ; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
mov.w #0xB0,R4 ; 10110000 suma R13 + R10
;mov.w #0xC0,R4 ;2s R10
;mov.w #0xC4,R4 ;shiftR10
;mov.w #0xCC,R4 ; IN
;mov.w #0xE0,R4 ;OUT
; mov.w #0xF0,R4 ;JR30
mov.W #2,R13
mov.w #8,R10
decoder:
mov R4,R5
AND.b #11110000b,R5
cmp.b #11110000b,R5
jeq JR30
mov R4,R5
AND.b #11100000b,R5
cmp.b #11100000b,R5
jeq outsub
mov R4,R5
AND.b #11001100b,R5
cmp.b #11001100b,R5
jeq insub
mov R4,R5
AND.b #11000100b,R5
cmp.b #11000100b,R5
jeq shift_right_operation
mov R4,R5
AND.b #11000000b,R5
cmp.b #11000000b,R5
jeq twos_complement_operation
jl addsub
JR30:
mov #1,R8
insub:
mov R4,R5
AND.b #00000011b,R5
cmp.b #3,R5
jeq inR13
cmp.b #2,R5
jeq inR12
cmp.b #1,R5
jeq inR11
jl inR10
inR13:
mov &P1IN,R13
rra R13
inR13:
mov &P1IN,R12
rra R12
inR13:
mov &P1IN,R11
rra R11
inR13:
mov &P1IN,R10
rra R10
outsub:
mov #1,R8
addsub:
MOV R4,R14
AND #0x30, R14 ;decode dd
MOV R4,R9
AND #0x0C,R9 ;decode ss
call #load_operand
cmp.b #00000000b,R9
jeq add_R10
cmp.b #00000100b,R9
jeq add_R11
cmp.b #00001000b,R9
jeq add_R12
cmp.b #00001100b,R9
jeq add_R13
twos_complement_operation:
mov R4,R14
AND #00000011,R14
cmp.b #00000000b,R14
jeq Tws_R10
cmp.b #00000001b,R14
jeq Tws_R11
cmp.b #00000010b,R14
jeq Tws_R12
cmp.b #00000011b,R14
jeq Tws_R13
Tws_R10:
inv R10
inc R10
call ALU_RETURN ;Needs to be implemented, next step after alu is done
Tws_R11:
inv R11
inc R11
call ALU_RETURN
Tws_R12:
inv R12
inc R12
call ALU_RETURN
Tws_R13:
inv R13
inc R13
call ALU_RETURN
Tws_R14:
inv R14
inc R14
call ALU_RETURN
shift_right_operation:
mov R4,R14
AND #00000011,R14
cmp.b #00000000b,R14
jeq shift_R10
cmp.b #00000001b,R14
jeq shift_R11
cmp.b #00000010b,R14
jeq shift_R12
cmp.b #00000011b,R14
jeq shift_R13
shift_R10:
rra R10
shift_R11:
rra R11
shift_R12:
rra R12
shift_R13:
rra R13
ALU_RETURN:
load_operand:
cmp.b #00000000b, R14
jeq load_register_10
cmp.b #00010000b, R14
jeq load_register_11
cmp.b #00100000b, R14
jeq load_register_12
cmp.b #00110000b, R14
jeq load_register_13
load_register_10:
mov R10,15
ret
load_register_11:
mov R11,R15
ret
load_register_12:
mov R12,R15
ret
load_register_13:
mov R13,R15
ret
add_R10:
add R10,R15
call #store_result
ret
add_R11:
add R11,R15
call #store_result
ret
add_R12:
add R12,R15
call #store_result
ret
add_R13:
add R13,R15
call #store_result
ret
store_result:
cmp.b #00000000b, R14 ;I DONT THINK WE NEED THIS SINCE WE DONT WRITE TO R10
jeq store_R10
cmp.b #00010000b, R14
jeq store_R11
cmp.b #00100000b, R14
jeq store_R12
cmp.b #00110000b, R14
jeq store_R13
store_R10: ;AGAIN I DONT THIN THIS IS NECCESARY JUST ADDING TO KEEP CODE CONSISTENT CAN BE REMOVED
;MAYBE ADDING ERROR TEXT OR SOMETHING
mov R15,R8
mov R8,R10
ret
store_R11:
mov R15,R8
mov R8,R11
ret
store_R12:
mov R15,R8
mov R8,R12
ret
store_R13:
mov R15,R8
mov R8,R13
ret
JMP $ ; jump to current location '$'
; (endless loop)
END