0

我被困在一个堆栈上。我必须在汇编代码中调用一个函数mips-32,在其中我必须通过给出 the和as 参数来评估Hermite 多项式。它必须使用递归来完成。nx

我尝试设置 2 个基本情况H0H1,同时使用它们,但我无法识别使代码清晰的序列和堆绘制。

遵循代码:

li $t2,2

recursive_hermite: #H(n,x,___,___)      
        bge     $a0,$t5,more_than_2         
        ####    base
        ####    case

         jr $ra ##<--- this takes us to the operation of the value
    more_than_2:

        ## here you are supposed to store the values on stack 
        ##     (such as return address and n values)

      addi $a0,$a0,-1         ##you must decrease n (or increase I'm not sure)
      jal recursive_hermite   ##once they are stored, you just recall  

    ### operations of value



    ## $f12 must contain the whole value
    jr $ra         ####this one returns to the main

有谁知道如何解决这个问题?

4

1 回答 1

0

我看你有麻烦了。从你写问题的方式来看,你的作业似乎明天就要到期了,所以我们必须尽快完成工作。

你让我想起了 20 年前的自己,那时 C++ 刚刚诞生,汇编风靡一时。我听说过像 QTspim 这样令人毛骨悚然的 MIPS 仿真器,您应该避免使用它们,并像真正的男人一样使用一些真正方便的硬件工作。

这是我的提示:您必须存储在每次递归中测试的多项式的部分结果。要做到这一点,你必须控制时间和空间,它们必须像所有事物一样完美平衡。

如果我是你,我会开始逐步执​​行程序,这样你就可以检查寄存器值是什么。

一个人去很危险,拿着这个:

    .data

  #COMPUTER PRINCIPLES UNIVERSITY OF MACANDCHESTER
  #PRACTIC 5: HERMITE POLINOMYALS CALCULUS
  #JACK ROBERTS II


  userInput:    .space  700
  empty:   .asciiz "Input is empty."
   long:    .asciiz "Input is too long."
  invalid: .asciiz "Invalid base-33 number."

.text

ErrorLong:
#prints message for input that is too long
  la $a0, long
  li $v0, 4
  syscall
  j end

ErrorInvalid:
#prints message for invalid input
  la $a0, invalid
  li $v0, 4
  syscall
  j end

ErrorEmpty:
#prints message for empty string
  la $a0, empty
  li $v0, 4
  syscall
  j end

.globl main

main:
  li $v0, 8
  la $a0, userInput
  li $a1, 200
  syscall

Rid:
#takes care of leading spaces
li $t9, 32 # space
lb $t8, 0($a0)
beq $t9, $t8, Character
move $t8, $a0
j length

Character:
addi $a0, $a0, 1
j Rid

#takes care of length
length:
addi $t0, $t0, 0
addi $t1, $t1, 10
add $t2, $t2, $a0

#itertates through the array
traverse:
lb $s2, 0($a0)
beqz $s2, discovered
beq $s2, $t1, discovered
addi $a0, $a0, 1
addi $t0, $t0, 1
j traverse

#busted empty space or input that violates limit
discovered:
#if it's empty go to case for empty which outputs 
beqz $t0, ErrorEmpty
slti $t4, $t0, 5
#if it's too long, go to case for too long and print 
beqz $t4, ErrorLong
move $a0, $t2
#go to next verification process
j verify

#Comenzamos a calcular H0
verify:
lb $s3, 0($a0)  #loads address here
beqz $s3, initial
beq $s3, $t1, initial
slti $t3, $s3, 48                 #invalid for anything below 0
bne $t3, $zero, ErrorInvalid
slti $t3, $s3, 58                 #legal input for everything less than or equal to 9
bne $t3, $zero, Move
slti $t3, $s3, 65                 #legal input for everything less than or equal to 65,  'a'
bne $t3, $zero, Move
slti $t3, $s3, 88                 #legal input for anything less than or equal to 88
bne $t3, $zero, Move
slti $t3, $s3, 97                 # invalid input, not numerical nor alphabetical
bne $t3, $zero, ErrorInvalid
slti $t3, $s3, 120                #legal input for lower case characters
bne $t3, $zero, Move
bgt $s3, 119, ErrorInvalid   # illegal input, out of range

#now I iterate again, this time to check for invalid input
Move:
addi $a0, $a0, 1 #iterates
j verify #goes to verification point

#first step of conversion, does the prerequisite work for translation 
initial:
move $a0, $t2  #moves content
addi $t5, $t5, 0  #$t5 has 0 now
add $s0, $s0, $t0  
addi $s0, $s0, -1 #decrement    
#aqui empieza lo bueno

Must:
addi $sp, $sp, -16
sw $ra, 0($sp)
sw $ra, 4($sp)
sw $ra, 8($sp)
sw $ra, 12($sp)
jal Must

ExitMust:

lw  $ra,16($sp)
lw $s4, 3($sp) 
lw $s5, 2($sp)
lw  $s6, 1($sp)
lw $s1, 0($sp)

jr $ra   #return

#li $s4, 3  #each digit
#li $s5, 2
#li $s6, 1
#li $s1, 0

translate:
lb $s7, 0($a0)   #loads digits
beqz $s7, final  #final conversion step
beq $s7, $t1, final #if branch statement is true, move to final conversion statement
slti $t3, $s7, 58  #checks for less than or equal to 58
bne $t3, $zero, Base  #OK to move forward if $t3 is not null
slti $t3, $s7, 88  #max for upper
bne $t3, $zero, Mari  #OK to go to conversion of upper characters if $t3 is not null
slti $t3, $s7, 120     #max for lower
bne $t3, $zero, Mici #OK to go to conversion of lower characters if $t3 is not null

Base:
addi $s7, $s7, -48  #conversion for regular numbers
j row

Mari:
addi $s7, $s7, -55  #conversion for upper case
j row

Mici:
addi $s7, $s7, -87  #conversion for lower case

row:  #determines which digit needs to be converted
beq $s0, $s4, one  
beq $s0, $s5, two
beq $s0, $s6, three
beq $s0, $s1, last

#first character
one:
li $t6, 35937   #values to multiply by for the power of 3
mult $s7, $t6
mflo $t7
add $t5, $t5, $t7
addi $s0, $s0, -1
addi $a0, $a0, 1
j translate

#second character
two:
li $t6, 1089   #values to multiply by for the power of 2
mult $s7, $t6
mflo $t7
add $t5, $t5, $t7
addi $s0, $s0, -1
addi $a0, $a0, 1
j translate

#third character
three:
li $t6, 33   #values to multiply by for the power of 1
mult $s7, $t6
mflo $t7
add $t5, $t5, $t7
addi $s0, $s0, -1
addi $a0, $a0, 1
j translate

#fourth character
last:
li $t6, 1    #values to multiply by for the power of 0
mult $s7, $t6
mflo $t7
add $t5, $t5, $t7
#no more need to go back to translation step


final:                  #final step
li $v0, 1
move $a0, $t5  #moves content to $a0 so it can be printed
syscall

#last system call of the program will end program
end:   #prints result
 li $v0, 10

希望对您有所帮助,如果您需要,请在此处进一步解释,它已直接从我的期末作品和我的硕士课程中删除。

PD:它是在 GPL 下获得许可的,所以要小心使用它,FBI 可能正在寻找你。爱 :)

于 2019-05-13T12:10:24.630 回答