Van Gan
Van Gan

Reputation: 45

BNE branch in MIPS assembly

Right now I'm preparing for a test in computer architecture, and being stuck in a task that I don't really understand. * $1=4, $2=2, $3=x Here's the code

LOOP:
ADDI $2,$2-1
SLL $2,$2,2
MULT $3,$1
MFLO $3
SW $3, 0($2)
BNE $2,$1,LOOP

My question is, which value does $2 have after this? Is this 4 or 4x?

Upvotes: 1

Views: 876

Answers (1)

Crashworks
Crashworks

Reputation: 41374

Maybe it will be clearer if you write it out as ordinary paper math:

$1  = 4
$2  = 2
$3  = x
LOOP:
$2  = $2 -1
$2  = $2 * 2^2
$lo = $3 * $1
$3  = $lo
"contents of memory address in $2" = $3 
if $2 != $1 GOTO LOOP

Upvotes: 1

Related Questions