## long mult -- multiplies two 32-bit integers ## Register usage: ## This program accomplishes the same thing as mul or mult ## But this shows the inner workings. ## $t1 ­ mask ## $t2 ­ multiplier (and right_hand_sum). ## $t3 ­ left_hand_sum. ## $t4 ­ multiplicand. ## $t5 - clear. ## $t6 - rightmost bit of left_hand_sum. ## $t7 - rightmost bit of right_hand_sum. ## $t8 - counter ## $v0 ­ syscall parameter / return values. ## $a0 ­ syscall parameters. ## $a1 ­ syscall parameters. .text .globl __start __start: ## read the two integers li $v0, 5 # load multiplicand. syscall move $t4, $v0 li $v0, 5 # load multiplier. syscall move $t2, $v0 lw $t1, mask lw $t5, clear li $t8, 32 continue: beqz $t8, end and $t7, $t1, $t2 beqz $t7, shift add $t3, $t3, $t4 shift: and $t6, $t3, $t1 # store rightmost bit og l_sum in $t6 and $t2, $t2, $t5 # clear rightmost bit of r_sum or $t2, $t2, $t6 # move stored right bit of l_sum to rightmost position of r_sum ror $t2, $t2, 1 # rotate r_sum srl $t3, $t3, 1 # shift l_sum right # Use sra for twos complement numbers addiu $t8, $t8, -1 b continue end: sw $t2, r_sum sw $t3, l_sum li $v0, 10 syscall .data r_sum: .word 0 l_sum: .word 0 mask: .word 0x00000001 clear: .word 0xFFFFFFFE