nasm - ASM question, two's complement -


so book "assembly language step step" awesome, sort of cryptic how two's complement works when working on actual memory , register data. along that, i'm not sure how signed values represented in memory either, feel might what's keeping me confused. anywho...

it says: "-1 = $ff, -2 = $fe , on". understand two's complement of number multiplied -1 , when added original give 0. so, ff hex equivalent of 11111111 in binary, , 255 in decimal. question is: what's book saying when says "-1 = $ff"? mean -255 + -1 give 0 also, didn't explicitly, set of flag?

so in practice... let's have 11h, 17 in decimal, , 00100001 in binary. , value in al. neg al, , set cf , sf, , change value in al to... 239 in decimal, 11101111 in binary, or efh? don't see how 17 * -1? or poorly worded explanation book, means gives value need cause overflow?

thanks!

in two's complement, bytes, (-x) == (256 - x) == (~x + 1). (~ c'ish not operator, flips bits in operand.)

let's have 11h.

100h - 11h == efh (256 - 17  == 239) 

note, 256 works bytes, cause they're 8 bits in size. 16-bit words you'd use 2^16 (65536), dwords 2^32. note math mod 256 bytes, 65536 shorts, etc.

or, using not/+1,

~11h = eeh +1...  efh 

this method works words of sizes.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -