mips1

Friday, July 15, 2016

Saving register to the stack Mips code

.data
    newLine:  .asciiz "\n"

.text
    main:
             addi $s0, $0, 10
       jal increaseMyregister
   #prints a new line
  li $v0, 4
  la$a0, newLine
syscall

  #printing the value
         li $v0, 1            #reading the integer
        move $a0, $s0   #moving the value from $s0 to $a0
      syscall

li $v0, 10              #system call finish the program
syscall


#funtion
increaseMyregister:
         addi $sp, $sp, -4     #making space for stack and string 4 byte or allocation place
        sw $s0, 0($sp)         #save the value of $s0 in the first place into the stack pointer
   

       addi $s0, $s0, 50       #now 30 will add with 10 which is on the top

#print new value in function
li $v0, 1
move $a0, $s0
syscall

lw $s0, 0($sp)
addi $sp, $sp, 4




jr $ra

No comments:

Post a Comment