Hi,

Am a self teaching Newbie Assembly programmer :) Still in the theoretical Stages.

My question is....

According to the book am reading

When you convert 254(decimal) to hexadecimal you get 0FEh.

And when you convert -2(decimal) to hexadecimal using two's complement you get OFEh.

When i do it manually i get FEh.

Is the zero before FEh always necessary or is it just another way of representing your code..?
Am fully aware that 0 in hexaecimal stands for 0000(base 2)

Thanks in advance......

Recommended Answers

All 7 Replies

Hi,

Am a self teaching Newbie Assembly programmer :) Still in the theoretical Stages.

My question is....

According to the book am reading

When you convert 254(decimal) to hexadecimal you get 0FEh.

And when you convert -2(decimal) to hexadecimal using two's complement you get OFEh.

When i do it manually i get FEh.

Is the zero before FEh always necessary or is it just another way of representing your code..?
Am fully aware that 0 in hexaecimal stands for 0000(base 2)

Thanks in advance......

Well, the 0 of 0FEH is wrong if it should represent -2D. The most significant bit (msb) of an integer numbers always indicates whether the number is positive or negative. msb = 0 is for positive numbers, msb=1 stands for negative numbers, where negative whole numbers usually are in two's complement.

Let's code -2D in binary 2k and then in hex 16k:

2D = 10 --> extend it by some 0 to indicate true positive number: 0000 0010
now 1K: 1111 1101, 2k = 1k + 1 = 1111 1101 + 1 = 1111 1110B
-2D = 1111 1110B = FEH

If you add a 0, you get 0FEH, binary: 00001111 1110B what is a positive number, therefore wrong! If you want to extend a negative whole number, you must extend with the sign bit, that is for example FEH = FFFEH = FFFFFFFEH.

-- tesu

commented: Simple but informative +1

Now I see you are a assembly programmer. Here the leading 0 has a special meaning.

Consider this two instructions:

MOV AL, FEH
MOV AL, 0FEH

In first instruction the value of the variable FEH (it is an offset) is moved into reg. AL. Therefore such variable must exists in data segment, for example by definition: FEH DB 1

In second instruction the 8-bit constant FEH is moved into 8bit reg. AL.

Also consider these:

;; negative FEH should be loaded:
MOV AX, 0FEH    ;;; wrong, bcause AX is filled with: 000000FEH
MOV AX, 0FFFFFFFEH    ;;; correct, AX is filled with FFFFFFFEH

-- tesu

As far as I know the assembler can't tell if you're trying to declare a variable or referencing one because variables can start with any letter, including those used in base 16. If I understood your question right, you must put a zero before the hexadecimal value to say the assembler its a number... Normally becomes 0FEh... FE isnt the same as 0FE because the assembler will treat FE as a variable name and 0FE as a hexadecimal number...

Wow! Thanks You taught me a lot from those few lines.

1k and 2k stands for 0ne's and two's complement respectively right???

Is msb (most significant bit) same as high order bit (H.O bit) and is L.O bit also same as lsb (least significant bit)???

If you want to extend a negative whole number, you must extend with the sign bit, that is for example FEH = FFFEH = FFFFFFFEH.

i didn't get this last part most probably i will get it when i read further.
Thanks....

If I understood your question right, you must put a zero before the hexadecimal value to say the assembler its a number... Normally becomes 0FEh.

If you add a 0, you get 0FEH, binary: 00001111 1110B what is a positive number, therefore wrong! If you want to extend a negative whole number, you must extend with the sign bit

isn't this contradictory???

uuuuum Okay getting a little confused here let me check my books and ill get back to you.

Hi Madawar,

first i have to correct the following line:

>> MOV AX, 0FFFFFFFEH ;;; correct, AX is filled with FFFFFFFEH

is wrong because length of AX is 16bits. Therefore correct is:

MOV AX, 0FFFEH ;;; correct, AX is filled with FFFEH

1k is short for one's complement (in Bavaria;))
2k is two's complement

msb = h.o. bit, lsb = l.o. bit

As for sign extension: we have negative whole number FEH = 1111 1110H. If we want to extend it for some reason, extension must be done with sign bit, for example 11 1111 1110B. How to translate it back into hex? each hex figure consist of 4 bits, therefore further extension must be made: 11 11 1111 1110B = FFEH. For 80x86 all register are divisible by 4 so sign extension usually happens in portion of 4 bits that makes just a hex figure, FEH, FFFEH, FFFFFFFEH (for al, ax, eax).

Btw, for 80x86 there exists a special move instruction MOVSX for move with sign extension.

Dante's very good explanation didn't cover negative whole numbers too, so you can't hardly say there would be a contradiction.

-- tesu

Av understood now! thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.