How to translate NASM "push byte" to GAS syntax?

I port the NASM source to GAS and I found the following lines of code:

push byte 0 push byte 37 

GAS does not allow push-byte or pushb.

How to translate the above code into GAS syntax?

thanks

+4
source share
2 answers

pushb been removed from GAS. You should be able to use the push command to get the same effect. A bit more info here .

+5
source

1) push byte in NASM 2.11 64-bit compilations are similar to push only, except that it refuses to compile if the marked thing is more than a byte:

 push 0x0000 push 0x01 push 0x0001 push 0x10 

Same as:

 push byte 0x0000 push byte 0x01 push byte 0x0001 push byte 0x10 

But the following failure:

 push byte 0x0100 push byte 0x1000 push byte 0x01000000 push byte 0x10000000 

All of them are compiled into form 6a XX instructions.

2) NASM and GAS automatically determine which form to use based on the size of the operand:

GAZ 2.25:

 push $0x0000 push $0x01 push $0x0001 push $0x10 push $0x0100 push $0x1000 push $0x01000000 push $0x10000000 

It compiles in the same way as NASM:

 push 0x0000 push 0x01 push 0x0001 push 0x10 push 0x0100 push 0x1000 push 0x01000000 push 0x10000000 

Objdump:

  0: 6a 00 pushq $0x0 2: 6a 01 pushq $0x1 4: 6a 01 pushq $0x1 6: 6a 10 pushq $0x10 8: 68 00 01 00 00 pushq $0x100 d: 68 00 10 00 00 pushq $0x1000 12: 68 00 00 00 01 pushq $0x1000000 17: 68 00 00 00 10 pushq $0x10000000 

So just push in GAS is the same as push byte in NASM, but without error checking.

3) The modifier that exists in GAS, w , as in:

 pushw $0 

which compiles to:

 0: 66 6a 00 pushw $0x0 

ie, adds the 0x66 prefix to switch the 16-bit operation.

NASM equivalent:

 push word 0 

4) The difference from mov is that we cannot control arbitrary push sizes: they all fix fixed amounts on the stack.

The only parameter that we can control in the encoding of commands is whether the prefix 0x66 or not.

The rest is determined by the segment descriptor. See Intel 64 and IA-32 Software Developer's Guide - Volume 2 Instruction Set Guide - 325383-056US September 2015 .

+1
source

All Articles