Re: gcc compile with asm
From: cLIeNUX user (r_at_cLIeNUX.)
Date: 02/25/04
- Next message: Roger Leigh: "Re: Issues with calling an external executable from PAM"
- Previous message: Happyslayer: "Re: Kernel 2.4.24 to 2.6.3, doesn't modules_install"
- In reply to:(deleted message) Andi Kleen: "Re: gcc compile with asm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 25 Feb 2004 06:50:30 -0000
humbubba@smart.net
>Bo Sun <b0s6067@cs.tamu.edu> writes:
>>
>> unsigned long sp(void)
>> {
>> _asm_("mov1 %esp, %eax"); // return stack ptr
>> }
>
>There are so many problems in that that it would take too long
>to point them all out.
>
>The correct way to write this is:
>
>unsigned long sp(void)
>{
> unsigned long sp;
> asm("movl %%esp,%0" : "=r" (sp));
> return sp;
>}
>
>or easier completely in C
>
>unsigned long sp(void)
>{
> char dummy;
> return (unsigned long)&dummy;
>}
>
>-Andi
In other words, this is why the Bell Labs Plan 9 C compiler written by Ken
Thompson has no asm() equivalent, and why I'm writing an OS in osimplay,
which is the assembler I wrote in Bash. asm() loses. The above in osimplay
is...
= SP to A # Why are you mucking with SP?
Which will work interactively from a Bash prompt if you've sourced
osimplay into your shell. The whole deal is ...
. osimplay
= SP to A # Why are you mucking with SP?
and then check the file ./binary with your favorite binary editor.
Also see the shasm thread on slashdot. shasm is now osimplay.
Rick Hohensee
- Next message: Roger Leigh: "Re: Issues with calling an external executable from PAM"
- Previous message: Happyslayer: "Re: Kernel 2.4.24 to 2.6.3, doesn't modules_install"
- In reply to:(deleted message) Andi Kleen: "Re: gcc compile with asm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]