-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab5.s
More file actions
190 lines (139 loc) · 2.71 KB
/
lab5.s
File metadata and controls
190 lines (139 loc) · 2.71 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
.global main
.section .data
name: .asciz "Cut-It-Up Saw\n"
cut: .asciz "Linear length of boards cut so far: %d inches\n"
infot: .asciz "\nBoards cut so far: %d \n"
info: .asciz "Current Board Lengths:\n"
item1: .asciz "One: %d inches\n"
item2: .asciz "two: %d inches\n"
item3: .asciz "Three: %d inches\n"
prompt: .asciz "length (6-144): "
not_enough: .asciz "Not enough wood.\n"
error: .asciz "Please enter a valid input.\n"
term: .asciz "Inventory levels have dropped below minimum levels and will now terminate. Waste is %d inches.\n"
fmt: .asciz "%d"
one: .int 144
two: .int 144
three: .int 144
req: .int 0
length: .int 0
total: .int 0
.section .text
main:
ldr r0, =name
BL printf
B loop
display:
MOV r11, lr
ldr r1, =total
ldr r1, [r1]
ldr r0, =infot
BL printf
ldr r1, =length
ldr r1, [r1]
ldr r0, =cut
BL printf
ldr r0, =info
BL printf
ldr r1, =one
ldr r1, [r1]
ldr r0, =item1
BL printf
ldr r1, =two
ldr r1, [r1]
ldr r0, =item2
BL printf
ldr r1, =three
ldr r1, [r1]
ldr r0, =item3
BL printf
MOV pc, r11
input:
MOV r11, lr
retry:
ldr r0, =prompt
BL printf
ldr r0, =fmt
ldr r1, =req
BL scanf
CMP r0, #1
BNE input_error
ldr r1, =req
ldr r1, [r1]
CMP r1, #6
BLT input_error
CMP r1, #144
BGT input_error
MOV pc, r11
input_error:
ldr r0, =error
BL printf
B retry
calculate:
MOV r11, lr
ldr r8, [r0]
ldr r9, =req
ldr r9, [r9]
MOV r1, #0
CMP r8, r9
MOVLT pc, lr
SUB r8, r8, r9
STR r8, [r0]
ldr r10, =total
ldr r8, [r10]
ADD r8, r8, #1
STR r8, [r10]
ldr r10, =length
ldr r8, [r10]
ADD r8, r8, r9
STR r8, [r10]
MOV r1, #1
MOV pc, r11
loop:
BL display
BL input
ldr r0, =one
BL calculate
CMP r1, #1
BEQ loop
ldr r0, =two
BL calculate
CMP r1, #1
BEQ loop
ldr r0, =three
BL calculate
CMP r1, #1
BEQ loop
LDR r0, =not_enough
BL printf
ldr r8, =one
ldr r8, [r8]
CMP r8, #5
BGT loop
ldr r8, =two
ldr r8, [r8]
CMP r8, #5
BGT loop
ldr r8, =three
ldr r8, [r8]
CMP r8, #5
BGT loop
B end
end:
BL display
MOV r8, #0
LDR r9, =one
LDR r9, [r9]
ADD r8, r8, r9
LDR r9, =two
LDR r9, [r9]
ADD r8, r8, r9
LDR r9, =three
LDR r9, [r9]
ADD r8, r8, r9
ldr r0, =term
MOV r1, r8
BL printf
MOV r7, #1
MOV r0, #0
SVC #0