www.digitalmars.com         C & C++   DMDScript  

D - Dernel: Inline Assembler question

reply "=?iso-8859-1?Q?Robert_M._M=FCnch?=" <robert.muench robertmuench.de> writes:
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
Feb 24 2004
parent reply "Walter" <walter digitalmars.com> writes:
"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.
Feb 24 2004
parent reply "=?iso-8859-1?Q?Robert_M._M=FCnch?=" <robert.muench robertmuench.de> writes:
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
Feb 24 2004
parent "Walter" <walter digitalmars.com> writes:
"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


 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.
Feb 24 2004