Any good references for AT&T/GAS x86 Assembler Syntax?

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
Most stuff is easy enough to convert from Intel to GAS, but for example I'm trying to figure out the GAS form of the 3-operand "imul" instruction, so I'm not really sure exactly what order the operands go in.

I've been using this site as a reference, however it's for Intel Syntax.
 

Cogman

Lifer
Sep 19, 2000
10,284
138
106
wouldn't it be something like

imull sourcea, sourceb, dest ?

I mean, your options are
register, imm, dest
or
imm, register, dest.
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
wouldn't it be something like

imull sourcea, sourceb, dest ?

I mean, your options are
register, imm, dest
or
imm, register, dest.

Yea... I mean I can figure each instance out pretty quickly through trial and error, but I've had similar questions rather frequently so I was seeing if there were any good resources out there I have overlooked.

FWIW, the imm is the first operand from what I've found.
 

Cogman

Lifer
Sep 19, 2000
10,284
138
106
Yea... I mean I can figure each instance out pretty quickly through trial and error, but I've had similar questions rather frequently so I was seeing if there were any good resources out there I have overlooked.

FWIW, the imm is the first operand from what I've found.

:) Assembly in general is going to be a trial and error thing. Even the resources for the superior Intel syntax are lacking :p.
 

dinkumthinkum

Senior member
Jul 3, 2008
203
0
0
The info manual for "as" has a pretty large section on i386-specific syntax and features. Here is an interesting section.

9.13.15 Notes
-------------

There is some trickery concerning the `mul' and `imul' instructions
that deserves mention. The 16-, 32-, 64- and 128-bit expanding
multiplies (base opcode `0xf6'; extension 4 for `mul' and 5 for `imul')
can be output only in the one operand form. Thus, `imul %ebx, %eax'
does _not_ select the expanding multiply; the expanding multiply would
clobber the `%edx' register, and this would confuse `gcc' output. Use
`imul %ebx' to get the 64-bit product in `%edx:%eax'.

We have added a two operand form of `imul' when the first operand is
an immediate mode expression and the second operand is a register.
This is just a shorthand, so that, multiplying `%eax' by 69, for
example, can be done with `imul $69, %eax' rather than `imul $69, %eax,
%eax'.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
The info manual for "as" has a pretty large section on i386-specific syntax and features. Here is an interesting section.

That's correct, to specify 64-bit expanded multiply you specify a single operand to be multiplied by %eax and then stored in %edx:eax. To use regular multiplication you would specify two operands, first the source then the destination. My book has no reference to a 3 operand multiply operation.
 

Modelworks

Lifer
Feb 22, 2007
16,240
7
76
From the book on AS for linux I got for writing some drivers
http://www.amazon.com/gp/product/038...HRAN7Q7NY31V01
Format: imul src
imul dest,src
imul dest,src,constant
Description: This instruction performs signed multiplication. The number of operands for imul can be between 1 and 3, depending on the format used.

In the one-operand format, the other operand is assumed to be in the AL, AX, or EAX register depending on whether the s r c operand is 8, 16, or 32
bits long, respectively. The s r c operand can be either in a register or in
memory. The result, which is twice as long as the s r c operand, is placed
in AX, DX:AX, or EDX:EAX for 8-, 16-, or 32-bit s r c operands, respec-
tively. In the other two forms, the result is of the same length as the input
operands.
The two-operand format specifies both operands required for multiplica-
tion. In this case, s r c and d e s t must both be either 16-bit or 32-bit
operands. While s r c can be either in a register or in memory, d e s t must
be a register.
In the three-operand format, a constant can be specified as an immediate
operand. The result ( s r c x c o n s t a n t ) is stored in d e s t . As in the
two-operand format, the d e s t operand must be a register. The s r c can
be either in a register or in memory. The immediate constant can be an 8-,
16-, or 32-bit value. For additional restrictions, refer to the Pentium data
book. Clock cycles: 10(11 if the one-operand format is used with either
8- or 16-bit operands).