ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
ok... now i know what these instructions do and what basic registers are being initialized to ,my question is little stupid i m not able to get the overall objective of these instructions like why we creating stack memory of 8 bytes and why we setting last 4 bits of %esp to 0 etc etc ....... it would be nice if someone would tell me the overall objective of all the instructions listed above
2)k my second problem is the commands ..... all of them end with a 'l'
ok.. i know just the arguments get reversed my problem is ...... is there
any way possible that gcc might use commands that do not end with 'l'
and if yes then under what cases
3)ok third problem i have yet to give it a try .... if i compile the program all the way through to build an executable file and then using a diassembler (i think i messed the spellings ) i get back the assembly code ,will this code match the code i got just by compiling a .c file with -s option
4) ok i m not sure of this one as i got this instruction way back and cant get it now i think it was something like
movl (%eax,3) , %ebx
if i made a mistake then correct me can anybody tell me what this does .....
i concluded that it multiplies the first 2 arguments and add the results to the 3rd but still i would prefer some input on it
1) The eight stack bytes are probably for local variable storage. Clearing the last four bits of the stack pointer is likely just for aligning on a page boundary - i.e improving performance.
2) this is nicely covered by murugesan's link
3) You should see the same ASM code (more or less... sometimes an assembler will substitue one identical command for another, but I don't know if gas does)
4) This is memory addressing. I think the example you gave translates to this in Intel syntax:
mov ebx, dword ptr [eax+3]
(more technically, [eax + 3*1], which amounts to the same thing)
which means take the value of EAX, add 3, then move the value in memory at that address into EBX. In other words, it uses the value in EAX as a pointer to memory, rather than just a value. There is a link at the bottom of the IBM page that helps explain this a little better (but not much - it mostly assumes you already understand the Intel syntax).
okkkk talk of fast reply
thanx man (CroMagnon,murugesan) you cleared most of my doubts the link is indeed helpful in what i m doin some last doubt .......
in (1) why are we subtracting zero ie the value stored in eax from esp
can this value differ
also 1 more ques some times in the assembly code a direct function call is made like in the case of using scanf routine in 'C' we get something like
pushl %eax
pushl $.LC1
call scanf
addl $16, %esp
now because of some stack operations inside this function i m losing the current stack pointer location which i need terribly i have searched thru net but not able to find the assembly code for these functions can somebody help me in giving me some link or any other resource regarding this
and finally pls suggest some good diassembler for gcc
4) This is memory addressing. I think the example you gave translates to this in Intel syntax:
mov ebx, dword ptr [eax+3]
(more technically, [eax + 3*1], which amounts to the same thing)
which means take the value of EAX, add 3, then move the value in memory at that address into EBX. In other words, it uses the value in EAX as a pointer to memory, rather than just a value. There is a link at the bottom of the IBM page that helps explain this a little better (but not much - it mostly assumes you already understand the Intel syntax).
Actually, the example is invalid. Memory adderssing works like this:
Code:
displacement(base,index,scale)
or, using Intel syntax:
Code:
[base + index*scale + displacement]
where base and index must be registers, displacement is an integer constant, and scale is one of 1, 2, 4, or 8. You can leave out unneeded parts, for example:
Code:
(,eax,4)
and the same in Intel syntax:
Code:
[eax*4]
Quote:
now because of some stack operations inside this function i m losing the current stack pointer location which i need terribly i have searched thru net but not able to find the assembly code for these functions can somebody help me in giving me some link or any other resource regarding this
This is not possible. The call instruction stores the return address in the stack, and ret gets it from there. If esp is messed up in the function, the function returns to wrong place, usually causing a segmentation fault.
Quote:
and finally pls suggest some good diassembler for gcc
okkk
now i think i agree with harmaa kettu that the (4)
instruction might be incorrect i m not able to remember it as i never got it again and i overwrited the file that had it
for function call problem i m not able to explain my point properly i think
now we are adding 16 bytes to the stack ie deallocating memory .... but we didnt allocated
16 bytes we only allocated 8 ... so i think now u should get my point thr must be some operation on stacks taking place ie the esp register inside the function so i basically need the assembly codes for these functions ....
Oops, looks like it has been too long since I worked with assembly language
You had a question earlier about subtracting 0 from ESP - I can think of two possibilities for that. One is, as you said, a value could change (possibly at runtime).
The other is to do with optimization. I don't know much about this in detail, but if you are asking the compiler to optimize for a CPU with multiple pipelines, sometimes it might add in extra instructions that don't do anything useful, but actually improve performance by separating dependent instructions, to make sure they are not pipelined in a negative way. I'm certainly no expert on this, so I don't know what the reason really is. As Harmaa said, concentrate on the ASM generated without optimization first; you'll have a better chance of spotting and understanding whether something is a low-level optimization, or a piece of template code.
Thanx CroMagnon
all i needed was to check that the instructions in (1) will not affect me ,the project is basically such that i have to take into account the instruction which were mapped from the c language ,the optimization instructions ,or the instructions which increase page access efficiency will not bother me so much now and i can simply ignore them anyway i deeply appreciate all ur guys help
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.