Thread overview
Dernel: Inline Assembler question
Feb 24, 2004
Robert M. Münch
Feb 24, 2004
Walter
Feb 24, 2004
Robert M. Münch
Feb 24, 2004
Walter
February 24, 2004
Hi, I have the following code:

asm {
mov EDX, port;
mov EAX, v;
db 0xEE;
// out DX, AL;
}

Which translates to:

		enter	4,0
		push	EBX
		push	ESI
		push	EDI
		mov	-4[EBP],EAX
		mov	EDX,8[EBP]
		mov	EAX,-4[EBP]
		out	DX,AL
		pop	EDI
		pop	ESI
		pop	EBX
		leave
		ret	4

And I tried:

asm {
mov EDX, port;
mov EAX, v;
out DX, AL;
}

Which translates to:

		enter	4,0
		mov	-4[EBP],EAX
		mov	EDX,8[EBP]
		mov	EAX,-4[EBP]
		out	DX,AL
		leave
		ret	4
		nop
		nop

0xEE is the one-byte opcode for "out DX, AL". Why this difference in the generated code? Why does the first version, safes and restors the listed registers? Is this necessary or does the 2nd version work as well?

-- 
Robert M. Münch
Management & IT Freelancer
http://www.robertmuench.de
February 24, 2004
"Robert M. Münch" <robert.muench@robertmuench.de> wrote in message news:opr3v41vfqheztw6@news.digitalmars.com...
> 0xEE is the one-byte opcode for "out DX, AL". Why this difference in the generated code? Why does the first version, safes and restors the listed registers? Is this necessary or does the 2nd version work as well?

Because register contents are only tracked when using mnemonics, not when writing arbitrary hex bytes. In the latter case, the assembler assumes all registers are modified.


February 24, 2004
On Tue, 24 Feb 2004 12:55:17 -0800, Walter <walter@digitalmars.com> wrote:

> Because register contents are only tracked when using mnemonics, not when
> writing arbitrary hex bytes. In the latter case, the assembler assumes all registers are modified.

Hi, you mean in the first case the assembler assumes all registers are modified and that's why these are safed and restored, right?

-- 
Robert M. Münch
Management & IT Freelancer
http://www.robertmuench.de
February 24, 2004
"Robert M. Münch" <robert.muench@robertmuench.de> wrote in message news:opr3v7vidjheztw6@news.digitalmars.com...
> On Tue, 24 Feb 2004 12:55:17 -0800, Walter <walter@digitalmars.com> wrote:
>
> > Because register contents are only tracked when using mnemonics, not
when
> > writing arbitrary hex bytes. In the latter case, the assembler assumes all registers are modified.
>
> Hi, you mean in the first case the assembler assumes all registers are modified and that's why these are safed and restored, right?

Yes. You can also use 'naked' and handle the register save/restore manually.