MIPS Assembly program to calculate the trace of a matrix after taking an integer input -


the following mips assembly code refuses work reason. please rescue me, i've been stuck 3 weeks!!! i'm supposed read in int n, square it, read in the n(squared) values matrix calculate trace of matrix. read onto , off stack, somewhere along lines, must have simple logic error cant identify. in advance:

.data                           #string variable declarations get_int: .asciiz   "please enter int value n: "  #prompts user enter number newline: .asciiz   "\n"  .text   .globl main   main:     addi $sp, $sp, -12                      #create stack (stack frame..) sw   $ra, 0($sp)                        #storage stack elements sw   $s0, 4($sp)       sw   $s1, 8($sp)       sw   $s2, 12($sp)                 li $v0, 5                       #read input  syscall move $s0, $v0                       #$s0 = $v0   mult $s0 $s0                            #square entered int mflo $t2 li $t0, $t2       #t0 receives squared value $t2   #adding stuff stack  li $t1, 0                       #t1 our counter (i)   stackloop: beq $t1, $t0, endstackloop                  #exit loop when t1== $t0   li $v0, 5                       #read input  syscall move $t5, $v0                       #$t5 = $v0   addi $sp, $sp, -4 sw $t5, 0($sp)  addi $t1, $t1, 1                    #add 1 t1 j stackloop                         #jump top of loop  stackpop:  lw $t3, 0($sp)      #t3 = 1st value stack  add $s1, $s1, $t3   #adding 1st value sum addi $sp, $sp, 4    #moving next stack element sub $t1, $t1, 1     #decrementing counter 1 add $t4, $t4, $0    #setting comparison value 0  matrixcondition: beq $t1, $0, output lw $t3, 0($sp) sub $t1, $t1, 1         #decrementing counter 1 beq $s0, $t4, matrixtrace   #jump matrixtrace when equal  add $t4, $t4, 1         #add 1 t4 j matrixcondition  matrixtrace: add $s1, $s1, $t3   #adding next value sum add $t4, $0, $0     #setting comparison value 0 j matrixcondition  output: li $v0, 4 syscall j progterminate  progterminate:  lw $ra, 0($sp)                      #restoring stack pointer  addi $sp, $sp, 8  jr $ra                          #return 

these errors found:

  1. this

    li $t0, $t2       #t0 receives squared value $t2 

    becomes

    move $t0, $t2       #t0 receives squared value $t2 
  2. endstackloop not exists.

  3. this

    add $t4, $t4, $0    #setting comparison value 0 

    becomes

    li $t4, 0    #setting comparison value 0 

if provide more information on not working, can better.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -