尝试将.ASCIIZ字符串复制到MIPS中的分配空间

发布于 2025-01-29 02:13:53 字数 393 浏览 1 评论 0原文

我试图制作一个简单的程序,将字符串soplas复制到.Space指令称为buffer。我会遇到错误,但我不确定我在哪里出错,beq语句将将字节与0 ASCII字符进行比较,因为那是如何终止字符串,对吗?使用JAL调用复制

copy:   
     lb   $t1, soplas($t0) 
     nop
     sb   $t1, buffer($t0)
     nop
     addi $t0, $t0,1
     beq  $t1, 0x00, done
     j copy
     nop
     nop
    
    
done: 
    jr $ra
    nop
    nop 


im trying to make a simple program that copies a string soplas to a .space directive called buffer. im getting errors but im not sure where im going wrong, the beq statement would be comparing the byte to the 0 ascii character since thats how strings are null terminated, right? copy is called using jal, hence the jr $ra in the done subroutine

copy:   
     lb   $t1, soplas($t0) 
     nop
     sb   $t1, buffer($t0)
     nop
     addi $t0, $t0,1
     beq  $t1, 0x00, done
     j copy
     nop
     nop
    
    
done: 
    jr $ra
    nop
    nop 


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟火散人牵绊 2025-02-05 02:13:53

假设您的C代码看起来像这样:

void copy() {
    int i = 0; // start i at 0 to work with soplas[0]/buffer[0]
    while (true) {
        char ch = soplas[i];
        buffer[i] = ch;
        i++;
        if (ch == '\0') break;
    }
}

您可以看到汇编版本中缺少的C代码的哪一行?


另外,如果您使用带有分支延迟插槽的MIPS,即使BEQbne需要nop s,而不仅仅是j j 代码>和JR

Let's say your C code would look like this:

void copy() {
    int i = 0; // start i at 0 to work with soplas[0]/buffer[0]
    while (true) {
        char ch = soplas[i];
        buffer[i] = ch;
        i++;
        if (ch == '\0') break;
    }
}

Can you see which line of the C code you're missing in the assembly version?


Also, if you're using MIPS with branch delay slots, even beq and bne need nops, not just j and jr.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文