nested

Shared by: dandanhuanghuang
Categories
Tags
-
Stats
views:
4
posted:
4/1/2012
language:
pages:
2
Document Sample
scope of work template
							      .data
w1:   .word   5
w2:   .word   90
output:       .asciiz            "Result = %d\n"

     .globl   main
     .globl   printf
     .globl   flush
     .globl   db_puts
     .text

/**************************************************************/
# Function proc1
# This function accepts a parameter, b, and returns proc2(8) + b
# Parameter b passed in $a0.
# Return result in $v0.
# Local variable c is stored in $s0,
# so need to push
# $s0 onto the stack because
# it might be in use
# by calling procedure.
# Also: Since we call a 2nd procedure,
# need to push $ra
# onto stack.
/**************************************************************/
proc1:
      addiu $sp, $sp, -12
      sw      $a0, 8($sp)
      sw      $ra, 4($sp)
      sw      $s0, 0($sp)

     li       $s0, 0

     # Set up for call to proc2
     li     $a0, 8
     jal    proc2
     lw     $a0, 8($sp) # Load proc1 b back into $a0
     add    $s0, $v0, $a0
     move   $v0, $s0

     lw     $a0, 8($sp)
     lw     $ra, 4($sp)
     lw     $s0, 0($sp)
     # Strictly speaking, we didn't need to restore $a0 value
     # because arg registers not preserved
     # across procedure calls.
     addiu $sp, $sp, 12
     jr     $ra
/**************************************************************/
# Function proc2
# This function accepts a parameter, a, and returns a/4
# Parameter passed in $a0.
# Return result in $v0.
/**************************************************************/
proc2:
      srl    $v0, $a0, 2
      jr     $ra

/**************************************************************/
# main of program
/**************************************************************/
main:
      addiu $sp, $sp, -32

     li      $a0, 2
     jal     proc1

     la      $a0, output
     move    $a1, $v0      # put result of proc1 in $a1
     jal     printf
     jal     flush

forever:
      j forever
      # End main

						
Related docs
Other docs by dandanhuanghuang
jowers
Views: 433  |  Downloads: 0
Tree Structured Index
Views: 1  |  Downloads: 0
32_sales_per_qtr_bv
Views: 1621  |  Downloads: 0
LATEST STAFF DETAILS
Views: 597  |  Downloads: 0
4grandparents
Views: 292  |  Downloads: 0
CommunicationsElectronicCommunicationsAnalyst
Views: 3  |  Downloads: 0
Lire un message SWIFT
Views: 332  |  Downloads: 0
David Cracknell EPC CIC
Views: 326  |  Downloads: 1