13.07.2015 Views

apple-pascal-1.3-manual

apple-pascal-1.3-manual

apple-pascal-1.3-manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Here is the source text for the 6502 routine used with ADDR:;Function ADDRreturns address of its own parameterRETURN .EQU !IJ ;Adrs of temp storage.FUNC ADDR, 1PLA;Save return addressSTA RETURN ; in temporary storagePLASTA RETURN+1PLA;Remove 4 bytes, leavingPLA;parameter address forPLA;function valuePLALDA RETURN+1 ;Retrieve return addressPHA;and push on stackLDA RETURNPHARTS;Return to Pascal.ENDFor instructions on how to assemble this 6502 program and link it into aPascal program, see Part II of this <strong>manual</strong>, Chapter 6. Here is how it works:1. When it calls ADDR, Pascal places the following information on theevaluation stack:2 bytes Pascal return address4 bytes 0 (space for function value)2 bytes address of variable passed for X2. The Pascal return address is at the "top" of the stack. The 6502 routinestarts by popping it off the stack and storing it in a temporary register(bytes $0 and $1 on the zero page).3. The 6502 routine then increments the stack pointer with 4 PLAinstructions, so that it now points to the address of the variable passedforX.4. Instead of popping this address, however, the 6502 routine simplyrestores the Pascal return address. The stack now looks like this:2 bytes Pascal return address2 bytes address of variable passed for XIII-264Chapter 16: Miscellaneous Information

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!