s***@crayne.org
2006-01-02 21:24:21 UTC
I am using gnu assembler 2.13 and targeting an x86 architecture... My
desired behavior is that I want to push a 16 bit immediate value onto a
stack, and then call a subroutine which will pop that same value off
into ax. I do not want to move the immediate into ax and then push ax.
That uses more instructions. :)
Opcode 68 achieves this, and places a 16b immediate onto the stack.
0x68 is also push imm32.
Opcode 6A is push 8b immediate
GAS seems to pick the instruction based on the length of my constant.
If I specify a constant that can be represented in 8 bits, then GAS
selects the imm8 version of the instruction. Even if I try to override
the instruction size, GAS picks 0x6a for the opcode. If I select a 16b
immediate that cannot be represented in 8bits, then GAS picks opcode
0x68.
If I handcode my instruction, as is the case on listing-line 54, I can
get an opcode 68.
Is there a mechanism to force a 16b sign extended (in this case 0
extended) immediate push without handcoding the assembly? I'd prefer to
use intel syntax, but I'll use AT&T if necessary. Maybe this is more of
a sign extending/variable sizing question?
Thanks!
--eric
***@ldclo6401> as -v
GNU assembler version 2.13.2.1 (x86_64-unknown-linux-gnu) using BFD
version 2.13.2.1
49 .intel_syntax
50 0000 666A0C pushw 12
51 0003 66683412 pushw 0x1234
52 0007 666A09 pushw 0x0009
53 000a 6668000C .byte 0x66, 0x68, 0x00, 0x0c #handcode the
push word immediate
54 .att_syntax
55 000e 6A0D pushl $13
56 0010 53 pushl %ebx
57 .intel_syntax noprefix
58 0011 666A0D push (word ptr 13)
desired behavior is that I want to push a 16 bit immediate value onto a
stack, and then call a subroutine which will pop that same value off
into ax. I do not want to move the immediate into ax and then push ax.
That uses more instructions. :)
Opcode 68 achieves this, and places a 16b immediate onto the stack.
0x68 is also push imm32.
Opcode 6A is push 8b immediate
GAS seems to pick the instruction based on the length of my constant.
If I specify a constant that can be represented in 8 bits, then GAS
selects the imm8 version of the instruction. Even if I try to override
the instruction size, GAS picks 0x6a for the opcode. If I select a 16b
immediate that cannot be represented in 8bits, then GAS picks opcode
0x68.
If I handcode my instruction, as is the case on listing-line 54, I can
get an opcode 68.
Is there a mechanism to force a 16b sign extended (in this case 0
extended) immediate push without handcoding the assembly? I'd prefer to
use intel syntax, but I'll use AT&T if necessary. Maybe this is more of
a sign extending/variable sizing question?
Thanks!
--eric
***@ldclo6401> as -v
GNU assembler version 2.13.2.1 (x86_64-unknown-linux-gnu) using BFD
version 2.13.2.1
49 .intel_syntax
50 0000 666A0C pushw 12
51 0003 66683412 pushw 0x1234
52 0007 666A09 pushw 0x0009
53 000a 6668000C .byte 0x66, 0x68, 0x00, 0x0c #handcode the
push word immediate
54 .att_syntax
55 000e 6A0D pushl $13
56 0010 53 pushl %ebx
57 .intel_syntax noprefix
58 0011 666A0D push (word ptr 13)