-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmips-16-powerFunc.asm
66 lines (50 loc) · 910 Bytes
/
mips-16-powerFunc.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
58
59
60
.data
string1: .asciiz "Enter base number:"
string2: .asciiz "Enter exp number:"
string3: .asciiz "Result:"
endLine: .asciiz "\n"
.text
#########################################################
powerFunction:
# a0 -> baseNumber a1 -> expNumber v0 -> result
# result = 1;
# counter = 0;
# if (exp == 0)
# return result;
# for ( counter = 0; counter < expNumber ; ++counter )
# result = result*baseNumber
# return result;
li $v0,1
bne $a1,$zero,endif
jr $ra
endif:
li $t0,0
loop:
bge $t0,$a1,endLoop
mul $v0,$v0,$a0
addi $t0,$t0,1
j loop
endLoop:
jr $ra
#########################################################
main:
li $v0, 4
la $a0, string1
syscall
li $v0,5
syscall
move $t0,$v0
li $v0, 4
la $a0, string2
syscall
li $v0,5
syscall
move $t1,$v0
move $a0,$t0
move $a1,$t1
jal powerFunction
move $a0,$v0
li $v0,1
syscall
li $v0, 10
syscall