Assembly troubles

Programming, for all ages and all languages.
Post Reply
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Assembly troubles

Post by davidv1992 »

I am currently writing a compiler produces code somewhat like the following example (simplified for testing):

Code: Select all

.intel_syntax noprefix
.global tigermain
.section .text
tigermain:
enter 0,0

mov ebx, L0
jmp ebx
L0:

leave
ret
however, the jump doesn't work.
I assemble it with gas, and then link it to a runtime written in c which calls tigermain. when i study the code with objdump the move seams to be correct, however, when debuging with gdb the load loads junk into ebx, instead of the label's adress. can anyone explain where it is going wrong?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Assembly troubles

Post by Combuster »

It works as expected here.

Are you looking at ld's default address 0x08048xxx because you didn't set a offset for .text yourself?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Re: Assembly troubles

Post by davidv1992 »

in objdump I see the default values, it is linked to another file and glibc (called with gcc (was easier)).

What I do suspect now though is that somehow it is loading the content at the label, instead of it's adress, and im currently doing some experiments to verify.

Which leads to another question, how the h*ck do I persuade it to load the address?

It is probably also worth saying that i'm working on a 64 bit machine, and am contiually passing --32 or -m32 to gas/gcc

Update: hunch was right, both opcode and the value that gdb returns confirm this. Can anyone tell me how I should do this?
tharkun
Member
Member
Posts: 51
Joined: Sat Mar 21, 2009 1:29 pm
Location: Ireland

Re: Assembly troubles

Post by tharkun »

This is a bug with GAS's intel_syntax feature.
E.g. Using GAS, this will load the contents of [L0]

Code: Select all

mov ebx, L0
Whereas this will load the address of L0:

Code: Select all

lea ebx, [L0]
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Re: Assembly troubles

Post by davidv1992 »

thanks for the help, probably wouldn't have figured that out myself.
Post Reply