during looking in my debugger, I found something I didnt know before -

two different opcode representations of the same asm command:

31 C9 xor cx, cx
33 C9 xor cx, cx

after some bit "unwire-ing" I found that
the commands are really equal. Same effect also for some mov and add instructions.

8B C1 mov ax, cx
89 C8 mov ax, cx

Is there a difference between the above in execution time? Can I force the assembler to use the one or other?
Posted on 2002-02-01 04:55:28 by beaster
beaster,

its common in Intel opcodes for x86 to have redundant instructions, they are there mainly for clarity reasons in coding. An opcode is an opcode, just plug in the opcode you want, the mnemonic is just a convenience.

Regards,

hutch@movsd.com
Posted on 2002-02-01 05:19:12 by hutch--
Beaster, it is possible to encount up to 3 different
forms for on given mnemonic. Example:

MOV EAX,[2300h]

NASM will say: A1 00 23 00 00
A386 will say: 67 A1 00 23
MASM will say: B8 00 23 00 00

(This is an example, i paste and copy from a new Assembler
test Source i am checking).

In several cases, the encodings may vary in length. So,
the shorter form is often prefered. But as you see upper,
not always. In the upper example, i think that the choice
of Eric Isaacson, for this particular shorter form is not
the good one, at a speed point of vue... but, as always,
unsure, because 'Case-Speed' may vary from Processor to
Processor.

Any case, you do not have to bother with this, it has
really very low (if any) relationship with any real life
programming considerations. Code optimisation is ridiculous,
usually, but Code optimisation, at this one level, would
be really crazy :)


Betov.
Posted on 2002-02-01 06:55:49 by Betov
The Intel/AMD manuals state to use the shorter forms.
This is to decrease the loads needed by the instruction cache.
Posted on 2002-02-01 09:58:52 by bitRAKE
Yes, there are two encodings for several instructions using two registers. One register is encoded in an "register" field, and the other is encoded in a more general "address" (r/m) field. A direction flag determines which operand is the destination.

You can view mov as two instructions: load and store.

With the alternate convention that the second operand is a potential memory operand, the following two commands are equal:

load eax,ecx
store ecx,eax

(parallel to the following syntax:)

load eax,mem
store ecx,mem
Posted on 2002-02-01 15:54:24 by tank
MOV EAX,[2300h]

NASM will say: A1 00 23 00 00
A386 will say: 67 A1 00 23
MASM will say: B8 00 23 00 00

A note on these examples. The A386 version is shorter, but it uses a prefix (67), and stores the data as a 16 bit value. It's ususlly not a good idea to mix 16 and 32 bit items in a 32 bit program. The prefix almost always causes a performance hit.

16 bit instructions are often shorter than their 32 bit equivalent, even with the added prefix, but they should still be avoided in 32 bit programs. Agner Fog describes this in great detail.

:)
Posted on 2002-02-02 12:30:08 by S/390
This is exactely what i mean, S/390, i know that Beaster is a great boy enough to understand by himself what is a prefix.

Betov.
Posted on 2002-02-02 13:36:06 by Betov
S/390, thanks for writing the bit about prefixes, I'm sure a lot of the
younger programmers don't know about them.

They can be useful if you strive for size and not speed, but out of
intro competitions (4096 bytes and below), I can't see any "good"
use for them, as they tend to slow down stuff.
Posted on 2002-02-03 16:45:57 by f0dder
i know that Beaster is a great boy enough to understand by himself what is a prefix

thanks (maybe I make a poll about this question :) :) )

originally I compared an original Win95b bootblock from MS with my own assembled (source from Internet) and found some differences in hexdump but not in disassembly.

So mainly I was afraid, if some of the addressing modes will not be available durin boot process (somewhat 8086 mode),
but now it seems that this does not matter.

I do this just for fun, I dont like to make my own OS ...

Btw, I found this funny comment in one of the assembly sources:

; AFTER DISASSEMBLY I have this impression:
;
; This is what Bill Gates said... when Win95 was going to be released:
;
; "Gates: OK, then we're ready to press the CD's and start shipping out
; this new load of shit, but of course nobody will notice... harr harr.
; Employee: Hey, Mr. Gates what about the Boot Sector?? We haven't
; written the FAT32 support routines there yet...
; Gates: Ah, that's right... anybody?? We have just 45 minutes...
; Employee #2: Well, I think I can hack some shit together...
; Gates: Fine, go for it... remember you have only 44 minutes...
; Employee #2: I think I can do it.
; Gates: Fine, then I'll just go home... We've made it!!"
Posted on 2002-02-04 04:07:53 by beaster