将C代码转换为mips时出错

将C代码转换为mips时出错,mips,Mips,这是到目前为止我已经转换过的C代码。它给了我一些错误,我已经包含在下面的代码中。我不明白c到mips转换中哪个部分是错误的 char ch[10]; int i; for (i = 0; i != 10; i++) ch[i] = ch[i] – 32 .data .text li $v0 4 syscall #$s1 = i, $s0 base address of ch addi $s1, $0, 0 #i =0 addi $t0, $0,

这是到目前为止我已经转换过的C代码。它给了我一些错误,我已经包含在下面的代码中。我不明白c到mips转换中哪个部分是错误的

 char ch[10];
 int i;
 for (i = 0; i != 10; i++)
 ch[i] = ch[i] – 32


.data

.text
li  $v0 4
syscall

#$s1 = i, $s0  base address of ch

addi $s1, $0, 0                #i =0
addi $t0, $0, 10               #t0 = 10
loop:   beq  $t0, $s1, end       
add  $t1, $s1, $s0
lw   $t2, 0($t1)
addi $t2, $t2, -32
sw   $t2, 0($t1)
addi $s1, $s1, 1
j   loop
end:
我的输出:

Runtime exception at 0x00400018: address out of range 0x00000000

在C代码中,您正在转换
char
类型数组,在MIPS中,您应该使用
lb
而不是
lw

要打印出来,您需要一个
main:
标签,还应该声明一个数组,如
.byte
.space

您应该使用
syscall 11
打印字符,或者使用
syscall 4
打印字符 绳子

我已经在你的代码中添加了上面提到的一些,希望能有所帮助

    .data
     #ch: .byte 'a','b','c','d','e'
     ch: .space 10
    .text
     main:


            li $v0, 8      #read character 
            li $a1, 10     #load the space
            la $a0, ch     
            syscall

            li $v0,11      #print character
            syscall

            li $v0,10      # exit program
            syscall

            addi $s1, $0, 0     #i = 0
            addi $t0, $0, 10    # $t0 = 10
    loop:   beq  $t0, $s1, end  
            add  $t1, $s1, $s0  
            lb   $t2, ch($t1)   
            addi $t2, $t2, -32
            sb   $t2, ch($t1)
            addi $s1, $s1, 1
            j   loop
    end:

我已经有一段时间没有MIPS了,但它看起来像一个空的寄存器。更重要的是,在MIPS中编写代码时,应该逐行注释,否则调试将是一场噩梦。您没有初始化
$s0
。另外,还不清楚
syscall
应该做什么,因为系统调用4需要
$a0
中的字符串地址。