-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathloops.s
69 lines (63 loc) · 1.5 KB
/
loops.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
# for (int i = smth1 ; i < smth2 ; ++i)
specificforexample:
addi $sp, $sp, -8 # make space in stack
sw $t0, 0($sp)
sw $t1, 4($sp)
li $t0, 1 # change 1 to your initilized value (smth1)
li $t1, 2 # change 2 to your initilized value (smth2)
specificforexampleloop:
# Condition
beq $t0, $t1, specificforexampleexit
######################
# Main loop body
######################
# Iteration end
addi $t0, $t0, 1
j specificforexampleloop
specificforexampleexit:
lw $t0, 0($sp)
lw $t1, 4($sp)
addi $sp, $sp, 8
# return
# jr $ra
# j exit
# While loop
whileloopexample:
# Condition
# beq $s0, $zero, whileloopexampleexit
######################
# Main loop body
######################
j whileloopexample
whileloopexampleexit:
# do stuff and return
# jr $ra
# j exit
# For loop
forexample:
# Initialization
# do stuff
forexampleloop:
# Condition
# beq $s0, $zero, forexampleexit
######################
# Main loop body
######################
# do stuff before next iteration
j forexampleloop
forexampleexit:
# do stuff and return
# jr $ra
# j exit
# Do while loop
dowhileexampleloop:
######################
# Main loop body
######################
# Condition
# beq $s0, $zero, dowhileexampleloopexit
j dowhileexampleloop
dowhileexampleloopexit:
# do stuff and return
# jr $ra
# j exit