我的任务是创建一个调用子程序的代码。
这是子程序
.data
msg1: .asciiz "Enter 4 integers A,B,C,D respectively:\n"
msg2: .asciiz "f_ten="
msg3: .asciiz "\nf_two="
msg4: .asciiz "\ng_ten="
msg5: .asciiz "\ng_two="
.text
main:
li $v0,4
la $a0,msg1 #program prints "Enter 4 integers A,B,C,D respectively:\n"
syscall
li $v0,5 #user enters integer A
syscall
move $t0,$v0 #stores integer A into t0
li $v0,5 #user enters integer B
syscall
move $t1,$v0 #stores integer B into t1
li $v0,5 #user enters integer C
syscall
move $t2,$v0 #stores integer C into t2
li $v0,5 #user enters integer D
syscall
move $t3,$v0 #stores integer D into t3
li $t6, 0 # sets t6 to zero
move $t4,$t0 #moves A into t4
move $t5,$t0 #moves A nto t5
jal multiply #multiplication of A by itsel
move $s0,$t6
li $t6,0 # resets t6 to zero
move $t4,$t1 #moves integer B ito t4
move $t5,$t3 #moves integer D into t5
jal multiply #multiplies B and D
sub $s0,$s0,$t6 #realizes function f
li $t6,0 # resets t6 to zero
move $t4,$t0 #moves A into t4
move $t5,$t3 #moves D into t5
jal multiply #multiplies A and D
move $s1,$t6
li $t6,0 # resets t6 to zero
li $t4,6 #sets t4 to 6
move $t5,$t2 #moves C to t5
jal multiply #multiplies C and 6
add $s1,$s1,$t6 #realizes function G
j printexit
multiply: #loop
beq $t4,$zero,term #when t4 is zero, end multiply
add $t6,$t6,$t5 #add t5 to t6 and store into t6
sub $t4,$t4,1 #subtract t4 by 1
j multiply
term:#endloop
jr $ra #return
printexit:
li $v0,4
la $a0,msg2 #program prints "f_ten="
syscall
li $v0,1 #displays f in decimal
move $a0,$s0
syscall
li $v0,4
la $a0,msg3 #program prints "f_two="
syscall
li $v0,35 #displays f in binary
move $a0,$s0
syscall
li $v0,4
la $a0,msg4 #program prints "g_ten="
syscall
li $v0,1 #displays g in decimal
move $a0,$s1
syscall
li $v0,4
la $a0,msg5 #program prints "g_two="
syscall
li $v0,35 #displays g in binary
move $a0,$s1
syscall
li $v0,10
syscall
使用除法的定义我需要显示:
h = ( f / g ); #returns h_quotient and h_remainder
i = ( f + g ) / h_quotient; #returns i_quotient and i_remainder
j = ( f – g ) % i_quotient; #returns j_remainder
as:
f_ten = 49026
g_ten = 13122
h_quotient = 3
h_remainder = 9660
i_quotient = 20716
i_remainder = 0
j_remainder = 15188
我不能为此使用宏、子例程或函数,并且在编写它时迫切需要帮助。