-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path104502565_SPIM_2.s
69 lines (59 loc) · 1.22 KB
/
104502565_SPIM_2.s
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
#This is print size of n image
#n = $s0
.text
.globl main
getstep:
#卡比獸的爬法術關係式子為: P(n) = P(n-1) + P(n-2), int getstep(int a0);
li $t1, 1
li $t2, 1
li $t3, 1
#for(int t4 = 1;t4<s0;t4++);
li $t4, 1
beq $t4, $t4, flchk1
forloop1:
add $t3, $t1, $t2
move $t1, $t2
move $t2, $t3
addi $t4, 1
flchk1:
blt $t4, $a0, forloop1
move $v0, $t3 #return t3
jr $ra
main:
read:
li $v0, 4
la $a0, prompt
syscall
li $v0, 5
syscall
move $s0, $v0
#if s0(n) == 0, end this program
li $t0, 0
beq $s0, $t0, endproc
move $a0, $s0
li $t0, 4
sub $sp, $sp, $t0
sw $ra, 0($sp)
jal getstep
lw $ra, 0($sp)
addi $sp, 4
move $s1, $v0
li $v0, 4
la $a0, result
syscall
li $v0, 1
move $a0, $s1
syscall
li $v0, 4
la $a0, nl
syscall
j read
endproc:
li $v0, 10 #exit program
syscall
.data
star: .byte '*'
space: .byte ' '
result: .asciiz "Result:"
nl: .asciiz "\n"
prompt: .asciiz ">"