- #1
electra123
- 4
- 0
I'm trying to write a MIPS assembly program that implements the calculation of n! Well i wouldn't be here if i were successful.When i try to run the following code on PCSpim this appears on the screen:
"Exception 6 [Bad instruction address] occurred and ignored"
Can anyone help me find my errors?i think my head is going to explode!
Thanks in advance...
Here is my code:
"Exception 6 [Bad instruction address] occurred and ignored"
Can anyone help me find my errors?i think my head is going to explode!
Thanks in advance...
Here is my code:
.data 0x10008000
.word 10
.word 1
.word 0
.ascii "The factorial of 10 is %d \n"
.text
.globl main
main:
addi $sp,$sp,-8
sw $ra,4($sp)
sw $fp,8($sp)
addiu $fp,$sp,4
lw $a0,4($gp)
jal fact
move $a1,$v0
jal printf
lw $ra,4($sp)
lw $fp,8($sp)
addi $sp,$sp,8
jr $ra
fact:
addi $sp,$sp,-8
sw $ra,4($sp)
sw $fp,8($sp)
addiu $fp,$sp,4
sw $a0,0($fp)
lw $v0,0($fp)
move $t0,$zero
slti $t0,$v0,1
beq $t0,$zero,L2
addi $v0,$zero,1
jr L1
L1:
lw $ra,4($sp)
lw $fp,8($sp)
addiu $sp,$sp,8
jr $ra
L2:
lw $v1,0($fp)
subu $v0,$v1,1
move $a0,$v0
jal fact
lw $v1,0($fp)
mul $v0,$v0,$v1
printf:
li $v0,4
la $a0,12($gp)
syscall
li $v0,1
move $a0,$v1
syscall