assembly - MIPS: multiplying two 32 bit numbers, getting a 64 bit -


i attempting multiply 2 32 bit numbers in mips. have code here uses mult operation. use mfhi , mflo operations 2 parts mult, not sure how put these together. have them print out operations separately example.

the input numbers have been using are: 1143330295 , 999999223

the output program (obviously needs work) is: 266202121 -1483441327

the correct output 1143329406632360785 or can in binary if easier.

this code larger project working on have multiply 2 32 bit numbers using shift , add algorithm without using mult function. trying wrap head around representing 64 bit number first. advice/input.

.data      geta:    .asciiz "please enter first number(multiplicand): "      getb:    .asciiz "please enter second number(multiplier): "      space:    .asciiz " "      promptstart:    .asciiz "this program multiplies 2 numbers. "      mipmult:   .asciiz "the product, using mips mult is: "      endline: .asciiz "\n" .text main:     li  $v0,4                la  $a0,promptstart      syscall                   li  $v0,4                la  $a0,endline          syscall                  #prompt multiplicand     li  $v0,4               la  $a0,geta             syscall                   #acquire multiplicand     li  $v0,5               syscall                  move    $s0,$v0          move    $s5,$s0          #prompt multiplier     li  $v0,4                la  $a0,getb             syscall                   #acquire multiplier     li  $v0,5               syscall                 move    $s1,$v0          move    $s6,$s1     # copy       mult    $s5, $s6     mfhi    $t0     mflo    $t1      li  $v0,4             la  $a0,mipmult         syscall      # print out result (this not correct, need help)     li  $v0,1              move    $a0,$t0              syscall             li  $v0,4               la  $a0,space            syscall                  # print out result     li  $v0,1               move    $a0,$t1             syscall                # print line feed     li  $v0,4                la  $a0,endline          syscall                    li  $v0,10               syscall             # exit program 

i guess dealing unsigned integers, should use multu instead of mult.

to print 64-bit number in decimal think can implement algorithm takes modulus 10 of 64 bit number, stores somewhere in memory, , repeat quotient until quotient zero. traverse string in reverse order print number digit-by-digit.

in question said ok print number in binary. easier can print value of each bit left right both registers (hi order first, low order).

to that, besides using multu instead of mult change call

# print out result (this not correct, need help)     li  $v0,1              move    $a0,$t0              syscall       li  $v0,4               la  $a0,space            syscall                 # print out result     li  $v0,1               move    $a0,$t1             syscall 

with

move $t2, $t0 jal print_binary move $t2, $t1 jal print_binary 

and add subroutine:

# $t2 should hold number print in binary print_binary:      li $t3, 32      li $v0, 1 print_bit:      subiu $t3, $t3, 1      srlv $a0, $t2, $t3      andi $a0, $a0, 1      syscall      bgtz $t3, print_bit      jr $ra 

Popular posts from this blog