-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection.asm
More file actions
39 lines (32 loc) · 814 Bytes
/
selection.asm
File metadata and controls
39 lines (32 loc) · 814 Bytes
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
# Written by Austin Staton
# Used in Intro. to Computer Architecture (CSCE 212) at the UofSC
# Translation of (from C):
# if (a < 20) {
# val = (val & 0xFFFF) * 16;
# } else {
# val = (val >> 16) + 10;
# }
.data
a: .word 19
val: .word 10
.text
lw $t0, a
bgt $t0, 20, else # If a < 20, go to the else statement.
lw $s0, val # Get val from memory.
and $s0, $s0, 0xFFFF # AND val and 0xFFFF (111...1111) = val
mul $s0, $s0, 16 # $s0 = val*16
sw $s0, val
return:
#***Print to Check - Ignore for solution***
li $v0, 1
lw $s2, val
add $a0, $zero, $s2
syscall
#******************************************
li $v0, 10 # End program call.
syscall
else: lw $s0, val
srl $s0, $s0, 16 # Shift right 16 bits "val >> 16"
addi $s0, $s0, 10
sw $s0, val
j return