architecture - mips converting to assembly -


i working writing mips assembly following statement:

f = - 20 + b + c - d 

using following registers

 $1   $2  b  $3  c  $4  d  $5  f  $6  g  $7   $8  j  $9   10$ d 

my answer this:

 add  $5,$2, $3 // f=b+c  addi 5$,5$,-20 // f=f+(-20)  add  $5,$1,5$  // f=a+f   sub  $5,$5,$4  // f=f-d  sw   $5,o($5)  // stores answer 

now constant -20 throwing me off little , , i'm not sure if handled right.

or do:

 add  $5,$2,$3  addi $5,$5,20  sub  $5,$1,$5  sub  $5,$5, $4  sw   $5,0($5) 

do not use $1, it's reserved assembler $at pseudoinstructions.

your code this

addui $5, $1, 0xffec # or a-20 in twos complement, should same addu $5, $5, $2      #  addu $5, $5, $3      # subu $5, $5, $4      # 

this line

sw $5,o($5) // stores answer 

doesn't make sense, you're saving $5 $5 + o, looks result-dependant location.

your second code, however, incorrect, mean

f = - (b + c + 20) - d f = - b - c - 20 - d 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -