简体   繁体   English

MIPS程序集:立即值太大,导致字段错误

[英]MIPS Assembly: Immediate value is too large for field error

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: 尝试存储用户输入的字符串时,对于项目的一部分,我在简单地加载文件时会在spim中收到以下错误:

Immediate value is too large for field: [0x0040009c] 立即数字段太大:[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? 这可能是由于字符串是32位吗? Any explanations as to why would be appreciated. 关于为什么的任何解释将不胜感激。 Thanks again! 再次感谢!

I see a couple of problems in your code: 我在您的代码中看到了几个问题:

This is way longer than 94 chars: 这比94个字符长:

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. 即使您删除了这些多余的空格,我仍然算出95个字符。


Don't assume that registers start out with a certain value: 不要假设寄存器以某个特定的值开始:

addi $v0, $v0, 4 #print prompt

This should be addi $v0, $zero, 4 . 这应该是addi $v0, $zero, 4


This should probably be 0x1001 , since the data section starts at 0x10010000: 这可能应该是0x1001 ,因为数据段从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: 我不知道SPIM是否将其转换为有效的指令:

sw $a0, 0x10000100

If not, you should load the address into a register first (eg $a1 ), and access memory through that register (eg sw $a0, ($a1) ). 如果不是,则应先将地址加载到寄存器中(例如$a1 ),然后通过该寄存器访问内存(例如sw $a0, ($a1) )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM