Sunday, 15 January 2012

assembly - What exactly does the lb instruction do? -



assembly - What exactly does the lb instruction do? -

i have exam coming up, , 1 of practice problems was:

assume $t0 contains value 0x12121212 , $t1 contains address 0x1000000.

assume memory data, starting address 0x1000000 is: 88 77 66 55.

what value of $t0 after next code executed:

lb $t0, 0($t1)

a) 0x00000088 b) 0x88121212 c) 0xffffff88 d) 0x12121288

the reply gave a, because byte lb instruction read (by understanding of instruction does) 88. 88 stored in $t0, value 0x00000088. reply given c. sense have fundamental misunderstanding how lb works - can please explain why reply c?

the reply c) 0xffffff88. lb instructions sign-extends byte 32-bit value. i.e. important bit (msb) copied upper 24 bits.

0x88 == 0b10001000, i.e. msb 1. upper 24 bits 0b111111111111111111111111 == 0xffffff.

assembly mips

No comments:

Post a Comment