pure pascal

C and PASCAL (or any other high-level languages) in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2058
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

pure pascal

Postby charles » Wed Feb 02, 2011 10:11 pm

any one still using this wonderfull program?

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2058
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: pure pascal

Postby charles » Thu Feb 03, 2011 8:29 pm

i'm asking because with the pascal package is alot of asm code and instructions

it apears users can use asm with the pure pascal
but !!!!!

one:
the instructions are
in german

and

two:
there is no examples that actually show direct use of asm
under pure pascal

and
lastily:

i can use just like any other basic where i use binary but this might be avoidable if i knew how pure pascal intended us to use it

there is also a ttp to disasemble the units
into asm .s code
and i'm also wondering if it can be recompilied back into a unit
or if the user must rebuild a unit file from within pascal???

any one

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!

PeyloW
Atarian
Atarian
Posts: 2
Joined: Mon Apr 11, 2011 8:34 pm

Re: pure pascal

Postby PeyloW » Mon Apr 11, 2011 9:12 pm

The examples are quite bad. I do still use it from time to time though.

I do my assembler code in Devpac 3.1, and link it with my Pascal code. This requires some understanding of the internals of both generating linkable object files with Devpac, and the calling conventions used by Pure Pascal.

First Devpac:
You need to assemble you code as DRI oject files. Just add "OPT DRI" at the top of you file.
You need to export your symbols that should be visible foe the Pascal world. Use "XDEF <symbolname>", where symbol name is the label tot he start of your function.

Then from Pascal:
Link the object file with "{$L YOURFILE.O}".
Forward declare the procedure/function using the exact name that you previusly exported.

Calling conventions are quite simple, if you use FEW arguments. Arguments are put on the stack from left to right. Intergral types (integers, bools, etc) that fit in 32bit are but in registers d0-d2, and pointer are put into a0-a1. If you really need floating point then use the extended type, as they will be put in fp0-fp2 (all other floatig point types are put on the stack). Results are put in d0, or a0 as is proper fro the return type.

So lets look at a simple example that adds a integer to a integer by reference, and return the result.:
function AddInts(a: Integer; b:^Integer): Integer; forward;

You would do the assembly implementation like this:
OPT DRI
XDEF AddInts
AddInts:
add.w (a0), d0
rts

A slighlty more complex example:
function Average(nums: ^integer, count: integer):integer; forward;

Assembly implementation:
OPT DRI
XDEF Average
Average:
clr.l #0, d1
.loop:
move.w (a0)+, a1
add.l a1, d1
dbra.s d0, .loop
move.l d1, d0
rts

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2058
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: pure pascal

Postby charles » Thu Apr 14, 2011 10:24 pm

peylo , u came to answer this at a great time , i was beginning to think it was never used by anybody ..
now i will try your example and implement this structure as so , for now on ...i know i benifited from your contribution and other will too , wheter they show it or not .

thanks lets keep in touch

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2058
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: pure pascal

Postby charles » Fri Apr 22, 2011 5:22 pm

so all seems good , here is my first trial to check the success ,benchmark...

thanks

it was the first 2 lines in the asm code i was unaware how to use

opt dri

and

xdef SYMBOLNAME

here is how i made out

Code: Select all

uses tos,system;
{$X+}

TYPE
as=^integer;

VAR
hz200 :longint absolute $4ba;
aa:integer;
tim:longint;
oldSuperStack : LongInt;
xx:integer;


function AddInts(a:Integer; b:as): Integer; external;
{$L E:\ASS.O}

function addin(a:integer; b:as):integer;
begin
addin:=a+b^;
end;

begin

aa:=32767-12;
xx:=0;


{****** brief wait/pause ***}
for xx:=0 to 32765 do;


{****** put machine in supervisor state ***}
oldSuperStack := Super( nil );


{****** bench mark the object code with linked asm ***}
hz200:=0;
xx:=0;
for xx:=0 to 4500 do begin
addints(12,addr(aa));
end;
writeln(hz200);


{****** bench mark the pure pascal internal routine ***}
hz200:=0;
xx:=0;
for xx:=0 to 4500 do begin
addin(12,addr(aa));
end;
writeln(hz200);


{****** remove machine from supervisor state ***}
Super( Pointer( oldSuperStack ));


end.



and the asm

Code: Select all


   OPT DRI
   XDEF AddInts
   AddInts:
   add.w (a0),d0
   rts





attached is the object code devpac made for the linking....

all was good except i was forced to change forward
into external

why is this/?

charles
You do not have the required permissions to view the files attached to this post.
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 2 guests