尝试让 if 函数在 mips 中工作
您好,刚开始使用 mars 程序和 mips,在读取用户输入及其地址后,我该如何使用它来执行特定的代码片段? 例如。
//get user input
input = 1
if(input == 1)
//run this code
这就是我想做的,我可以解释它的最好方式(显然格式错误)。 这就是我到目前为止所拥有的
```
typeinfo: .asciiz " 1 - Cls \n 2 - Row \n 3 - Column \n 4 - Triangle \n 5 - Exit\n\n"
typetext: .asciiz "Enter a number here for type: "
#prints the options
addi $v0, $zero, 4
la $a0, typeinfo
syscall
#prints out the prompt
addi $v0, $zero, 4
la $a0, typetext
syscall
#i want to be able to run this if user inputs "1"
###########################################################
lui $s0, 0x1004
addi $t8, $zero, 0x00ff
addi $t0, $s0, 0
lui $s1, 0x100C
drawPixel:
sw $t8, 0($t0)
addi $t0, $t0, 4
bne $t0, $s1, drawPixel
##########################################################
#gets the user input
li $v0, 5
syscall
#move from $v0 to $t0
move $t1, $v0
#ends program
li $v0, 10
syscall
```
Hello new to using mars program and mips in general how would i got about after reading user input and its in an adress how do i use that to execute specific pieces of code?
Eg.
//get user input
input = 1
if(input == 1)
//run this code
this is what i want to do, best way i could explain it (obviously in wrong format).
This is what i have up to now
```
typeinfo: .asciiz " 1 - Cls \n 2 - Row \n 3 - Column \n 4 - Triangle \n 5 - Exit\n\n"
typetext: .asciiz "Enter a number here for type: "
#prints the options
addi $v0, $zero, 4
la $a0, typeinfo
syscall
#prints out the prompt
addi $v0, $zero, 4
la $a0, typetext
syscall
#i want to be able to run this if user inputs "1"
###########################################################
lui $s0, 0x1004
addi $t8, $zero, 0x00ff
addi $t0, $s0, 0
lui $s1, 0x100C
drawPixel:
sw $t8, 0($t0)
addi $t0, $t0, 4
bne $t0, $s1, drawPixel
##########################################################
#gets the user input
li $v0, 5
syscall
#move from $v0 to $t0
move $t1, $v0
#ends program
li $v0, 10
syscall
```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是比较寄存器的方法(我使用的寄存器名称是任意的,您可以比较任意两个寄存器)
但是,有时,放置代码的顺序并不总是简单的。如果您想写:
实际上反转分支条件更容易,如下所示:
Here are the ways you can compare registers (the register names I use are arbitrary, you can compare any two registers)
Sometimes, the order in which you put your code isn't always straightforward, however. In the event you want to write:
It's actually easier to reverse the branch condition, like so: