so i have this following code which does this simple thing in mips

mult $t0, $t1

$t0 = -763
$t1 = 29

when I move the values from hi and lo registers to $t2 and $t3 i get following values for each
$t2 = -1 and $t3 = -22127

is this correct??? can someone explain me why?

here is the code

.text 
	.globl main
main:

addi $t0,$zero,-763
move $a0,$t0
li $v0, 1
syscall

la $a0, plus
li $v0, 4	#print_string
syscall

addi $t1,$zero,29
move $a0,$t1
li $v0, 1
syscall


mult	$t0,$t1

mfhi $t2
mflo $t3

la $a0, t0equals
li $v0, 4	#print_string
syscall

move $a0,$t0
li $v0, 1
syscall


la $a0, t1equals
li $v0, 4	#print_string
syscall


move $a0,$t1
li $v0, 1
syscall

la $a0, t2equals
li $v0, 4	#print_string
syscall
	
move $a0,$t2
li $v0, 1
syscall

la $a0, t3equals
li $v0, 4	#print_string
syscall

move $a0,$t3
li $v0, 1
syscall

li $v0, 10 # syscall code 10 is for exit.
syscall 

	.data
prompt:	 .asciiz "Please enter a (floating point) number: "
plus:	 .asciiz " + "
t0equals:	 .asciiz "\n t0 = "
t1equals:	 .asciiz "\n t1 = "
t3equals:	 .asciiz "\n t3 = "
t2equals:	 .asciiz "\n t2 = "
# end of add2.asm.

Recommended Answers

All 3 Replies

$LO = $s * $t

mult	$t0,$t1
mfhi $t2           # HI
mflo $t3           # LO

 la $a0, t0 equals
  li $v0, 4	#print_string
  syscall

#t2 is HI   #t3 is lOW
#  move $a0,$t0
   move $a0,$t3           # Print lower 32-bits
  li $v0, 1
  syscall

I am not following you. Can you please explain.

You perform an multiplication and store the 32-bit low result in register t3 and the upper 32-bits in register t2.

But you print register t0, one of the source operands of the multiplication, not t3 the lower 32-bit result!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.