Hi,
I am in a lot of trouble right now. MIPS an assembly language programming. I need to implement multiplication in my program for numbers exceeding the 32 LO bit register. Here is my code to try to find 66 000 000^2. I will enter a number and try to find its square. Then the LO register will be printed followed by the HI register. Multiplication in MIPS by the multu command stores the result in a LO and HI register since the registers only store 32 bits.
.data
num_1: .word 66000000
space: .asciiz " "
.text
main:
lw $t0, num_1
multu $t0, $t0
mflo $t1
li $v0, 1
move $a0, $t1 # print t1, LO register
syscall
li $v0, 4
la $a0, space
syscall
mfhi $t2
li $v0, 1
move $a0, $t2 # print t2, HI register
syscall
li $v0, 10
syscall
Generates the results: 1218723840 1014210
When I ran the program with num_1 = 66000, the results were: 61032704 1
This shows 66000^2 -1*2^32 = 61032704
66000^2 = 1*2^32 +61032704
The LO register stored 61032704 and the HI register stored 1. In the run above, the LO register stored 1218723840 and the HI register stored 1014210.
66 000 000^2 = 1014210*2^32 +1 218 723 840
My question is how can I work with these large numbers in MIPS if the registers only store 32 bits? By work with, I mean I will need to multiply/divide the result 66000000^2 and print out the answer somehow. Well, with numbers on that magnitude, but not those exact numbers. Anybody with any theory here is wonderful. Thanks all.
I am in a lot of trouble right now. MIPS an assembly language programming. I need to implement multiplication in my program for numbers exceeding the 32 LO bit register. Here is my code to try to find 66 000 000^2. I will enter a number and try to find its square. Then the LO register will be printed followed by the HI register. Multiplication in MIPS by the multu command stores the result in a LO and HI register since the registers only store 32 bits.
.data
num_1: .word 66000000
space: .asciiz " "
.text
main:
lw $t0, num_1
multu $t0, $t0
mflo $t1
li $v0, 1
move $a0, $t1 # print t1, LO register
syscall
li $v0, 4
la $a0, space
syscall
mfhi $t2
li $v0, 1
move $a0, $t2 # print t2, HI register
syscall
li $v0, 10
syscall
Generates the results: 1218723840 1014210
When I ran the program with num_1 = 66000, the results were: 61032704 1
This shows 66000^2 -1*2^32 = 61032704
66000^2 = 1*2^32 +61032704
The LO register stored 61032704 and the HI register stored 1. In the run above, the LO register stored 1218723840 and the HI register stored 1014210.
66 000 000^2 = 1014210*2^32 +1 218 723 840
My question is how can I work with these large numbers in MIPS if the registers only store 32 bits? By work with, I mean I will need to multiply/divide the result 66000000^2 and print out the answer somehow. Well, with numbers on that magnitude, but not those exact numbers. Anybody with any theory here is wonderful. Thanks all.
Last edited: