Explain your answers clearly.
Have fun.
There's a PDP8/E instruction I forgot to tell you about. It's an op-code 7 instruction called BSW (for "byte swap"), and it swaps the upper 6 bits of the AC with the lower 6 bits. Its machine code is 7002.
*0000
A, 0000
B, 0000
*0200
START, CLA IAC BSW
CMA IAC
DCA A
C, DCA B
ISZ C
ISZ A
JMP C
...
Execution times in micro-seconds for PDP8/E instructions
--------------------------------------------------------
Addressing mode
------------------------------------------
Instruction Indirect with
Type Direct Indirect auto-increment
--------------------------------------------------------
AND 2.6 3.8 4.0
TAD 2.6 3.8 4.0
ISZ 2.6 3.8 4.0
DCA 2.6 3.8 4.0
JMS 2.6 3.8 4.0
JMP 1.2 2.4 2.6
Opcode 7 1.2 (addressing mode irrelevant)
--------------------------------------------------------
/ CALL -- calls a function.
/
/ Pre-conditions: The address of the function to be called
/ is in the page-0 location ADDR, and the parameter of
/ the function is in the AC.
/
/ Post-conditions: The return address to the caller and the
/ parameter have been pushed (in that order) onto the
/ system stack. Control has been transferred to the
/ function being called.
CALL, 0000
DCA CALLTMP
TAD CALL
JMS PUSH
TAD CALLTMP
JMS PUSH
JMP I ADDR
CALLTMP, 0000
/ RETURN -- returns from a function
/
/ Pre-conditions: the return value of the function is in the AC.
/
/ Post-conditions: the stack frame has been popped, the return
/ value is in the AC, and control has been returned to the
/ original routine that called CALL (via the return address
/ that was in the stack frame).
RETURN, DCA RETTMP
JMS POP
JMS POP
DCA ADDR
TAD RETTMP
JMP I ADDR
RETTMP, 0000
How would you modify our function-calling mechanism to allow for
a variable number of parameters? How would the stack frame be
structured? Show new versions of CALL and RETURN including
pre- and post-conditions that implement your extended
function-calling mechanism.