在我上面写的这个当前例子中,我用80作为n。我的输出是n = 91,count = 42.这也称为McCarthy 91.但是我现在想在汇编语言(MIPS)中使用这个代码。有没有人有关于如何做到这一点的任何提示?我从未处理过在MIPS中构建递归类型程序的问题。下面我提供了我的工作python代码,以及带有注释的汇编代码,这些代码正在python代码下面编写。使用汇编代码肯定会有任何提示/帮助。
Python代码:
def mcc91(n):
global count
count +=1
if n > 100:
return n -10
else:
return mcc91 (mcc91(n + 11))
def main():
print mcc91(80)
print count
main()
MIPS计划
.data
p1:
.asciiz "What is integer n? "
ans1:
.asciiz "\nn is "
ans2:
.asciiz "\nCount is "
.text
.globl main
main:
li $v0, 4 # system call code for print_str
la $a0, p1 # address of string to print
syscall # print the first prompt
li $v0, 5 # system call code for read_int
syscall # read the first integer
move $t1, $v0 # and store it 'till later
li $t9, 0 #tracks count
loop1:
bgt $t1, 100, target1
add $t1, $t1, 11 #adds 11 when under 100
add $t9, $t9, 1 #add 1 to count
Loop1(loop1 #cluless how to do this
target1:
sub $t1, $t1, 10 #subtracts 10 when over 100
add $t9, $t9, 1 #add 1 to count
#j done #cluless here also(how many stacks in is it? If 0, jump to done)
done:
#THIS PRINTS N
li $v0, 4 # system call code for print_str
la $a0, ans1 #address of string to print
syscall # print the answer identifying string
li $v0, 1 # system call code for print_int
move $a0, xxxxx # integer to print (sum)
syscall # print it
#THIS PRINTS Count
li $v0, 4 # system call code for print_str
la $a0, ans2 # address of string to print
syscall # print the answer identifying string
li $v0, 1 # system call code for print_int
move $a0, xxxxx # integer to print (difference)
syscall # print it
jr $ra # return from this program to the system
答案 0 :(得分:0)
将python编译为C,然后使用您选择的C编译器将其转换为汇编。