🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Dragoljub Pokraj Fri, 11 Sep 1998 00:00
PDP11, handling C routine
#3894
Author: Dragoljub Pokraj
Date: Fri, 11 Sep 1998 00:00
27 lines
653 bytes
In fact, this could be a mesaage for Henrik!
I have also an assignment on PDP11 and don't know how PDP11 handles C
subroutine
call.

In 8086 assembler, C subroutine call is implemented on the following
way:

Say, we call
program(a1,a2)  which is written in assembler and have int4 arguments a1
and a2

The stack after calling will be:


a2|a1|PCfor return|BP|local parameters of subroutine

where BP points to the start of stack block for previous level of
subroutines (i.e
for caller of subroutine). (BP is called FP-frame pointer)

I don't know if, when we call identical subroutine on PDP's, also frame
pointer is
pushed onto stack...

Thanks,

Pokie
Re: PDP11, handling C routine
#3897
Author: wilson@dbit.com
Date: Sat, 12 Sep 1998 00:00
25 lines
1365 bytes
In article <35FA0543.4F59C6B2@eecs.wsu.edu>,
Dragoljub Pokrajac  <dpokraja@eecs.wsu.edu> wrote:
>I don't know if, when we call identical subroutine on PDP's, also frame
>pointer is
>pushed onto stack...

I don't know either (presumably it depends on the details of the particular
C compiler), but there's certainly no *need* to do it.  The reason it's
necessary in 8086 code is because there are no addressing modes that allow
you to index off the SP register, so the typical HLL subroutine entry code
starts by saving BP and copying SP to it.  This has continued with 386+
32-bit code even though the 32-bit addressing modes *do* include ways to index
off of ESP, I don't know if it's force of habit for the compiler writers,
or if it's because their stack allocation code is senile and forgets just how
much space it's allocated (ESP is often restored from EBP before returning),
well that would be stupid because even Ron Cain's ultra-simplistic Small-C
compiler can do *that* correctly.

On the PDP-11 it's perfectly possible to just adjust SP as usual (K&R even
goes into this when it talks about what happens when you "goto" into a block
statement that has initialized locals) and not waste another register to
point into the stack.  In that case the rightmost arg would be at 2(SP)
on entry to the routine, and the rest would be higher up.

John Wilson
D Bit
Re: PDP11, handling C routine
#3898
Author: wilson@dbit.com
Date: Sat, 12 Sep 1998 00:00
8 lines
330 bytes
In article <35fa9214.0@news.wizvax.net>, John Wilson <wilson@dbit.com> wrote:
>In that case the rightmost arg would be at 2(SP)
>on entry to the routine, and the rest would be higher up.

Dang!  Of course I should have said LEFTmost (in Small-C it's the rightmost
but that's why there's no printf() in Small-C).

John Wilson
D Bit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads