PDP-11 stack may grow in either direction?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












According to this answer, the stack grows downward. It's in §4.4 of the cited document:




As another example, the DEC PDP11 range has a hardware
stack which grows with decreasing store addresses.




Now, but the way this works is by the pre-decrement and post-increment addressing modes. We can just use (r6)+ for pop or -(r0) for push.



But isn't that just convention? From what I understand we could equally well reverse the direction and use (r6)+ for push or -(r0) for pop. Yet every document I see says the stack grows downward on the PDP-11. So what am I missing?










share|improve this question





















  • That is very probably a problem with the definition of "stack". Generic data structure (can grow in any direction) vs. how does the CPU implicitly uses a stack for call and return, interrupts,... (grows downwards only)
    – tofro
    1 hour ago











  • See also stackoverflow.com/questions/664744/…
    – paxdiablo
    1 hour ago














up vote
1
down vote

favorite












According to this answer, the stack grows downward. It's in §4.4 of the cited document:




As another example, the DEC PDP11 range has a hardware
stack which grows with decreasing store addresses.




Now, but the way this works is by the pre-decrement and post-increment addressing modes. We can just use (r6)+ for pop or -(r0) for push.



But isn't that just convention? From what I understand we could equally well reverse the direction and use (r6)+ for push or -(r0) for pop. Yet every document I see says the stack grows downward on the PDP-11. So what am I missing?










share|improve this question





















  • That is very probably a problem with the definition of "stack". Generic data structure (can grow in any direction) vs. how does the CPU implicitly uses a stack for call and return, interrupts,... (grows downwards only)
    – tofro
    1 hour ago











  • See also stackoverflow.com/questions/664744/…
    – paxdiablo
    1 hour ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











According to this answer, the stack grows downward. It's in §4.4 of the cited document:




As another example, the DEC PDP11 range has a hardware
stack which grows with decreasing store addresses.




Now, but the way this works is by the pre-decrement and post-increment addressing modes. We can just use (r6)+ for pop or -(r0) for push.



But isn't that just convention? From what I understand we could equally well reverse the direction and use (r6)+ for push or -(r0) for pop. Yet every document I see says the stack grows downward on the PDP-11. So what am I missing?










share|improve this question













According to this answer, the stack grows downward. It's in §4.4 of the cited document:




As another example, the DEC PDP11 range has a hardware
stack which grows with decreasing store addresses.




Now, but the way this works is by the pre-decrement and post-increment addressing modes. We can just use (r6)+ for pop or -(r0) for push.



But isn't that just convention? From what I understand we could equally well reverse the direction and use (r6)+ for push or -(r0) for pop. Yet every document I see says the stack grows downward on the PDP-11. So what am I missing?







pdp-11






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









Wilson

9,150541111




9,150541111











  • That is very probably a problem with the definition of "stack". Generic data structure (can grow in any direction) vs. how does the CPU implicitly uses a stack for call and return, interrupts,... (grows downwards only)
    – tofro
    1 hour ago











  • See also stackoverflow.com/questions/664744/…
    – paxdiablo
    1 hour ago
















  • That is very probably a problem with the definition of "stack". Generic data structure (can grow in any direction) vs. how does the CPU implicitly uses a stack for call and return, interrupts,... (grows downwards only)
    – tofro
    1 hour ago











  • See also stackoverflow.com/questions/664744/…
    – paxdiablo
    1 hour ago















That is very probably a problem with the definition of "stack". Generic data structure (can grow in any direction) vs. how does the CPU implicitly uses a stack for call and return, interrupts,... (grows downwards only)
– tofro
1 hour ago





That is very probably a problem with the definition of "stack". Generic data structure (can grow in any direction) vs. how does the CPU implicitly uses a stack for call and return, interrupts,... (grows downwards only)
– tofro
1 hour ago













See also stackoverflow.com/questions/664744/…
– paxdiablo
1 hour ago




See also stackoverflow.com/questions/664744/…
– paxdiablo
1 hour ago










1 Answer
1






active

oldest

votes

















up vote
4
down vote













It seems that JSR and RTS expected a down growing stack.
Stack addressing modes




R6, also written SP, is used as a hardware stack for traps and
interrupts. A convention enforced by the set of modes the PDP-11
provides is that a stack grows downward—toward lower addresses—as
items are pushed onto it. When a mode is applied to SP, or to any
register the programmer elects to use as a software stack, the
addressing modes have the following effects:




JSR and RTN




The JSR instruction could save any register on the stack. Programs
that did not need this feature specified PC as the register (JSR
PC,address) and the routine returned using RTS PC. If a routine were
called with, for instance, "JSR R4, address", then the old value of R4
would be on the top of the stack and the return address (just after
JSR) would be in R4. This let the routine gain access to values coded
in-line by specifying (R4)+, or to in-line pointers by specifying
@(R4)+. The autoincrementation moved past these data, to the point at
which the caller's code resumed. Such a routine would have to specify
RTS R4 to return to its caller.




So, as long as you use the stack pointed to by R6 (or SP) and anywhere in your program uses any of:



  • JSR (jump to subroutine)

  • RTS (return from subroutine)

  • MARK (support of stack clean-up at return)

  • EMT (emulator trap)

  • TRAP, BPT (breakpoint trap)

  • IOT (input/output trap)

  • RTI & RTT (return from interrupt)

you have to follow the growing down idea, since they all expect the CPU controlled stack to be growing downwards.



If you never use any commands that uses the CPU controlled R6 (SP) stack, do as your like.



You could also set up your own data stack growing upwards. I've seen things like that on some systems. Two stacks sharing the same RAM area, one growing from bottom up, the other growing from top down. If they ever overlap the same area, you will get interesting results.






share|improve this answer






















  • Good answer, the minor thing that bothers me how you distinguish between "hardware stack" and "own data stack" - These are both "hardware stacks" and I would rather use terminology like "generic data structure" vs. "CPU implicitly using this structure"
    – tofro
    1 hour ago











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "648"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fretrocomputing.stackexchange.com%2fquestions%2f8014%2fpdp-11-stack-may-grow-in-either-direction%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote













It seems that JSR and RTS expected a down growing stack.
Stack addressing modes




R6, also written SP, is used as a hardware stack for traps and
interrupts. A convention enforced by the set of modes the PDP-11
provides is that a stack grows downward—toward lower addresses—as
items are pushed onto it. When a mode is applied to SP, or to any
register the programmer elects to use as a software stack, the
addressing modes have the following effects:




JSR and RTN




The JSR instruction could save any register on the stack. Programs
that did not need this feature specified PC as the register (JSR
PC,address) and the routine returned using RTS PC. If a routine were
called with, for instance, "JSR R4, address", then the old value of R4
would be on the top of the stack and the return address (just after
JSR) would be in R4. This let the routine gain access to values coded
in-line by specifying (R4)+, or to in-line pointers by specifying
@(R4)+. The autoincrementation moved past these data, to the point at
which the caller's code resumed. Such a routine would have to specify
RTS R4 to return to its caller.




So, as long as you use the stack pointed to by R6 (or SP) and anywhere in your program uses any of:



  • JSR (jump to subroutine)

  • RTS (return from subroutine)

  • MARK (support of stack clean-up at return)

  • EMT (emulator trap)

  • TRAP, BPT (breakpoint trap)

  • IOT (input/output trap)

  • RTI & RTT (return from interrupt)

you have to follow the growing down idea, since they all expect the CPU controlled stack to be growing downwards.



If you never use any commands that uses the CPU controlled R6 (SP) stack, do as your like.



You could also set up your own data stack growing upwards. I've seen things like that on some systems. Two stacks sharing the same RAM area, one growing from bottom up, the other growing from top down. If they ever overlap the same area, you will get interesting results.






share|improve this answer






















  • Good answer, the minor thing that bothers me how you distinguish between "hardware stack" and "own data stack" - These are both "hardware stacks" and I would rather use terminology like "generic data structure" vs. "CPU implicitly using this structure"
    – tofro
    1 hour ago















up vote
4
down vote













It seems that JSR and RTS expected a down growing stack.
Stack addressing modes




R6, also written SP, is used as a hardware stack for traps and
interrupts. A convention enforced by the set of modes the PDP-11
provides is that a stack grows downward—toward lower addresses—as
items are pushed onto it. When a mode is applied to SP, or to any
register the programmer elects to use as a software stack, the
addressing modes have the following effects:




JSR and RTN




The JSR instruction could save any register on the stack. Programs
that did not need this feature specified PC as the register (JSR
PC,address) and the routine returned using RTS PC. If a routine were
called with, for instance, "JSR R4, address", then the old value of R4
would be on the top of the stack and the return address (just after
JSR) would be in R4. This let the routine gain access to values coded
in-line by specifying (R4)+, or to in-line pointers by specifying
@(R4)+. The autoincrementation moved past these data, to the point at
which the caller's code resumed. Such a routine would have to specify
RTS R4 to return to its caller.




So, as long as you use the stack pointed to by R6 (or SP) and anywhere in your program uses any of:



  • JSR (jump to subroutine)

  • RTS (return from subroutine)

  • MARK (support of stack clean-up at return)

  • EMT (emulator trap)

  • TRAP, BPT (breakpoint trap)

  • IOT (input/output trap)

  • RTI & RTT (return from interrupt)

you have to follow the growing down idea, since they all expect the CPU controlled stack to be growing downwards.



If you never use any commands that uses the CPU controlled R6 (SP) stack, do as your like.



You could also set up your own data stack growing upwards. I've seen things like that on some systems. Two stacks sharing the same RAM area, one growing from bottom up, the other growing from top down. If they ever overlap the same area, you will get interesting results.






share|improve this answer






















  • Good answer, the minor thing that bothers me how you distinguish between "hardware stack" and "own data stack" - These are both "hardware stacks" and I would rather use terminology like "generic data structure" vs. "CPU implicitly using this structure"
    – tofro
    1 hour ago













up vote
4
down vote










up vote
4
down vote









It seems that JSR and RTS expected a down growing stack.
Stack addressing modes




R6, also written SP, is used as a hardware stack for traps and
interrupts. A convention enforced by the set of modes the PDP-11
provides is that a stack grows downward—toward lower addresses—as
items are pushed onto it. When a mode is applied to SP, or to any
register the programmer elects to use as a software stack, the
addressing modes have the following effects:




JSR and RTN




The JSR instruction could save any register on the stack. Programs
that did not need this feature specified PC as the register (JSR
PC,address) and the routine returned using RTS PC. If a routine were
called with, for instance, "JSR R4, address", then the old value of R4
would be on the top of the stack and the return address (just after
JSR) would be in R4. This let the routine gain access to values coded
in-line by specifying (R4)+, or to in-line pointers by specifying
@(R4)+. The autoincrementation moved past these data, to the point at
which the caller's code resumed. Such a routine would have to specify
RTS R4 to return to its caller.




So, as long as you use the stack pointed to by R6 (or SP) and anywhere in your program uses any of:



  • JSR (jump to subroutine)

  • RTS (return from subroutine)

  • MARK (support of stack clean-up at return)

  • EMT (emulator trap)

  • TRAP, BPT (breakpoint trap)

  • IOT (input/output trap)

  • RTI & RTT (return from interrupt)

you have to follow the growing down idea, since they all expect the CPU controlled stack to be growing downwards.



If you never use any commands that uses the CPU controlled R6 (SP) stack, do as your like.



You could also set up your own data stack growing upwards. I've seen things like that on some systems. Two stacks sharing the same RAM area, one growing from bottom up, the other growing from top down. If they ever overlap the same area, you will get interesting results.






share|improve this answer














It seems that JSR and RTS expected a down growing stack.
Stack addressing modes




R6, also written SP, is used as a hardware stack for traps and
interrupts. A convention enforced by the set of modes the PDP-11
provides is that a stack grows downward—toward lower addresses—as
items are pushed onto it. When a mode is applied to SP, or to any
register the programmer elects to use as a software stack, the
addressing modes have the following effects:




JSR and RTN




The JSR instruction could save any register on the stack. Programs
that did not need this feature specified PC as the register (JSR
PC,address) and the routine returned using RTS PC. If a routine were
called with, for instance, "JSR R4, address", then the old value of R4
would be on the top of the stack and the return address (just after
JSR) would be in R4. This let the routine gain access to values coded
in-line by specifying (R4)+, or to in-line pointers by specifying
@(R4)+. The autoincrementation moved past these data, to the point at
which the caller's code resumed. Such a routine would have to specify
RTS R4 to return to its caller.




So, as long as you use the stack pointed to by R6 (or SP) and anywhere in your program uses any of:



  • JSR (jump to subroutine)

  • RTS (return from subroutine)

  • MARK (support of stack clean-up at return)

  • EMT (emulator trap)

  • TRAP, BPT (breakpoint trap)

  • IOT (input/output trap)

  • RTI & RTT (return from interrupt)

you have to follow the growing down idea, since they all expect the CPU controlled stack to be growing downwards.



If you never use any commands that uses the CPU controlled R6 (SP) stack, do as your like.



You could also set up your own data stack growing upwards. I've seen things like that on some systems. Two stacks sharing the same RAM area, one growing from bottom up, the other growing from top down. If they ever overlap the same area, you will get interesting results.







share|improve this answer














share|improve this answer



share|improve this answer








edited 37 mins ago

























answered 2 hours ago









UncleBod

40615




40615











  • Good answer, the minor thing that bothers me how you distinguish between "hardware stack" and "own data stack" - These are both "hardware stacks" and I would rather use terminology like "generic data structure" vs. "CPU implicitly using this structure"
    – tofro
    1 hour ago

















  • Good answer, the minor thing that bothers me how you distinguish between "hardware stack" and "own data stack" - These are both "hardware stacks" and I would rather use terminology like "generic data structure" vs. "CPU implicitly using this structure"
    – tofro
    1 hour ago
















Good answer, the minor thing that bothers me how you distinguish between "hardware stack" and "own data stack" - These are both "hardware stacks" and I would rather use terminology like "generic data structure" vs. "CPU implicitly using this structure"
– tofro
1 hour ago





Good answer, the minor thing that bothers me how you distinguish between "hardware stack" and "own data stack" - These are both "hardware stacks" and I would rather use terminology like "generic data structure" vs. "CPU implicitly using this structure"
– tofro
1 hour ago


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fretrocomputing.stackexchange.com%2fquestions%2f8014%2fpdp-11-stack-may-grow-in-either-direction%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

Confectionery