Advertisement
Guest User

Untitled

a guest
Oct 9th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # memread.s program for MIPS
  2.  
  3.  
  4. .data
  5. inp:        .word   1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
  6. msg:        .asciiz "Reading array\n"
  7. newline:    .asciiz "\n"
  8.  
  9. .globl main # declare the global symbols of this program
  10.                 # SPIM requires a "main" symbol, (think of symbol
  11.                 #  as another name for label), which declares
  12.                 #  where our program starts
  13.  
  14. .text
  15.                 # .text starts the text segment of the program,
  16.                 # where the assembly program code is placed.
  17.  
  18.  
  19. readarr:    # method to process an array
  20.  
  21. loop:
  22.     beqz    $a2,    end     # go to end if all array elements processed
  23.     lw  $a0,    0($a1)      # load array element into reg $a0
  24.     li  $v0,    1
  25.     syscall             # print element
  26.  
  27.     la  $a0,    newline
  28.     li  $v0,    4
  29.     syscall
  30.  
  31.     addi    $a2,    $a2,    -1  # decrement counter for elements left to be processed
  32.     addi    $a1,    $a1,    4   # increment address for next element
  33.     j   loop            # end of iteration
  34. end:
  35.     jr  $ra         # return
  36.  
  37. main:                   # This is the entry point of our program
  38.  
  39.     la  $a0,    msg     # make $a0 point to where the message is
  40.     li  $v0,    4       # $v0 <- 4
  41.     syscall             # Call the OS to print the message
  42.  
  43.     la  $a1,    inp     # array to be processed
  44.     li  $a2,    16      # size of array to be processed
  45.  
  46.     jal readarr
  47.    
  48.     # This is the standard way to end a program
  49.     li  $v0,    10
  50.     syscall             # end the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement