-
assembly
sry, this is an assembler question but i really need a little help here.
i spent like a day on looking up that info, but no site i found gave me the information i need. most sites just say that there are different address modes, but none says how the assembler differs between those.
its really sucky that google doesnt support looking up symbols like * & $ etc...
1)
so: how does the assembler differ between immediates and addresses?
e.g. jump relative 100 and jump to absolute address 100
so i have seen things on sites like 100, *100, $100, what do these mean, and are there more of these operators?
and how can addresses be marked to be relocatable/non-relocatable?
does anyone know a good assembler forum?
2)
hm... and does anyone know a site which explains how to create a new segment?
i mean i somehow need to create a segment descriptor, this descriptor is stored in which table - (global or local descriptor table)? on the other hand i need an selector to access that segment - how is selector obtained? which instructions are involved? and how much of this can i do in which privilege level? like does windows allow an ordinary application (privilege level 3) to create new segments? well i guess yes, but new segments cannot be more privileged than the current privilege level.
uh well maybe just ignore the second part - if someone could give me a link on that id be very happy, but in the moment i need a quick answer to the first question
-
Not all assemblers use the same syntax, so you'll have to look up what your particular assembler is using. The GNU Assembler (invoked with 'as' in UNIX) uses AT&T syntax, so it works like this:
Code:
movl $200, %eax # Immediate mode - copy the value 200 to eax
movl %eax, %ebx # Register addressing mode - Copy the value in eax
# to ebx
movl 200, %eax # Direct addressing mode - Copy the value stored at
# memory address 200 to eax
movl (%eax), %ebx # - Indirect addressing mode (pointers) - Use the
# value in eax as an address, and then copy the value
# stored at that address to ebx
movl 4(%ebp), %eax # - Base pointer addressing mode - Same as indirect
# mode, only you use an offset. So this means fetch
# the value in ebp as an address, and then add the
# offset (4) to that address and copy the value at
# that address to eax.
There's also indexed addressing mode, but it involves at bit more explanation.
EDIT: fixed the layout breakage
-
thxalot, but what about this:
Code:
.data
jmp end
.text
main:
.globl main
jmp .data
end:
so in "function" main i jump to the data section and jump back to the end terminate
why does
jmp .data
compile to (gdb output, btw, is there a way to disassemble a whole program? currently i always type "disassemble main", which only shows code in main)
0x08048334 <main+0>: jmp 0x804951c <p.0+4>
what does <p.0+4> mean?
and since i am jumping to another segment (the data segment) wouldnt this require a far jmp (intersegment jump), thus a selector:offset combo?
0x804951c looks like an ordinary absolute address. or is it just that gdb resolves the addresses since text and data segments for an executable always exist on the same (virtual) addresses?
sry for asking all that stuff, but i am pretty much confused on how it works
e.g in my book it says somthing like:
Code:
if absolute jump
offset = dest // dest is the operand
if offset > segment_limit
#GP(0) // general protection exception
else
eip = offset
so am i right when:
jmp 100 means: jump to location segment base + 100? thus 100 is interpreted as relative to the start of the segment?
so actually my question reduces to how would i do:
.) jump 100 bytes forward from the CURRENT LOCATION
.) jump 100 bytes forward from the start of the SEGMENT
.) jump 100 bytes forward from the start of the VIRTUAL ADDRESS SPACE
-
a different question (because all my questions here are offtopic anway i dont start a new post for this)
1) assembly: what is the meaning of asterisk(*) e.g. jmp *100?
2) how does the assembler differ between relocatable addresses and absolute addresses?
does it even make sense having relocatable addresses?
i mean intrasegment calls/jumps are relative anyway -> thus no relocation needed
if i refer to the absolte address foo (e.g. refering to the gdi.dll) i use the absolute address which is independing on where my program exisits in memory -> thus again no relocation needed
so the only reason i can think of for having relocatable addresses is for using them as placeholders for addresses to symbols which were not known when the assembly program was compiled.
in other words: relocatable addresses are just needed for linking and filling the appropriate addresses in.
but what are the relocation entries in the exe file format for? i mean they just point to the locations in the file where the origin (address of where the exe is loaded to) needs to be added.
3) mov %eax, (100)
is 100 treated as an absolute address (thus address 100 in the virtual address space? or is it 100 bytes from the beginning of the segment which is selected by the ds register (did i understand it right, that all instructions like mov, add, sub, (thus arithmetic stuff) usually refer to the data segment for their data (unless there is an segment override prefix))?)
[edit]
oh i guess i cant simply jump to the gdi.dll - i rather need to do that via a call gate so i must do call selector : dummy offset