Date: Sat, 16 Mar 1996 20:52:49 -0700 (MST) From: Terry Lambert <terry@lambert.org> To: jdp@polstra.com (John Polstra) Cc: nate@sneezy.sri.com, freebsd-hackers@freebsd.org Subject: Re: GAS question Message-ID: <199603170352.UAA18530@phaeton.artisoft.com> In-Reply-To: <199603152356.PAA02917@austin.polstra.com> from "John Polstra" at Mar 15, 96 03:56:56 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> > Most of this is obvious, but these two lines completely baffle me. > > > > : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=D" (cf) > > : "0" (*eax), "1" (*ebx), "2" (*ecx) > > This is GCC's "extended asm" syntax. The documentation is in the GCC > info pages. From the top-level node, follow the menu entry "C > Extensions", then "Extended Asm". > > Here's a quick answer for this specific case. The stuff after the > first colon specifies the output operands of the assembly code. > The stuff after the second colon specifies the input operands. > The quoted strings are GCC "constraints," which say more or less > specifically where each operand will be. In parentheses is the > corresponding C expression for each operand. > > For the output operands, the constraints here refer to specific hardware > registers: > > "a" means %eax > "b" means %ebx > "c" means %ecx > "D" means %edi > > The "=" on each output operand is required by gcc; it says that the > operand will be modified. > > For the input operands, the "0", "1", and "2" say that the three inputs > correspond in location to the first three output operands. In other > words, these operands are read, modified, and written back to the same > place. > > In the assembly code itself, "%3" refers to third operand. For > this, the operands are numbered from 0, output operands first, then > input operands. Here, "%3" refers to the local variable "cf", > which, according to its constraint "=D", is in the register %edi. Oh god, this sucks. A VC++ C variable reference from an inline addembler statement: void foo( unsigned long locklist) { unsigned long delta; ... __asm mov eax, delta __asm mov ebx, locklist ... } And Assembly for a C callable function (Win95 blue screen from a VXD, actually): IFSMgr_SYSMODAL_Message PROC C PUBLIC USES EBX EDI ESI \ pszMessage:DWORD, \ pszCaption:DWORD, \ dwFlags:DWORD VxDCall Get_Sys_VM_Handle ; handle in ebx mov eax, dwFlags mov ecx, pszMessage mov edi, pszCaption VxDCall SHELL_SYSMODAL_Message ; bluescreen with message ret IFSMgr_SYSMODAL_Message ENDP A C function without any preamble/postamble, and block inline assembly: __declspec(naked) void _peneter(save_edx) { _asm { mov eax, esp pushfd cli push eax mov edx, save_edx ... popfd ret } } Variable references are plain old variable references. Why is GCC so complicated? Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199603170352.UAA18530>