mips 程序无法识别 mips/mflo/sw

发布于 2024-12-12 03:05:13 字数 1799 浏览 0 评论 0原文

我想编写一个将十进制转换为二进制的程序。为此我将使用一个数组。请查看下面注释的行,并告诉我为什么它可能不起作用,因为 spim 模拟器说尝试执行非指令

       .text
       .globl __start
    __start:

        la $a0,prompt
        li $v0,4
        syscall

        li $v0,5
        syscall

        move $t1,$v0

        li $t0,0
        la $t2,bin
        #add $t2,$t2,124
            lop:    
            div $t1,$t1,2
        mflo $v0
        sw $v0,($t2) #right here
        add $t2,$t2,4
        add $t0,$t0,1
        ble $t0,32,lop
        j dnn

            ads:    
            la $a0,spc
    li $v0,4
    syscall
    j back

            dnn: 
        la $t0,bin
        li $t3,1
        la $a0,pr2
        li $v0,4
        syscall
        add $t0,$t0,124
            lp2:
        lw $t1,($t0)
        sub $t0,$t0,4
        add $t3,$t3,1
        move $a0,$t1
        li $v0,5
        syscall
        div $t4,$t3,4
        mflo $t4
        ble $t4,0,ads
            back:   
            ble $t3,33,lp2

        li $v0,10
        syscall

        .data
            prompt: .asciiz "Enter decimal: "
            spc:    .asciiz " "
            pr2:    .asciiz "\nbinary value:\n"
            bin:    .space 128

编辑:我做了一些更改,就像现在所有的“add”都是“addi”,而“.align 2”紧随其后。数据 同样在 SPIM 模拟器(PCSpim)中我注意到一些有趣的事情:

   [0x00400020]        0x3c011001  lui $1, 4097 [bin]              ; 15: la $t2,bin
   [0x00400024]        0x342a0022  ori $10, $1, 34 [bin]
   [0x00400028]        0x34010002  ori $1, $0, 2                   ; 17: div $t1,$t1,2
   [0x0040002c]        0x0121001a  div $9, $1
   [0x00400030]        0x00004812  mflo $9
   [0x00400034]        0x00001012  mflo $2                         ; 18: mflo $v0
   [0x00400038]        0xad420000  sw $2, 0($10)                   ; 19: sw $v0,($t2)

为什么 mflo 做了两次?

I wanted to write a program that converts a decimal in to binary. For this I would use an array. Please look at the line commented below and tell me why it might not work because the spim simulator says attempting to execute non-instruction

       .text
       .globl __start
    __start:

        la $a0,prompt
        li $v0,4
        syscall

        li $v0,5
        syscall

        move $t1,$v0

        li $t0,0
        la $t2,bin
        #add $t2,$t2,124
            lop:    
            div $t1,$t1,2
        mflo $v0
        sw $v0,($t2) #right here
        add $t2,$t2,4
        add $t0,$t0,1
        ble $t0,32,lop
        j dnn

            ads:    
            la $a0,spc
    li $v0,4
    syscall
    j back

            dnn: 
        la $t0,bin
        li $t3,1
        la $a0,pr2
        li $v0,4
        syscall
        add $t0,$t0,124
            lp2:
        lw $t1,($t0)
        sub $t0,$t0,4
        add $t3,$t3,1
        move $a0,$t1
        li $v0,5
        syscall
        div $t4,$t3,4
        mflo $t4
        ble $t4,0,ads
            back:   
            ble $t3,33,lp2

        li $v0,10
        syscall

        .data
            prompt: .asciiz "Enter decimal: "
            spc:    .asciiz " "
            pr2:    .asciiz "\nbinary value:\n"
            bin:    .space 128

EDIT: I made some changes, like now all the 'add's are 'addi's and '.align 2' comes after .data
also in The spim simulator (PCSpim) I noticed something interesting:

   [0x00400020]        0x3c011001  lui $1, 4097 [bin]              ; 15: la $t2,bin
   [0x00400024]        0x342a0022  ori $10, $1, 34 [bin]
   [0x00400028]        0x34010002  ori $1, $0, 2                   ; 17: div $t1,$t1,2
   [0x0040002c]        0x0121001a  div $9, $1
   [0x00400030]        0x00004812  mflo $9
   [0x00400034]        0x00001012  mflo $2                         ; 18: mflo $v0
   [0x00400038]        0xad420000  sw $2, 0($10)                   ; 19: sw $v0,($t2)

why is mflo done twice?

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

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

发布评论

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

评论(1

萌︼了一个春 2024-12-19 03:05:13

mflo 执行了两次,因为 DIV 伪指令这样做并且你之后就明确地这样做了。

你可以这样做:

    div $v0,$t1,2

mflo is done twice because the DIV pseudo instruction does it and you're doing it explicitly right after.

You can just do:

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