I tried to make a program which read 64 bit integer into two registers on RARS.
Then, when multiplying 32 bit unsigned integers by 10, I wrote
mulhu s3, s3, s2 #s2 is 10
, but s3 doesn't change form 0.
Then when I wrote
mul s3, s3, s2
it worked, but s3 is still signed integer.
The following is a part of the program.
.eqv SYS_EXITO, 10
.eqv CON_PRTSTR, 4
.eqv CON_PDSTR, 8
.eqv BUFSIZE, 100
.data
prompt:
.asciz "64 bit input:"
result:
.asciz "64 bit addition output:"
buf:
.space BUFSIZE
.text
main:
la a0, prompt
li a7, CON_PRTSTR
ecall
la a0, buf
li a1, BUFSIZE
li a7, CON_PDSTR
ecall
# processing
la t0, buf # t0 is the address of data (load address)
mv t1, t0 # t1=t0
li t3, ' '
li t4, '0'
li t5, '9'
li s1, '1'
li s2, 10
li s3, 0 #low 32 bit1
li s4, 0 #high 32 bit1
li s5, 429496729 #4294967295 divided by 10
digit:
lbu t2,(t0) #load t0 to t2
bltu t2, t3, second #second number if below space
bleu t2, t5, lessthan9 #if t2<=9, digit
addi t0, t0, 1 #source++
addi t1, t1, 1 #else destination++
b digit
lessthan9:
bgeu t2, t4, biggerthan0 #if t2>=0,goto digit2
addi t0, t0, 1 #source++
addi t1, t1, 1 #else destination++
j digit
biggerthan0:
addi t0, t0, 1 #source++
sub t2, t2, t4 #t2-'0'
add s3, s3, t2 #load to low 32 bit
bgt s3, s5, highfirst #jump if s3 is bigger than 429496729
mul s3, s3, s2 #It works, but I want to multiply unsigned integers.
#So, s3 should be between 0 to 4294967295
mulh a2, s3, s2 #I'm not sure why s3 doesn't change from 0
mulh a3, s2, s3 #Same as above
mulhu a4, s3, s2 #Same as above
j digit
So, how can I write the program which multiply unsigned integers?