Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to translate "pushl 2000" from AT&T asm to Intel syntax on i386

I'm trying to translate the following from AT&T assembly to Intel assembly:

pushl 2000

Now this compiles down to:

ff 35 d0 07 00 00       pushl  0x7d0

But no matter what I try, I cannot get the same in Intel synax, I've tried:

intel asm
disassembly after compiling to at&t

push 2000
68 d0 07 00 00          push   $0x7d0

push [2000]
68 d0 07 00 00          push   $0x7d0

push dword ptr [2000]
68 d0 07 00 00          push   $0x7d0

push dword ptr 2000
68 d0 07 00 00          push   $0x7d0

So I'm out of clues, what is the equivalent of "pushl 2000"?

like image 595
Sverre Rabbelier Avatar asked Nov 10 '09 18:11

Sverre Rabbelier


2 Answers

I think the original code isn't doing what you think it's doing. According to msdev the disassembly is:

003AFCFC FF 35 D0 07 00 00 push        dword ptr ds:[7D0h] 

Which is equal to pushing:

*((DWORD*)2000)

NOT pushing the value 2000 onto the stack. However - if that's really what you want then the instruction is:

push dword ptr ds:[2000]

ds: is an indication to use the ds segment register. The segment registers are a hold-over from nasty 16-bit days. The major ones are cs - code segment, ds - data segment and ss - stack segment (and fs which is where thread locals are stored). Think of them as base offsets into memory. By default data accesses are off the ds segment.

My guess as to why push dword ptr [2000] didn't work is that the compiler realized that that was a silly thing for you to use and 'fixed it'. By forcing use of the ds prefix you indicate that you really mean to do a memory access there.

like image 196
Aaron Avatar answered Sep 21 '22 12:09

Aaron


for me, in GNU assembler 2.18, for 32-bit target

.intel_syntax
push dword [2000]

generates :

0:   ff 35 d0 07 00 00       pushl  0x7d0

and for nasm :

push dword [dword 2000]
like image 39
matja Avatar answered Sep 18 '22 12:09

matja