Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For example, multiply 1732 by 546: ---------------------------------------------

ID: 3579888 • Letter: F

Question

For example, multiply 1732 by 546:

---------------------------------------------------______________________

.data
  
promptA: .asciiz " Enter number A: "

promptB: .asciiz "Enter number B: "

result: .asciiz "The product of multiplication is : "

.text
  
main:

li $v0, 4       # System call for print String
la $a0, promptA   # load address of prompt in $a0
syscall         
li $v0, 5       # system call code for read int
syscall           # read num into $v0
move $t1, $v0   # copy num into $t1

li $v0, 4       # System call for print String
la $a0, promptB # load address of prompt in $a0
syscall         
li $v0, 5       # system call code for read int
syscall           # read num into $v0
move $t2, $v0   # copy num into $t1

initializer:

li $s1, 1 # shift = 1
li $s2, 0 # product = 0
li $s4, 10
li $s5, 10

for:
andi $s3, $t2, 0x01 # mults with that one digit
mult $s3, $t1
mflo $t5 # saves that to t5
mult $t5, $s1 # subprod mul shift
mflo $t5
#add $t5, $t5, $0
mult $s1, $s4
mflo $s1
srl $t2, $t2, 1 # shifts 1 to right
# sll $t1, $t1, 1
beqz $t2, end
b for

end:

li $v0, 4 # system call code for print string
la $a0, result # load addr of projector in $a0
syscall   
li $v0, 1 # system call code for print int
move $a0, $t5 # move the number to read into $a0
syscall # print prompt # print prompt

Explanation / Answer


promptA:        .asciiz " Enter number A: "

promptB:       .asciiz "Enter number B: "

result:    .asciiz "The product of multiplication is : "

    .text
  
main:

     li    $v0, 4            # System call for print String
     la    $a0, promptA                # load address of prompt in $a0
     syscall           
     li    $v0, 5            # system call code for read int
     syscall                # read num into $v0
     move $t1, $v0                # copy num into $t1

     li    $v0, 4            # System call for print String
     la    $a0, promptB             # load address of prompt in $a0
     syscall           
     li    $v0, 5            # system call code for read int
     syscall                # read num into $v0
     move $t2, $v0                # copy num into $t1
   
initializer:

     li    $s1, 1                   # shift = 1
     li    $s2, 0                   # product = 0
     li    $s4, 10
     li    $s5, 10

for:
     andi   $s3, $t2, 0x01         # mults with that one digit
     mult   $s3, $t1
     mflo   $t5                     # saves that to t5
     mult   $t5, $s1                # subprod mul shift
    mflo   $t5
     #add    $t5, $t5, $0
     mult   $s1, $s4
     mflo   $s1
     srl    $t2, $t2, 1             # shifts 1 to right
#    sll    $t1, $t1, 1
     beqz   $t2, end
     b      for
   product = 0
   for each digit d of b, starting from the 1's column {
      subprod = a * d
      product = product + shift * subprod
      shift = shift * 10
   }

For example, multiply 1732 by 546:

       1732
      x 546
      -----
      10392 (1732 * 6 * 1)
      6928   (1732 * 4 * 10)
     8660    (1732 * 5 * 100)
     ------
     945672

   
end: