views:

104

answers:

2

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"?

+4  A: 

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.

Aaron
That does indeed seems to be the correct translation. I can't say I understand the original code very well (nor do I really desire to), but I want to translate it to Intel syntax.Can you explain where the "ds:" is coming from?
Sverre Rabbelier
Okay - I added a little description of the `ds` to the answer.
Aaron
Do you happen to know how I can get as to not try to be clever like that?
Sverre Rabbelier
Sorry - nope. My guess is that an long time ago someone made a bug in the compiler and it became a defacto standard.
Aaron
+1  A: 

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]
matja
That same code generates this for me " 0: 68 d4 07 00 00 push $0x7d4" on as 2.20 passing it --32.
Sverre Rabbelier