在 MIPS 中仅输出 10 个个位数列表中的负整数

发布于 2024-08-12 23:25:35 字数 1546 浏览 3 评论 0原文

我正在尝试编写一个 MIPS 程序来检查十个个位数的集合 可以从终端输入(正、零或负)。检查后 数字,只需要输出负数(带有适当的符号)及其计数 到航站楼。

下面是我的 MIPS 程序

        .data
prompt: .asciiz "Input Score: "
        .align 2
HR_Neg:        .asciiz "\n negative Scores: "
        .align 2
HR_Pos:        .asciiz "\n positive Scores: "
        .align 2
HR_Negsc:        .asciiz "\n Number of Negative Scores: "
        .align 2
HR_Posc: .asciiz "\n Number of positive Scores: "
        .align 2
HR_coma: .asciiz ", "
        .align 2
HR_brk:         .asciiz "\n\n"
        .align 2
NEg:        .space 10
        .align 2
Pos:        .space 10
        .align 2

        .globl main
        .text
main:
        li $t0, 0
        la $t1, Neg
        li $t2, 0
        la $t3, pos
        li $t4, 0
        li $t5, 0
        li $t6, 0

loop:
        li $v0, 4
        la $a0, prompt
        syscall

        li $v0, 5
        syscall

        bltu $v0, 50, else
        sw $v0, 0($t1)
        addi $t1, $t1, 4
        addi $t0, $t0, 1
        b l_end

else:
        sw $v0, 0($t3)
        addi $t3, $t3, 4
        addi $t2, $t2, 1

l_end:
        addi $t4, $t4, 1
        bltu $t4, 15, loop

#output counts
        li $v0, 4
        la $a0, HR_negc
        syscall

        la $v0, 1
        add $a0, $t0, 0
        syscall

        li $v0, 4
        la $a0, HR_posc
        syscall

        la $v0, 1
        add $a0, $t2, 0
        syscall

#output neg scores
        li $v0, 4
        la $a0, HR_neg
        syscall

        la $t1, Neg
        lw $a0, 0($t1)
        li $v0, 1

i m trying to write a MIPS program that will examine set of ten single digit numbers
(positive, zero,or negative) that can be inputted from the terminal. After examining the
numbers, only the negative numbers (with appropriate sign) along with their count needs to be outputted
to the terminal.

BELOW IS MY MIPS PROGRAM

        .data
prompt: .asciiz "Input Score: "
        .align 2
HR_Neg:        .asciiz "\n negative Scores: "
        .align 2
HR_Pos:        .asciiz "\n positive Scores: "
        .align 2
HR_Negsc:        .asciiz "\n Number of Negative Scores: "
        .align 2
HR_Posc: .asciiz "\n Number of positive Scores: "
        .align 2
HR_coma: .asciiz ", "
        .align 2
HR_brk:         .asciiz "\n\n"
        .align 2
NEg:        .space 10
        .align 2
Pos:        .space 10
        .align 2

        .globl main
        .text
main:
        li $t0, 0
        la $t1, Neg
        li $t2, 0
        la $t3, pos
        li $t4, 0
        li $t5, 0
        li $t6, 0

loop:
        li $v0, 4
        la $a0, prompt
        syscall

        li $v0, 5
        syscall

        bltu $v0, 50, else
        sw $v0, 0($t1)
        addi $t1, $t1, 4
        addi $t0, $t0, 1
        b l_end

else:
        sw $v0, 0($t3)
        addi $t3, $t3, 4
        addi $t2, $t2, 1

l_end:
        addi $t4, $t4, 1
        bltu $t4, 15, loop

#output counts
        li $v0, 4
        la $a0, HR_negc
        syscall

        la $v0, 1
        add $a0, $t0, 0
        syscall

        li $v0, 4
        la $a0, HR_posc
        syscall

        la $v0, 1
        add $a0, $t2, 0
        syscall

#output neg scores
        li $v0, 4
        la $a0, HR_neg
        syscall

        la $t1, Neg
        lw $a0, 0($t1)
        li $v0, 1

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

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

发布评论

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

评论(1

深爱成瘾 2024-08-19 23:25:35

请在您的代码中添加一些注释,以便我们这些感兴趣的人可以尝试了解它正在尝试做什么。

另外,上面的代码有一个拼写错误,您有一个标签 HR_Negsc 和对 HR_negc 的引用,这让我认为当您说“它没有运行”时,您实际上意味着它无法运行,因为它没有链接!

第 1 步 - 放入一些注释,特别是围绕系统调用

第 2 步 - 让它实际执行

第 3 步 - 现在您可以开始调试

您可以查看以下几个区域:

.space 为您提供了多少空间,够了吗?

您用来评估 +ve 和 -ve 的 bltu 指令是否正确?

你的程序是如何结束的——看起来缺少一些东西?

后来的评论:

嘿,来自 你之前的问题之一 我怀疑你当时编写的一些代码已经保留到这个项目中。我指的是数字 15 和 50。

您知道,当我们必须猜测您知道多少和不知道多少时,很难提供有用的帮助。问题越详细,答案就越有针对性。回答另一个问题的一些建议显然仍然适用。

Please put some comments in your code so those of us who are interested can try to understand what it is trying to do.

Also, the code above has a typo in that you have a label HR_Negsc and a reference to HR_negc, which makes me think that when you say "it didn't run" you actually mean it couldn't run because it didn't link!

Step 1 - Put some comments in, particularly around the syscalls

Step 2 - Get it to actually execute

Step 3 - Now you can start to debug

There are a couple of areas that you could look at:

How much room is .space giving you, is it enough?

Is the bltu instruction that you are using to evaluate +ve and -ve correct?

How does your program end - looks like some stuff missing?

LATER COMMENT:

Hey, from the problem description of one of your previous questions I suspect that some of the code you wrote then has survived into this project. I am referring to the numbers 15 and 50.

You know, it's very hard to provide useful help when we have to guess how much you know and don't know. The more detailed the question, the more directed the answer can be. And some of the advice in answer to that other question obviously still applies.

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