MIPS字符串到整数转换

时间:2014-10-24 18:03:09

标签: string mips

基本上,我会从控制台读取一个字符串,这没问题。此字符串中的第一个和第三个字符将是0-9数字,我希望这些数字作为内存存储在内存中以便以后重用。我得到“在PC = 0x0040004c时出现异常”,当点击中止时,我得到“商店中未对齐的地址:0x100100c9”。

有什么问题?请帮助!

编辑:当我一步一步地运行时,第24行发生错误。

.data

exp:    .space 201     #allocate 200 bytes for logic expression to be read from stdin. +1 is for null char.
dimension:  .space 8   #allocate 8 bytes for dimensions of environment

.text


main: 

li  $v0, 8             # load appropriate system call code into register $v0;
                       # code for reading string is 8
la  $a0, exp           # load address of string to be read into $a0
li  $a1, 201           # load length of string to be read into $a1
syscall                # call operating system to perform read operation


la $t0, exp
la $t1, dimension

add $t2,$zero,$zero

lb $t2, 0($t0)
addi $t2, $t2, -48
sw $t2, 0($t1)




li  $v0, 10
syscall

1 个答案:

答案 0 :(得分:1)

存储单词时,您必须在字边界处对齐数据。

为此,您必须使用带有参数.align的{​​{1}}指令。

在您的示例中,维度未对齐,因为exp是201字节长度(不是4的倍数)。所以你必须使用:

2
相关问题