assembly - Can somebody tell me How , i can solve it , and how i can learn it -


assume following program run in 32-bit little-endian mips processor

addi sr1. sr0, 0x80000000 ,  sr3, sr2, sr1 beq  sr3, sr0, end  addi sr2, sr2, 1  end: 
  1. register sr2 stores x, signed integer. function executed program , written in high level language?

  2. what value stored in sr2, @ end of program , if sr2=0xfffffff5

please can tell me , how can start learning or book?

it's late here take grain of salt.

the function increment x if negative

int unknown(int x) { return x<0 ? ++x : x;} 

the first instruction set $r1 value 0x80000000 bit mask. use fact $0 0, $r1 = 0 + 0x80000000 = 0x80000000.

the second instruction ands $r2 (the x value) $r1 (the bit mask) , store result in $r3. result 0x80000000 if , if x negative (see 2 complement format) otherwise zero.

the third instruction jump end if $r3 zero, i.e. if x positive or zero.

the last instruction increment x , executed if x negative.

if $r2 = 0xfffffff5 x -11 (again 2 complement).
after function x -10 , $r2 = 0xfffffff6.

note: convert , 2 complement not number , add one.


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 -