[dundee] Grabbing the stack pointer...

Nicholas Walker tel0seh at googlemail.com
Mon Mar 23 11:32:16 UTC 2009


How come your compiler likes the __asm__ instead of just asm ? mine throws a
fit ^^

On Mon, Mar 23, 2009 at 10:54 AM, Andrew Clayton
<andrew at digital-domain.net>wrote:

> On Mon, 23 Mar 2009 09:25:04 +0000, Nicholas Walker wrote:
>
> > gcc on linux :)
> >
> > it seems that it prefers just "asm" over __asm__
> >
> > so, compiling:
> >
> >
> > #include<stdio.h>
> > unsigned long sp(void)
> > {
> >     asm("movl %esp, %eax");
> > }
> >
> > void main(void)
> > {
> >     printf("0x%x\n", sp());
> > }
> >
> >
> >
> > returns:
> >
> >
> >
> > tel0s at bufferoverflow:~$ cd Desktop/
> > tel0s at bufferoverflow:~/Desktop$ gcc -o sp sp.c
> > sp.c: In function ‘main’:
> > sp.c:9: warning: format ‘%x’ expects type ‘unsigned int’, but
> > argument 2 has type ‘long unsigned int’
> > sp.c:8: warning: return type of ‘main’ is not ‘int’
> > tel0s at bufferoverflow:~/Desktop$
> >
> >
> > changing main to int main() kills the last error it seems:
> >
> > tel0s at bufferoverflow:~/Desktop$ gcc -o sp sp.c
> > sp.c: In function ‘main’:
> > sp.c:9: warning: format ‘%x’ expects type ‘unsigned int’, but
> > argument 2 has type ‘long unsigned int’
> > tel0s at bufferoverflow:~/Desktop$
>
> OK, so it's not a compile failure, just a warning.
>
> #include <stdio.h>
>
> unsigned int sp()
> {
>        __asm__("movl %esp, %eax");
> }
>
> int main()
> {
>        printf("0x%x\n", sp());
>
>         return 0;
> }
>
> Is the cleanest I got it.
>
> $ gcc -Wall -o sp sp.c
> sp.c: In function ‘sp’:
> sp.c:6: warning: control reaches end of non-void function
>
>
> Andrew
>
> _______________________________________________
> dundee GNU/Linux Users Group mailing list
> dundee at lists.lug.org.uk  http://dundee.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/dundee
> Chat on IRC, #tlug on dundee.lug.org.uk
>



-- 


Nick Walker
Vice President : The Linux Society
UAD Ethical Hacker
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/dundee/attachments/20090323/c86252f6/attachment-0001.htm 


More information about the dundee mailing list