assembly - MIPS: Print contents of array using stack pointer -



assembly - MIPS: Print contents of array using stack pointer -

i'm learning mips, , having problem understanding how utilize stack pointer printing contents of array while next c calling conventions, i.e. passing parameters using stack, local variables on stack, saving registers on stack. homework assignment appreciate clarifications , hints. thanks.

question 1: understand it, we're set parameters using stack making room in main subroutine:

subi $sp, $sp, 12 sw $t2, 8($sp) # base of operations address of array sw $t1, 4($sp) # end index sw $t0, 0($sp) # start index

then phone call subroutine @ end of main using jal, , load parameters in @ origin of subroutine. @ end of subroutine should pop stack , homecoming using jr $ra. issue arises because subroutine i've implemented loop 1 time completed, branches subroutine i'm not clear should popping stack , doing return. clarifications great.

this how i've implemented far, i'm unsure if should doing pop within printarray or completeprint.

printarray: beq $t1, $a1, completeprint lw $a2, 8($sp) # loading parameters lw $a1, 4($sp) # a2 = base of operations address of array, a1 = hi, a0 = lo lw $a0, 0($sp) lw $a0, ($a2) # *** li $v0, 1 syscall la $a0, space li $v0, 4 syscall sub $sp, $sp, 12 # stack 3 registers sw $t1, 8($sp) sw $t0, 4($sp) sw $s0, 0($sp) addi $t1, $a0, 1 addi $a2, $a2, 4 # += 4 j printarray completeprint: lw $a0, ($s0) #print final number in array li $v0, 1 syscall la $a0, carriagereturn li $v0, 4 syscall lw $s0, 0($sp) #popping stack lw $t0, 4($sp) lw $t1, 8($sp) add together $sp, $sp, 24 jr $ra #returning

question 2 of right now, i'm getting error when seek print each element of array (the line ***), , believe has utilize of registers a0-a3. understand these registers used parameters, i'm confused how should using them.

assembly mips

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -