0

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

  • 1
    _"it gave me an error in line 2"_ Then you should include the exact error message in your question. – Michael Apr 05 '16 at 20:08
  • this program did not load the code into its environment, it gave me this message by dialog –  Apr 05 '16 at 20:11
  • What message? You're going to need to copy the error message verbatim, because you can't expect people to fire up some program and try it for you. – Peter Cordes Apr 05 '16 at 20:37
  • Ya. That's a pretty lame error message. – Konrad Lindenbach Apr 06 '16 at 02:41
  • how to solve the problem... I need to test my code to see weather it is correct or not –  Apr 06 '16 at 02:47
  • The links to the images you've posted are broken. Avoid images and put the exact error messages _as text_ into your question. – Michael Apr 06 '16 at 08:33

1 Answers1

1

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
Konrad Lindenbach
  • 4,911
  • 1
  • 26
  • 28