6

On an Apple 3 the following pascal function

function randu( High: integer): integer;
begin
  randu:= random mod High
end;

will be translated to

Proc    = 06
Typ     = P-Code
codeBeg = 02A6
Exitcode= 02AF
Paramet.= 0006
Data    = 0000

procedure randu( param1, param2, param3);
02A6  00            SLDC 00
02A7  00            SLDC 00
02A8  CD 16 06      CXP 16,06
02AB  DA            SLDL 03
02AC  8E            MODI
02AD  CC 01         STL 01
loc1:= (random mod loc3);
02AF  AD 01         RNP 01
02B1  00            BYT  00
end (*randu*);

How can I recognise in the p-Code, that this is an integer function and has not 3 parameter values (6 bytes = 3 words data).

2 Answers 2

6

How can I recognise in the p-Code, that this is an integer function and has not 3 parameter values (6 bytes = 3 words data).

Has not? To be honest, I'm a bit confused about what you're asking. So here are my two (no, not cents) possible interpretations of this question.

If it's about how many parameters a function has:

In p-code functions always have (at least) two (16 bit) parameters even if there is none defined in source. Any defined ones come in addition. So RANDU has one source level parameter, but three internal.

That's nicely visible with the call for the random function within your RANDU. CXP 16,6 calls entry 6 in external segment 16 (which should be random). Before doing so two constant 0 words are pushed - even though random doesn't have a parameter.

If you want to know how to determinate function parameters and return from objectcode:

There is no direct way for a program to evaluate during runtime how many parameters a function (or procedure) has. The parameter list is prepared when the activation record is setup by the calling instruction (C*P). It uses the 'Parameter Size' value stored in the attribute section of the jump table - or procedure header - to reserve that space above the Mark Pointer and copies as much bytes from the stack into this space. There is no information (in object code) hom many parameter there are and how they are structured.


For further information you may want to read the Apple Pascal Operating System Reference Manual which contains all information. In addition Randall Hyde's p-Source - a Guide to the Apple Pascal System might be helpful, as it explains it (mostly the same parts) in greater detail.

3

If you look at the return code in the function above "RNP 01" stands for "return from nonbase procedure and return 1 word as a function result. Therefore this must be an integer/scalar/boolean function. As already mentioned by @Raffzahn the compiler always assigns 2 null bytes as extra parameters for any function.

This function has 3 data words: loc1 = function result, loc2 = null bytes unused, loc3 = passed parameter.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .