Pregunta

When trying to store a user's inputed string, for part of a project, I receive the following error in spim when I simply load the file:

Immediate value is too large for field: [0x0040009c]

Below is my code:

.globl main
.data
prompt: .asciiz "0: exit, 1: enter string, 2: convert, 3: mean, 4: median, 5: display                 string, 6: display array: " #94 char long
enter:  .asciiz "Enter string: "
.text
main:
display: addi $v0, $v0, 4 #print prompt
        lui $a0, 0x1000  #grabbing prompt
        syscall

        addi $v0, $0, 5 #get integer
        syscall

        beq $v0, 0, rtn #if user type's 0, exit program
        nor $0, $0, $0 #nop

        beq $v0, 1, enterString #if user type's 1, enterString
        nor $0, $0, $0 #nop

enterString:
    addi $v0, $0, 4 #printing string
    lui $a0, 0x1000 #grabbing prompt
    addi $a0, $a0, 95 #grabbing enter
    syscall

    addi $v0, $0, 8 #grabbing input
    sw $a0, 0x10000100 #storing inpuit - this specific address is a requirement
    syscall

rtn: jr $ra

Now, when I run this I get the above mentioned error. However, I'm not quite sure why. It may be due to a string being 32 bit? Any explanations as to why would be appreciated. Thanks again!

¿Fue útil?

Solución

I see a couple of problems in your code:

This is way longer than 94 chars:

prompt: .asciiz "0: exit, 1: enter string, 2: convert, 3: mean, 4: median, 5: display                 string, 6: display array: " #94 char long

Even if you remove those extra spaces, I still count 95 chars.


Don't assume that registers start out with a certain value:

addi $v0, $v0, 4 #print prompt

This should be addi $v0, $zero, 4.


This should probably be 0x1001, since the data section starts at 0x10010000:

lui $a0, 0x1000

Same goes for all other places where you're trying to access the data section.


I don't know if SPIM translates this into a valid instruction:

sw $a0, 0x10000100

If not, you should load the address into a register first (e.g. $a1), and access memory through that register (e.g. sw $a0, ($a1)).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top