-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi2f.snk
187 lines (146 loc) · 2.01 KB
/
i2f.snk
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
# Load MSB's and LSB's of int into R2 and R3
Assign 1
Ld R2
Assign 2
Ld R3
# Extract sign bit
Assign R2
Set R4
Assign 7
Sr R4
Sl R4
#### Get Exponent ####
# Start Exponent at max value of 29
Assign 29
Set R5
# Clear sign bit of int
Assign 1
Sl R2
Sr R2
# if int is equal to 0: return 0x0000 as float
Assign R2
Or R8
Assign R3
Or R8
Assign 8
BNZ R8
Clr R6
Clr R7
Assign 5
St R6
Assign 6
St R7
HALT
# if MSB[6] == 0 : shift left by 1 and decrement exponent(r5)
Assign R2
Set R6
Assign 6
Sr R6
Assign 13
BNZ R6
### MSB[6] == 0 :
## shift int(r2 and r3) left by 1
# Copy r3 into r7
Assign R3
Set R7
# shift r2 and r3
Assign 1
Sl R2
Sl R3
# get msb of r3 into r7
Assign 7
Sr R7
# put msb of r3 into lsb of r2
Assign R7
Or R2
# decrement exponent
Dec R5
# continue loop
Assign 17
Jmp R0
#### Get U,R,and S bits ####
# Copy R3 into R6,R7,and R8
Assign R3
Set R6
Set R7
Set R8
# extract U and R bits
Assign 4
Sr R6
Assign 3
Sr R7
Assign 1
And R6
And R7
# get bits below rounding bit
Assign 5
Sl R8
#### Rounding Logic ####
# branch if rounding bit(R7) is not 1
Assign 24
BZ R7
# branch if neither U nor S is 1 (add them together and check bz)
Assign R8
Add R6
Assign 20
BZ R6
# add 8 (1 to the 4th LSB Bit to Round)
Assign 8
Add R3
Adc R2
#### Overflow Logic ####
# if MSB[7](r6) == 1 : shift right by 1 and inc exp
Assign R2
Set R6
Assign 7
Sr R6
Assign 11
BZ R6
# copy R2 to R6
Assign R2
Set R6
# shift int(r2 and r3) by 1
Assign 1
Sr R2
Sr R3
# extract lsb of MSB bits
Assign 7
Sl R6
# assign msb of LSB bits to lsb of MSB bits
Assign R6
Or R3
# increment exponent
Inc R5
#### Set Final Float ####
# get R2[3:0] and R3[7:4] into R7
Assign R2
Set R7
Assign R3
Set R8
Assign 4
Sl R7
Sr R8
Assign R8
Or R7
# get exp bits in spots 6:2 of R5
Assign 2
Sl R5
# get 2-msb's after hidden(R2[5:4]) into spots 1:0
Assign 2
Sl R2
Assign 6
Sr R2
# get sign + exp + mantissa[9:8] into r6
Clr R6
Assign R4
Or R6
Assign R5
Or R6
Assign R2
Or R6
# store R6 and R7 into Mem[5] and Mem[6]
Assign 5
St R6
Assign 6
St R7
HALT