Calling 64-bit assembly language functions lodged inside the Delphi source code
http://www.atelierweb.com/calling-64-bit-assembly-language-functions-lodged-inside-the-delphi-source-code/
http://www.codeproject.com/Articles/262819/Finally-Bit-Delphi-is-here-and-with-Bit-BASM
One thing you will notice immediately by looking at the code below is that 32-bit Assembly Language is totally different from 64-bit Assembly language. So, if you want to port 32-bit routines to 64-bit, forget about that and start new ones from scratch.
unit basmTestUnit; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type
TBasmTest = class(TForm)
GroupBox1: TGroupBox;
lblCaption: TLabel;
edCaption: TEdit;
lblInput: TLabel;
edInput: TEdit;
btGo: TButton; procedure btGoClick(Sender: TObject);
private public
{ Public declarations }
end; var
BasmTest: TBasmTest; implementation {$R *.dfm} var
myReturnString : string = 'I am back in Delphi!';
charCount : integer; type
bigarray = array[0..127] of char; function assemblyTestFunction(myCaption: string; myText : string): bigarray;
{$IFDEF CPUX86}
asm
// This is the 32-bit case with the default Register (Borland Fastcall) calling convention
// where the Result is an extra var parameter.
// Arguments are passed in EAX, EDX and ECX, left to right. So, the Result (i.e, the
// return value pointer) will come to the function in ECX.
push edi
push esi
push dword ptr 0
push dword ptr myCaption
push dword ptr myText
push dword ptr 0
mov edi, ecx; // Save the return pointer to EDI because we need ECX as a counter and
// EDI is the destination pointer in a rep movsw instruction
call MessageBox
mov esi, dword ptr myReturnString
mov ecx, [charCount]
rep movsw
pop esi
pop edi
ret
end;
{$ELSE}
{$IFDEF CPUX64}
// This is the 64-bit case
// General rule: Integer and pointer arguments are passed left to right in RCX, RDX, R8
// and R9. HOWEVER, when there is a large return value, this is the case, RCX contains
// a pointer to the return space when the callee is called and all Registers usage are
// pushed one to the right
//
asm
push rsi
push rdi
push rbx
push rbp // Yes, it is a kludge. No need to push rbp, it is just to align the stack.
// The alternative is 'and rsp,-16'
sub rsp, 28h xor r9, r9
mov rbx, rcx
mov rax, rdx
mov rdx, r8
mov r8, rax
xor rcx, rcx
call MessageBox mov rdi, rbx
mov rsi, qword ptr myReturnString
mov ecx, [charCount]
rep movsw
add rsp, 28h
pop rbp
pop rbx
pop rdi
pop rsi
ret
end;
{$ENDIF CPUX64}
{$ENDIF} procedure TBasmTest.btGoClick(Sender: TObject);
var
retValue : bigArray;
begin
fillchar(retValue, sizeof(bigArray),0);
charCount := length(myReturnString);
retValue := assemblyTestFunction(edCaption.Text, edInput.Text);
showMessage(retValue);
end;
Download Example:
http://www.atelierweb.com/downloads/BasmTest.zip https://www.board4allcz.eu/showthread.php?t=618277
Calling 64-bit assembly language functions lodged inside the Delphi source code的更多相关文章
- 1.2 ASSEMBLY LANGUAGE
People are much happier moving up the ladder,socially or even technically.So our profession has move ...
- An Assembly Language
BUFFER OVERFLOW 3 An Assembly Language Introduction Basic of x86 Architecture Assembly Language Comp ...
- Notes on <Assembly Language step by step>
By brant-ruan Yeah, I feel very happy When you want to give up, think why you have held on so long. ...
- PythonStudy——汇编语言 Assembly Language
汇编语言 汇编语言(assembly language)是一种用于电子计算机.微处理器.微控制器或其他可编程器件的低级语言,亦称为符号语言.在汇编语言中,用助记符(Mnemonics)代替机器指令的操 ...
- Language and Compiler Features Since Delphi 7
from: http://edn.embarcadero.com/cn/article/34324 Language and Compiler Features Since Delphi 7 In ...
- 《PC Assembly Language》读书笔记
本书下载地址:pcasm-book. 前言 8086处理器只支持实模式(real mode),不能满足安全.多任务等需求. Q:为什么实模式不安全.不支持多任务?为什么虚模式能解决这些问题? A: 以 ...
- CS萌新的汇编学习之路(其实是老师作业呵呵哒)Learning of Assembly Language
第一节课学习汇编语言,做笔记,做笔记 1.概念 首先是汇编语言这门课程的定义以及对于学习高级语言.深入理解计算机系统的作用 软硬件接口机器语言 汇编语言 高级语言 关系 机器语言和汇编语言可移植性差 ...
- 汇编语言教材assembly language
https://en.wikipedia.org/wiki/Assembly_language https://baike.baidu.com/item/%E6%B1%87%E7%BC%96%E8%A ...
- 《汇编语言程序设计》(Professional Assembly Language)学习笔记(二)
挖坑:学习笔记(一)讲述如何在 Windows Vmware 上安装 Ubuntu 20.04 实践环境 本文是基于Ubuntu 20.04平台进行实验,下文中的解决方法都基于此前提 问题记录 问题一 ...
随机推荐
- JAVA 创建TXT文件,写入文件内容,读取文件内容
[java] view plain copy package com.abin.facade.ws.mail.function; import java.io.BufferedReader; i ...
- BFG
"/"应用程序中的服务器错误. 配置错误 说明: 在处理向该请求提供服务所需的配置文件时出错.请检查下面的特定错误详细信息并适当地修改配置文件. 分析器错误消息: 提供程序集合中不 ...
- 一个简单链表的C++实现
/* LList.cpp * Author: Qiang Xiao * Time: 2015-07-12 */ #include<iostream> using namespace std ...
- Quiz 6a Question 7————An Introduction to Interactive Programming in Python
First, complete the following class definition: class BankAccount: def __init__(self, initial_bal ...
- 新建linux组、用户命令
之前在安装oracle的时候,出现了一个问题:安装Oracle,新建组.用户的时候的一个错误.看这篇博客前,先看这个链接,学习要从解决出现的问题出手. 建立用户组和用户 下面总结一下Linux建立组和 ...
- (待解决问题)nowrap在table和td都设置了宽度的时候仍然有效
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- android设置按钮按下的不同效果图
<!-- 按钮设置按下去的不同效果的方式,设置android:background属性, 下面的 button_select实际上是button_select.xml --> <Bu ...
- Subsets 【dfs】
Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must ...
- clear伪类使用
都知道float会脱离文档流 用什么办法撑开父元素呢? 手动在本区块的所有float元素之后加上一个块元素并对其添加clear:both 可以 但是这样还要再去修改html页面 而且多了一个仅仅是 ...
- Using WMIC For Gathering System Info
WMIC is a command line interface to WMI (Windows Management Instrumentation). While it has many uses ...