|
This month I thought of doing something simple. I thought I would explain how to call an assembler routine in Pascal. All the code in listing 1 does is check to see if the user has a 386 or higher machine.
Pascal includes a very nice "directive" called 'assembler' that you add to the end of a function or procedure declaration line.function funcname: boolean; assembler;
This tells the pascal compiler that the following function is an assembler routine. When this happens, the compiler creates a few optimizer options and makes your code smaller and faster.
I won't get in to detail on how the assembler routine works, but I will show how you create the assembler function.
Create a procedure/function just like normal, except add the assembler; "directive" on to it. Then instead of using begin/end; use asm/end;.
In a function, AX is returned as the function value. In a boolean; typed function, AX is returned True (Not zero), or False (is zero). If you want to return a 32 bit value, use DX:AX.
¥
|
Listing 1
program Is386demo;
uses dos;
function is386: boolean; assembler;
asm
push bx { save reg's used (except ax) }
xor ax,ax { assume false }
mov bx,7000h { if bits 12,13,14 are still set }
push bx { after pushing/poping to/from }
popf { the flags register then we have }
pushf { a 386+ }
pop bx
and bx,7000h
cmp bx,7000h
jne @Not386
mov ax,-1
@Not386:
pop bx { restore register }
end;
begin
if not is386 then
writeln('You have a 286 or before')
else
writeln('You have a 386 or higher (32-bits)');
end.
|