MIPS while 循环错误

发布于 2024-12-17 08:08:50 字数 1611 浏览 0 评论 0原文

我在使用以下 mips 代码时遇到了一些问题:

    li $t0, -1
    li $t5, 0
    countNumberofVariables:
        addi $t0, $t0, 1
        beq $t0, $t8, endCount
        add $t1, $t0, $t9
        lb $t1, ($t1)
        li $t2, 10
        beq $t1, $t2, endCount
        li $t2, 13
        beq $t1, $t2, endCount
        li $t2, 97
        blt $t1, $t2, countNumberofVariables
        li $t2, 122
        bgt $t1, $t2, countNumberofVariables
        li $t2, -1
        stackScan:
            addi $t2, $t2, 2
            add $t3, $sp, $t2
            lb $t3, ($t3)
            beq $t3, $t1, countNumberOfVariables
            li $t4, 64
            bne $t4, $t3, stackScan
            addi $sp, $sp, -2
            sb $t1, ($sp)
            li $t1, 0
            sb $t1, 1($sp)
            addi $t5,$t5,1
            j countNumberofVariables

    endCount:
    move $a0, $t5
    li $v0, 1
    syscall

    j main

我想做的是计算字符串中唯一小写字母的数量(地址在 $t9 中,长度在 $t8 中)。我遇到的问题是,在 SPIM 7.3 下运行时出现此错误:

Instruction references undefined symbol at 0x00400108
[0x00400108]    0x11180000  beq $8, $24, 0 [endCount-0x00400108]; 87: beq $t0, $t8, endCount

变量是:

$t0, outer loop counter
$t5, number of unique lowercase letters in string
$t1, the character at the current location in the string
$t2, random variable in outer loop, loop counter in inner loop
$t3, the character at the current location on the stack in the inner loop
$t4, random variable

请注意,魔术常量 64 是堆栈顶部的哨兵值。

编辑:已解决。我将标签名称更改得更短,这似乎满足了 spim 的需求。不太确定根本问题是什么,但如果您遇到的问题似乎不应该存在,请更改为较短的标签

I am having some trouble with the following mips code:

    li $t0, -1
    li $t5, 0
    countNumberofVariables:
        addi $t0, $t0, 1
        beq $t0, $t8, endCount
        add $t1, $t0, $t9
        lb $t1, ($t1)
        li $t2, 10
        beq $t1, $t2, endCount
        li $t2, 13
        beq $t1, $t2, endCount
        li $t2, 97
        blt $t1, $t2, countNumberofVariables
        li $t2, 122
        bgt $t1, $t2, countNumberofVariables
        li $t2, -1
        stackScan:
            addi $t2, $t2, 2
            add $t3, $sp, $t2
            lb $t3, ($t3)
            beq $t3, $t1, countNumberOfVariables
            li $t4, 64
            bne $t4, $t3, stackScan
            addi $sp, $sp, -2
            sb $t1, ($sp)
            li $t1, 0
            sb $t1, 1($sp)
            addi $t5,$t5,1
            j countNumberofVariables

    endCount:
    move $a0, $t5
    li $v0, 1
    syscall

    j main

What I am trying to do is count the number of unique lower case letters in a string (address in $t9, length in $t8). The problem I am having, when running under SPIM 7.3 is that I get this error:

Instruction references undefined symbol at 0x00400108
[0x00400108]    0x11180000  beq $8, $24, 0 [endCount-0x00400108]; 87: beq $t0, $t8, endCount

The variables are:

$t0, outer loop counter
$t5, number of unique lowercase letters in string
$t1, the character at the current location in the string
$t2, random variable in outer loop, loop counter in inner loop
$t3, the character at the current location on the stack in the inner loop
$t4, random variable

note that the magic constant 64 is a sentinel value at the top of the stack.

EDIT: SOLVED. I changed label names to be shorter, which seemed to satisfy spim. Not quite sure what the underlying problem was, but if you are having a problem where there doesn't seem like there should be one, change to shorter labels

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文