-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEs1.asm
57 lines (45 loc) · 1.03 KB
/
Es1.asm
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
# Write an assembly program that reads 3 values a, b and c memorised in memory at the "values" label. Store them in $t0, $t1, and $t2 registers and calculate:
# Sum of those 3 values if the first one is positive
# Prod of those 3 values if the first one is negative
# AND of second and third value is the first one is equal to zero
# Store the final value is the memory location after the last value.
.data
values: .word 8, 7, 8
mem: .word 0
.text
.globl main
main:
la $t5, values
lw $t0, 0($t5) # Loading values
lw $t1, 4($t5)
lw $t2, 8($t5)
# CASE 1
# pseudoinstruction
# bgt $t0, $r0, case1
# corrispondent ISA instructions
slt $t3, $t0, $0
beq $t3, $0, case1
# CASE 2
# pseudoinstruction
# bgt $r0, $t0, case1
# corrispondent ISA instructions
slt $t3 $0, $t0
beq $t3, $0, case2
# CASE 3
beq $t0, $0, case3
case1:
add $s0, $t0, $t1
add $s0, $s0, $t2
j end
case2:
mul $s0, $t0, $t1
mul $s0, $s0, $t2
j end
case3:
and $s0, $t1, $t2
j end
end:
la $t0, mem
sw $s0, 0($t0)
li $v0, 10
syscall