Recent

Author Topic: Free Pascal and Intel Core 64-bit assembly language  (Read 21419 times)

Rick314

  • New Member
  • *
  • Posts: 28
Free Pascal and Intel Core 64-bit assembly language
« on: March 14, 2015, 10:31:45 pm »
What do I need to do to use Intel Core 64-bit assembly language statements within a Free Pascal program? I read about assembly language in the Programmers Guide, but it only mentions 80x86.  So my answer may be "it can't be done" but I'd like to get that from someone that is sure there is no way to do it.

Specifically, I am running Free Pascal Compiler 2.6.4 (fpc-2.6.4.i386-win32.exe) under Windows 7 on my Dell XPS 8300 PC with Intel Core i7-2600 CPU.  The attached program compiles at the Command Prompt using "fpc -dASSY -Rintel div_test4.txt" and runs as expected.  The 80386 assembly language "div" instruction inside it does "uint64/uint32 = uint32 quotient and uint32 remainder" (Notation: "uint64" means unsigned integer, 64-bit.)  I want to extend the program to do "uint128/uint64 = uint64 quotient and uint64 remainder" using the DIV instruction described on PDF page 304 of the Intel Instruction Set Reference. That instruction does "Unsigned divide RDX:RAX by r/m64, with result stored in RAX (Quotient) and RDX (Remainder)".  Do I have to install fpc-2.6.4.x86_64-win64.exe (that I found under the "Win32" download directory)? How do I get the CPU into 64-bit mode? What other problems am I likely to run into?

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #1 on: March 14, 2015, 10:52:46 pm »
First, your OS must be 64-bit. Second, you will need full blown FPC 2.6.4 for 64-bit. If I remember correctly, that fpc-2.6.4.x86_64-win64.exe package contains only crosscompiler for Win64-bit target.

Rick314

  • New Member
  • *
  • Posts: 28
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #2 on: March 15, 2015, 12:46:59 am »
First, your OS must be 64-bit. Second, you will need full blown FPC 2.6.4 for 64-bit. If I remember correctly, that fpc-2.6.4.x86_64-win64.exe package contains only crosscompiler for Win64-bit target.

Thank you for your reply.  My OS is 64-bit (Windows 7 Control Panel, System, System Type = "64-bit Operating System"). What is "full blown FPC 2.6.4 for 64-bit" and what do I need to do to install it? What does it have that is more than "only crosscompiler for Win64-bit target" that I need? Most important, if I follow your instructions, are you sure that then I will then be able to do what I need?

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #3 on: March 15, 2015, 01:19:56 am »
Like I said, full blown FPC 64-bit environment only includes 64-bit executables, namely the compiler, the text mode IDE, the GNU GDB debugger for Win64, all RTL and package units compiled for 64-bit environment  and few utilities (some are 32-bit, thought).

You need to check yourself if that cross-compiler package suits for you. I myself build my own FPC environments, currently 2.6.4 (release) , 2.6.5 (fixes) and 3.1.1 (development version from SVN trunk).

Rick314

  • New Member
  • *
  • Posts: 28
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #4 on: March 15, 2015, 02:15:39 am »
Thanks Cyrax -- I understand what you mean now. Can anyone else answer the questions posed in the original post? I hope to get a definitive "it isn't possible" or "it is possible and here's what you need to do".

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #5 on: March 15, 2015, 06:22:00 am »
Thanks Cyrax -- I understand what you mean now. Can anyone else answer the questions posed in the original post? I hope to get a definitive "it isn't possible" or "it is possible and here's what you need to do".
Did you mean:
Code: [Select]
{$asmmode intel}

var
  HiDividend,LoDividend,Divisor,Quotient,Remainder: Int64;
begin
  HiDividend := $0000000000000001;
  LoDividend := $1100000000000010;
  Divisor := $10;
  asm
    MOV RDX,HiDividend
    MOV RAX,LoDividend
    DIV Divisor
    MOV Quotient,RDX
    MOV Remainder,RAX
  end ['RAX','RDX'];
  WriteLn(HexStr(Quotient,16));
  WriteLn(HexStr(Remainder,16));
end.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #6 on: March 15, 2015, 11:04:52 am »
First, your OS must be 64-bit. Second, you will need full blown FPC 2.6.4 for 64-bit.
That is incorrect. A cross-compiler has exactly the same capabilities as a so-called native compiler for the same target. We would not distribute cross-compilers as official releases if they wouldn't be fully functional.

photor

  • New Member
  • *
  • Posts: 49
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #7 on: March 15, 2015, 01:14:37 pm »
I learned  :)

Thanks Cyrax -- I understand what you mean now. Can anyone else answer the questions posed in the original post? I hope to get a definitive "it isn't possible" or "it is possible and here's what you need to do".
Did you mean:
Code: [Select]
{$asmmode intel}

var
  HiDividend,LoDividend,Divisor,Quotient,Remainder: Int64;
begin
  HiDividend := $0000000000000001;
  LoDividend := $1100000000000010;
  Divisor := $10;
  asm
    MOV RDX,HiDividend
    MOV RAX,LoDividend
    DIV Divisor
    MOV Quotient,RDX
    MOV Remainder,RAX
  end ['RAX','RDX'];
  WriteLn(HexStr(Quotient,16));
  WriteLn(HexStr(Remainder,16));
end.

Rick314

  • New Member
  • *
  • Posts: 28
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #8 on: March 15, 2015, 05:23:29 pm »
Did you mean: ...
Thanks Leledumbo, but I want to know the environment in which your code is compiling. When I try to compile the code you provided in the environment I described in the original post, I get "unknown identifier RDX" and similar errors. Is installing fpc-2.6.4.x86_64-win64.exe all you think I need to do?

Laksen

  • Hero Member
  • *****
  • Posts: 724
    • J-Software
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #9 on: March 15, 2015, 05:25:03 pm »
Yes. Install that and set the project os target to Win64, and cpu target to x86_64

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #10 on: March 15, 2015, 06:34:17 pm »
First, your OS must be 64-bit. Second, you will need full blown FPC 2.6.4 for 64-bit.
That is incorrect. A cross-compiler has exactly the same capabilities as a so-called native compiler for the same target. We would not distribute cross-compilers as official releases if they wouldn't be fully functional.

Ah, thanks for clarifying on that matter.

Did you mean: ...
Thanks Leledumbo, but I want to know the environment in which your code is compiling. When I try to compile the code you provided in the environment I described in the original post, I get "unknown identifier RDX" and similar errors. Is installing fpc-2.6.4.x86_64-win64.exe all you think I need to do?


I might be wrong, but you can't debug resulting program with 32-bit GDB? I think Lazarus don't have ability detect bitness of the program and change debugger on the fly. There may be way by using IDE Macros if you have recent version of Lazarus (1.4 RC2 or trunk) in use.

Rick314

  • New Member
  • *
  • Posts: 28
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #11 on: March 16, 2015, 02:02:19 am »
Yes. Install that and set the project os target to Win64, and cpu target to x86_64
How do I "set the project os target to Win64, and cpu target to x86_64"?

Details: After already having fpc-2.6.4.i386-win32.exe installed, I installed fpc-2.6.4.x86_64-win64.exe. I am using "fpc" at the Windows 7 Command Prompt to compile single-file Pascal programs. I am looking at fpc command-line options and don't see anything like that. I am new to both Free Pascal and Win64 development, and suspect I am missing something obvious to those with more experience.

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #12 on: March 16, 2015, 02:19:50 am »
I highly recommend to use Lazarus for this and future projects.

Rick314

  • New Member
  • *
  • Posts: 28
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #13 on: March 16, 2015, 02:39:21 am »
I highly recommend to use Lazarus for this and future projects.
Thanks Cyrax. I am translating and updating many old early-1990s Turbo Pascal 6.0 programs to Free Pascal. If possible, I want to stay at the Command Prompt or use the Free Pascal IDE that is very much like the Turbo Pascal 6.0 interface I am used to. If Lazarus is required to do what I described in the original post, please let me know. But I hope it can be done at the Windows Command Prompt or inside the Free Pascal IDE.
« Last Edit: March 16, 2015, 02:41:37 am by Rick314 »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Free Pascal and Intel Core 64-bit assembly language
« Reply #14 on: March 16, 2015, 04:42:41 am »
Did you mean: ...
Thanks Leledumbo, but I want to know the environment in which your code is compiling. When I try to compile the code you provided in the environment I described in the original post, I get "unknown identifier RDX" and similar errors. Is installing fpc-2.6.4.x86_64-win64.exe all you think I need to do?
x86_64-linux, should be no different on x86_64-win64. If you use fpc command line, pass -Px86_64 -Twin64 (probably this one is not needed since the cross compiler already targets win64 by default) before the filename. In Lazarus, you have in the project options dialog.

 

TinyPortal © 2005-2018