我正在制作一个mips汇编语言类型的计算器。它得到一个等式作为数据,我必须解析方程并遵循PEMDAS(操作顺序)。我似乎无法弄清楚如何解析和存储字符串,以便我这样做。我知道你必须检查等式的十六进制值才能知道要解决的数学问题,但不知道如何编码它。在我们将两个数字相乘之后,您如何将答案重新放入等式中以继续迭代它。下面的一些代码,我工作,需要完成这个。这个等式只是一个例子。括号和指数不用于此。由于这是汇编,我没有把我的确切代码放入,因为这将是大量的行,但我画了一个大纲,我需要修复或帮助,我有什么和理解。如果我能理解解析以及方程和数字的存储方式,我可以自己修复其余部分,所以我只需要解析和pemdasone,两个和三个标签。
.globl division
.globl multiplication
.globl addition
.globl subtraction
.globl end
.globl PemdasOne
.globl PemdasTwo
.globl PemdasThree
.globl parse
.data
a: .half 2
b: .half 3
c: .half 8
d: .half 35
exp: .asciiz "b:=26/a-c+b"
.text
parse:
(HELP!This is the part that needs work.) (HELP! Read and store expression)
(HELP! Create iterator to keep spot in the equation?)
pemdasone:
(HELP! Check if ascii value at iterator is * or /)
(UNDERSTAND: if so branch or jump to math equation)
(UNDERSTAND: if not branch or jump to pemdastwo)
pemdastwo:
(HELP! check if ascii value at iterator is + or -, reiterate through equation with updated values after pemdasone is done with what it does)
(UNDERSTAND: if so branch or jump to math equation)
(UNDERSTAND: if not branch or jump to pemdasthree)
pemdasthree:
(HELP! check if equation is completed. Store answer in variable b so it is updated from the input value to the answervalue.)
(UNDERSTAND that if it is done jump to end label)
multiplication:
(HELP! get number before the ascii value of * and fter the ascii value of * and store them in registers for the equation.)
(UNDERSTAND: how to do the mathmatical operator with two numbers.)
(HELP! store answer in equation so you can keep doing the equation)
(UNDERSTAND: that jump or branch back to pemdasone)
division:
(All the math parts are the same help and understands just with new operator and jump and branch locations)
addition:
(Same help and understands as divide and multiply except jump to pemdastwo)
subtraction:
(Same as addition)
end:
(UNDERSTAND that you store the answer into the variable it tells you to)
(HELP! with memory and where we stored the answer)