Forum > General

Turbo Pascal 6.0, 80386 assembly language, Free Pascal, 64-bit CPU

(1/3) > >>

Rick314:
Help!  The attached test program compiles and runs fine using Turbo Pascal 6.0 within DOSBox on a 2012 Dell XPS 8300 Windows 7  PC with an Intel Core i7-2600 64-bit CPU.  The 80386 assembly code in the program is a small part of a much bigger program with other assembly code procedures in it.  WITHOUT CHANGING THE ASSEMBLY CODE I want to compile and run it on the same hardware using Free Pascal Compiler and not using DOSBox.  What compiler switches and (hopefully minimal) changes to the source code are required?

Other details: Expected output is included in the comments near the end of the file.  I wrote the original program I am working on in 1992 and have done very little with x86 assembly since then.  I am new to Free Pascal but have lots of experience with Turbo Pascal 6.0.  I have recently been able to compile and run over 80 old TP 6.0 programs using Free Pascal with the -Mtp (Turbo Pascal 7.0 compatibility) switch.  Now I am trying to get old assembly code to work on new hardware with a new compiler (FPC).  (The attachment should be TEST1.PAS, but this Pascal forum won't allow .PAS attachments.  Sigh.)

Leledumbo:
The problem is mostly (if not all) unrecognized opcode. Looks like you have to use db/dd/dw to generate the opcode by hand (as already been used in some places in the source) as the assembler reader doesn't know the opcode.

Rick314:

--- Quote from: Leledumbo on February 23, 2015, 06:51:51 am ---... Looks like you have to use db/dd/dw to generate the opcode by hand (as already been used in some places in the source) as the assembler reader doesn't know the opcode.
--- End quote ---
This is explained in the code as required due to Turbo Pascal 6.0 limitations (quote below).  But if Free Pascal can properly read 80286 assembler code then it should work on a 80386-compatible CPU. So my original question remains, but more specifically I want Free Pascal to understand 80286 assembly and use the backward-compatibility features of modern 64-bit CPUs to emulate it.  Here is the code quote:

"This procedure requires an 80386 processor, as it makes use of 32-bit data operations for increased speed.  The Turbo PASCAL version 6.0 built-in assembler does not support these 386-only instructions, however. This is handled by including a "DB $66" instruction prefix byte before instructions meant to use 32-bit 386-only registers."

Leledumbo:

--- Quote from: Rick314 on February 23, 2015, 07:03:33 am ---But if Free Pascal can properly read 80286 assembler code then it should work on a 80386-compatible CPU. So my original question remains, but more specifically I want Free Pascal to understand 80286 assembly and use the backward-compatibility features of modern 64-bit CPUs to emulate it.
--- End quote ---
Since FPC minimum requirement is 386, I don't think the assembler reader is implemented with 80286 opcode.

Jonas Maebe:
The problem is that your assembler code is written for 16 bit real mode, while FPC for i386 platforms targets 32 bit protected mode. This requires a completely different way to deal with pointers, and e.g. the les/lds instructions won't work at all anymore (not in the way you are using them anyway). Another issue is that since the cpu is in 32 bit mode, "db $66" followed by an instruction using 16 bit registers would result in two "db $66" prefixes (one inserted by the db, and another by the compiler to tell the cpu that it should interpret the next instruction as a 16 bit instead of as a 32 bit instruction). There are probably more problems.

You'll have to rewrite the assembler code completely, either into Pascal or into 32 bit assembler.

Navigation

[0] Message Index

[#] Next page

Go to full version