Hi

This is not really a win32 asm question, but this is the only ASM forum I know of.
I have been reading in art of assembler and ran across this example, which told the size using the add instuction.

add al, 2 //Two bytes long
add ah, 2 //Two bytes long
add ax, 2 //Three bytes long <-- error ?
add eax, 2 //Two bytes long

So I tried to execute it using the assembler in Delphi. I line 3 the operant is two bytes 0002, in the other lines the operant is just 02.
So is this an "error" in the Delphi assembler or is this just the way
Posted on 2002-01-14 11:11:04 by koger
koger,

ax is represented by 2 bytes. If you have any debugger (that you should if you've got DOS) you can see the registers and see that ax is, for example, 0000. Then, if you add this number 2 you are going to have 0002. But ah and al use 8 bits, so they are shown as 02, for example. ah is the high part and al is the low.

I'd suggest you to puy your little code in another debugger and see what i mean. More questions are appreciated.
Posted on 2002-01-14 18:51:34 by CodeLover
koger:
Look closely at the following code(opcode | mnemonics):
04 02 ADD AL,2
80C3 02 ADD BL,2
83C0 02 ADD EAX,2
83C3 02 ADD EBX,2
66:83C0 02 ADD AX,2
66:83C3 02 ADD BX,2
66:8BC3 MOV AX,BX
66:F7D0 NOT AX

Last 4 instruction has byte 66 in their code.
And all them - 16 bit register instruction
the two pares of instructions opcodes a similar exept for leading
66 byte:

83C0 02 ADD EAX,2
83C3 02 ADD EBX,2

66:83C0 02 ADD AX,2
66:83C3 02 ADD BX,2

It's called "prefix of operand size".
And it depends on address mode flags, in simple - in address mode
if you in 32 bit addressing mode
66:83C0 02
66:83C3 02
means
ADD AX,2
ADD BX,2
in 16 bit adressing mode the same
66:83C0 02
66:83C3 02
means
ADD EAX,2
ADD EBX,2
Posted on 2002-01-14 23:56:09 by The Svin
The AX, 2 is in Delphi assembled not to

ADD AX, 2 = 66:83C0 02

as you write but to

ADD AX, 2 = 66:0502 00


The ADD BX, 2 is the same.

Is the (what do you say?) instuction / opcode generated by Delphi faster/slower or is it just the same?

Perhaps it's is a dumb question but I'm only 1/4 way through the art of assembly book :)
Posted on 2002-01-15 04:50:02 by koger