-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadInput.s
More file actions
198 lines (160 loc) · 3.4 KB
/
readInput.s
File metadata and controls
198 lines (160 loc) · 3.4 KB
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
.section .rodata
trainSetFile: .string "train-images.idx3-ubyte"
trainLabelFile: .string "train-labels.idx1-ubyte"
testSetFile: .string "t10k-images.idx3-ubyte"
testLabelFile: .string "t10k-labels.idx1-ubyte"
.section .bss
dim: .space 16
.align 12
.globl trainImages
trainImages: .space 47040000
.align 12
.globl testImages
testImages: .space 7840000
.align 12
.globl trainLabels
trainImages: .space 60000
.align 12
.globl testLabels
trainImages: .space 10000
.section .text
.globl _start
_start:
#------------ Reading Training Set ------------
# Opening the Train-Set
li a0, -100
la a1, trainSetFile
li a2, 0
li a3, 0
li a7, 56 # 56 = openat()
ecall
mv s0, a0 # S0 = fd
# Reading Train-Set Dimensions
la a1, dim
li a2, 16
li a7, 63 # 63 = read()
ecall
# Loading, Saving Train-Set Dimensions
la t0, dim
lw s1, 4(t0) # S1 = numPictures
rev8 s1, s1
lw s2, 8(t0) # S2 = Width
rev8 s2, s2
lw s3, 12(t0) # S3 = Height
rev8 s3, s3
# Calculating Number of Bytes to be Read
mul s4, s1, s2
mul s4, s4, s3 # S4 = NumBytesToBeRead
# Reading the Pixel Values into a single
# Contiguous Array
mv a0, s0
la a1, trainImages
mv a2, s4
li a7, 63
ecall
# For Checking if Valid Read
la t0, trainImages
lw t1, 152(t0) # Should be 0312 1212
rev8 t1, t1
# Closing the File
mv a0, s0
li a7, 57 # 57 = close()
ecall
#------------ Reading Test Set ------------
# Opening the Test-Set
li a0, -100
la a1, testSetFile
li a2, 0
li a3, 0
li a7, 56 # 56 = openat()
ecall
mv s0, a0 # S0 = fd
# Reading Test-Set Dimensions
la a1, dim
li a2, 16
li a7, 63 # 63 = read()
ecall
# Loading, Saving Test-Set Dimensions
la t0, dim
lw s1, 4(t0) # S1 = numPictures
rev8 s1, s1
lw s2, 8(t0) # S2 = Width
rev8 s2, s2
lw s3, 12(t0) # S3 = Height
rev8 s3, s3
# Calculating Number of Bytes to be Read
mul s4, s1, s2
mul s4, s4, s3 # S4 = NumBytesToBeRead
# Reading the Pixel Values into a single
# Contiguous Array
mv a0, s0
la a1, testImages
mv a2, s4
li a7, 63
ecall
# Closing the File
mv a0, s0
li a7, 57 # 57 = close()
ecall
#------------ Reading Train Labels ------------
# Opening the Train-Labels
li a0, -100
la a1, trainLabelFile
li a2, 0
li a3, 0
li a7, 56 # 56 = openat()
ecall
mv s0, a0 # S0 = fd
# Reading Train-Labels Dimensions
la a1, dim
li a2, 8
li a7, 63 # 63 = read()
ecall
# Loading, Saving Train-Labels Dimensions
la t0, dim
lw s1, 4(t0) # S1 = numLabels
rev8 s1, s1
# Reading the Pixel Values into a single
# Contiguous Array
mv a0, s0
la a1, trainLabels
mv a2, s1
li a7, 63
ecall
# Closing the File
mv a0, s0
li a7, 57 # 57 = close()
ecall
#------------ Reading Test Labels ------------
# Opening the Test-Labels
li a0, -100
la a1, testLabelFile
li a2, 0
li a3, 0
li a7, 56 # 56 = openat()
ecall
mv s0, a0 # S0 = fd
# Reading Test-Labels Dimensions
la a1, dim
li a2, 8
li a7, 63 # 63 = read()
ecall
# Loading, Saving Test-Labels Dimensions
la t0, dim
lw s1, 4(t0) # S1 = numLabels
rev8 s1, s1
# Reading the Pixel Values into a single
# Contiguous Array
mv a0, s0
la a1, testLabels
mv a2, s1
li a7, 63
ecall
# Closing the File
mv a0, s0
li a7, 57 # 57 = close()
ecall
exit:
li a0, 0
li a7, 93 # 93 = exit()
ecall