Summary: NOTE: When posting messages, use the following HTML tags to make your message easier to read and understand. For more information, refer to Tips for Posting Messages. Use and for BOLD text. Use and for ITALICS text. Place source code source code between
and
. Your e-mail address is not published in the forum.
Message:
I noticed that there's something I can't understand - the sign extension that is performed when moving a 8-bit or 16-bit value to a register. How does it work?
Signed conventions follow 2's complement method i.e. to convert a positive number into negative number, 2's complement is used. The MSB indicates the sign (1 - negative, 0 - positive). The MSB is copied to all the bits if you try to represent the 1byte number to 2byte number.so, sign extension can be read as "make the value the same for a different bit length"
if you take 2's complement of 2,
0000 0010 -> 1byte 1111 1110 => 2s complement 0000 0000 0000 0010 -> 2byte 1111 1111 1111 1110 => 2s complement hence, -2 = 0xfe -> 1byte -2 = 0xfffe -> 2byte
thus value remains the same.
PS: if you have used scientific calculator to represent any negative number (perform signed operation), you will understand it clearly (you already have a calculator in windows)