From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 Date: Mon, 16 Jan 2012 14:30:02 +0200 Message-ID: From: Alexander Kapshuk To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=f46d0401f777a235eb04b6a45f3d Subject: Re: [9fans] assembly syntax in plan 9 Topicbox-Message-UUID: 5d0bf404-ead7-11e9-9d60-3106f5b1d025 --f46d0401f777a235eb04b6a45f3d Content-Type: text/plain; charset=ISO-8859-1 i have a question about putting things on the stack for x86 arch under plan 9... under unix/linux, when defining a function, i would: (1). push the address the base pointer is pointing to prior to this function being called, onto the stack; e.g. pushl %ebp (2). then i would have the base pointer point to the current stack pointer; e.g. movl %esp, %ebp (3). then i would allocate space on the stack for local variables, if any; e.g. subl $n, %esp; (4). then follows the function body; to return from the function i would: (1). restore the stack pointer; e.g. movl %ebp, %esp; (2). restore the base pointer, e.g. popl %ebp; (3). then return to the calling function; i searched the 9fans archives for posts on assembly programming under plan 9; found some bits and pieces; e.g. in one of the posts it was mentioned that BP is a general purpose register, not the base pointer; and that FP is what ebp is under unix/linux; in the paper for the plan 9 assembler, it says that there are three registers available to manipulate the stack, FP, SP, and TOS; would the following comparison stand true then? plan9 unix/linux ------- ------------- FP EBP SP -4(%EBP)...-n(%EBP) /* local variables */ TOS ESP thanks; sasha kapshuk --f46d0401f777a235eb04b6a45f3d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable i have a question about putting things on the stack for x86 arch under plan= 9...

under unix/linux, when defining a function, i woul= d:
(1). push the address the base pointer is pointing to prior to= this function being called, onto the stack; e.g. pushl %ebp
(2). then i would have the base pointer point to the current stack poi= nter; e.g. movl %esp, %ebp
(3). then i would allocate space on th= e stack for local variables, if any; e.g. subl $n, %esp;
(4). the= n follows the function body;
to return from the function i would:
(1). restore the stack = pointer; e.g. movl %ebp, %esp;
(2). restore the base pointer, e.g= . popl %ebp;
(3). then return to the calling function;

i searched the 9fans archives for posts on assembly programm= ing under plan 9; found some bits and pieces; e.g. in one of the posts it w= as mentioned that BP is a general purpose register, not the base pointer; a= nd that FP is what ebp is under unix/linux;

in the paper for the plan 9 assembler, it says that the= re are three registers available to manipulate the stack, FP, SP, and TOS; = would the following comparison stand true then?
plan9 =A0 =A0unix= /linux
------- =A0 =A0 -------------
FP =A0 =A0 =A0 =A0EBP
SP =A0 =A0 =A0 =A0-4(%EBP)...-n(%EBP) /* local variables */
TOS= =A0 =A0 ESP

thanks;

sash= a kapshuk

--f46d0401f777a235eb04b6a45f3d--