assemblymipssystem-callsmips64

How to load MIPS code correctly in winMIPS64


I tried to load the following code into winMIOS64 but it the process failed because it gave me an error in line 2, could help me to identify the problem and if there other instructions should be changed??!!

 .data 
        m1:.asciiz "enter the total number of digits"
        m2:.asciiz "enter total number of digits"
        m3:.asciiz "entered number:"
        m4:.asciiz "sum of product:"
        m5:.asciiz "not an armstrong number"
.text  
main:
      addi.d $sp,$sp,-20
       sd $ra,0($sp) 
       sd $a0,4($sp) 
       sd $a1,8($sp) 
       sd $a2,12($sp)
       sd $a3,16($sp) 
       jal start

start:  ld $a0,0($sp) #restore a0 from stack 
        ld $a1,4($sp)
        ld $a2,8($sp)
        ld $a3,12($sp)  
        ld $ra,16($sp)  
        addi.d $sp,$sp,20 #restore stack pointer 
        jr $ra #return to calling routing 
        halt

The following are the errors appeared in a dialog while the code has not downloaded:

1. first dialog said: pass 1 - error on line 2

2. second dialog said: errors detected on pass 1


Solution

  • The error is presumably misaligned address.

    You are attempting to store a double word in line 2:

    sd $ra, 0($sp)
    

    But you are not passing an address that is double-word aligned (a multiple of 8).

    Because you are storing double words, they should each be 8 bytes apart, and you should be allocating 40 bytes in the stack for 5 registers instead of just 20:

    addi.d $sp, $sp, -40