问题描述
我是MIPS汇编语言的新手,在过去的几天中遇到了一些问题,尽管我自己解决了大多数问题,但是特别是我感到很沮丧。
我正在编写一个简单的计算器,并且在脚本中有2个 b ranch eq uals语句,据我所知,beq语句的编写方式如下:
beq $ t0,$ t1,additionFunction
大致翻译为:
如果$ t0等于$ t1,则跳至脚本中的additionFunction。
这是我的代码:
.data #Data section
Prompt1: .asciiz "For addition enter 1
\nFor subtraction enter 2
\nFor and enter 3
\nFor or enter 4
\nFor xor enter 5
\nEnter your choice: "
Prompt2: .asciiz "\nEnter first number: "
Prompt3: .asciiz "\nEnter second number: "
Result: .asciiz "The result is: "
.globl main
.text #Code section
main:
li $t1,1
li $t2,2
#STARTUP MESSAGE
li $v0,4 #system call code for Print String
la $a0,Prompt1 #load address of Prompt1 into $a0
syscall #print the Prompt1 message
li $v0,5 #system call code for Read Integer
syscall #reads the value of 1st integer into $v0
move $t0,$v0 #move the 1st integer to $t0
beq $t0,$t1,additionFunction #if branch is equal to $t1
beq $t0,$t2,subtractionFunction
additionFunction:
li $v0,4 #call to print string
la $a0,Prompt2 #load prompt2 into variable $a0
syscall #call system to print
li $v0,5 #call to read integer
syscall #read integer into $v0
move $s1,$v0
li $v0,4 #syscall to print string
la $a0,Prompt3 #load prompt3 into variable $a0
syscall #call system to print
li $v0,5 #call to read integer into $v0
syscall #read integer into $v0
move $s2,$v0 #moves value of $v0 to $t2
li $v0,Result #load Result into variable $a0
syscall #call system to print
add $s3,$s1,$s2 #t3 = t2 +t1
li $v0,1 #call to print integer
move $a0,$s3
syscall
Exit
subtractionFunction: #if branch is equal to $t2
li $v0,Result #load Result into variable $a0
syscall #call system to print
sub $s3,$s3
syscall
Exit
在第一个提示中输入“ 1”后,程序将正确运行并添加用户键入的下两个整数。但是,在输入“ 2”时,会出现以下错误消息:
指令在0x00400048 [0x00400048]处引用未定义符号0x110a0000 beq $ 8,$ 10,0 [subtractionFunction-0x00400048]; 23:beq $ t0,$ t2,subtractionFunction
根据我的理解,这意味着我有一个不正确的beq语句,而我对为什么感到困惑,而为了使该功能正常工作,我需要更改什么?
我对MIPS汇编语言非常陌生,因此,如果这是一个简单的修复程序,我会为一个看似毫无意义的问题预先道歉,但我希望获得任何类型的反馈,以帮助我更好地理解该语言。
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)