0

im tasked with creating a code that calls a sub program.

this is the sub program

.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

using the definition of division i need to display:

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 

I cannot use Macro, Subroutines, or Functions for this and desperately need help in writting it.

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • I do not really understand what you want. Something equivalent to the "multiply" subroutine? (BTW, it works, but is an inefficient way to perform multiplication). But what means "I cannot use Macro, Subroutines" if you have to do a subroutine. Are you allowed to use the `div` instruction? Could you give additional precisions? – Alain Merigot Feb 14 '19 at 10:05
  • I cant use the div instruction. I have to use a pseudo instruction with a loop to do the division. For instance in the above sub program i used a loop for the multiplication. I just cant figure out how to call that sub program into the new one to read the answers of F and G, then have it preform the loop for the division processes, – Cassie Lonis Feb 20 '19 at 16:45

0 Answers0