- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用这个组件http://sourceforge.net/projects/tponguard/现在我需要在 64 位中编译。我被困在这个程序集中了。
事情是这样的:
push esi
push edi
mov esi, eax //esi = Mem1
mov edi, edx //edi = Mem2
push ecx //save byte count
shr ecx, 2 //convert to dwords
jz @Continue
cld
@Loop1: //xor dwords at a time
mov eax, [edi]
xor [esi], eax
add esi, 4
add edi, 4
dec ecx
jnz @Loop1
@Continue: //handle remaining bytes (3 or less)
pop ecx
and ecx, 3
jz @Done
@Loop2: //xor remaining bytes
mov al, [edi]
xor [esi], al
inc esi
inc edi
dec ecx
jnz @Loop2
@Done:
pop edi
pop esi
我改成这样:
push rsi
push rdi
mov rsi, rax //esi = Mem1
mov rdi, rdx //edi = Mem2
push rcx //save byte count
shr rcx, 2 //convert to dwords
jz @Continue
cld
@Loop1: //xor dwords at a time
mov rax, [rdi]
xor [rsi], rax
add rsi, 4
add rdi, 4
dec rcx
jnz @Loop1
@Continue: //handle remaining bytes (3 or less)
pop rcx
and rcx, 3
jz @Done
@Loop2: //xor remaining bytes
mov al, [rdi]
xor [rsi], al
inc rsi
inc rdi
dec rcx
jnz @Loop2
@Done:
pop rdi
pop rsi
但现在我在 xor [rsi]、rax 中遇到访问冲突
最佳答案
您正在查看的功能是
procedure XorMem(var Mem1; const Mem2; Count : Cardinal); register;
来自ogutil
单元。
就我个人而言,我不会费心将其转换为 x64 汇编程序。为了做到这一点,您需要正确处理一些棘手的细节。对我来说,移植到 Pascal 并让编译器处理细节更有意义。最简单最幼稚的翻译如下:
procedure XorMem(var Mem1; const Mem2; Count: Cardinal);
var
p1, p2: PByte;
begin
p1 := PByte(@Mem1);
p2 := PByte(@Mem2);
while Count>0 do
begin
p1^ := p1^ xor p2^;
inc(p1);
inc(p2);
dec(Count);
end;
end;
如果这对性能至关重要,那么您需要稍微展开循环以对大操作数进行操作。比如说 x86 上的 32 位操作数和 x64 上的 64 位操作数。
在 32 位操作数上运行的版本可能如下所示:
procedure XorMem(var Mem1; const Mem2; Count: Cardinal);
var
p1, p2: PByte;
begin
p1 := PByte(@Mem1);
p2 := PByte(@Mem2);
while Count>3 do
begin
PCardinal(p1)^ := PCardinal(p1)^ xor PCardinal(p2)^;
inc(p1, 4);
inc(p2, 4);
dec(Count, 4);
end;
while Count>0 do
begin
p1^ := p1^ xor p2^;
inc(p1);
inc(p2);
dec(Count);
end;
end;
实际上,您可以轻松地编写一个根据编译目标自动使用 32 位或 64 位操作数的版本。诀窍是使用 NativeUInt
类型,即机器字大小。
procedure XorMem(var Mem1; const Mem2; Count: Cardinal);
var
p1, p2: PByte;
begin
p1 := PByte(@Mem1);
p2 := PByte(@Mem2);
while Count>SizeOf(NativeUInt)-1 do
begin
PNativeUInt(p1)^ := PNativeUInt(p1)^ xor PNativeUInt(p2)^;
inc(p1, SizeOf(NativeUInt));
inc(p2, SizeOf(NativeUInt));
dec(Count, SizeOf(NativeUInt));
end;
while Count>0 do
begin
p1^ := p1^ xor p2^;
inc(p1);
inc(p2);
dec(Count);
end;
end;
在启用优化的情况下编译时,这个最终版本非常高效。我不会超越最终的 Pascal 版本。
关于delphi - 为什么将此汇编代码移植到 x64 时会出现访问冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17023838/
我是 Mercurial 的新手,并且不知何故仍处于评估过程中,所以这四个概念对我来说有点困惑。有些被提到等同于 Git 的 Staging/Index 概念,有些甚至比 Git 的 Staging
如何将在某些网站 (www.example1.com) 上用某种语言即 (java) 制作的 session 传送到用其他语言制作的网站,即在某些其他网站上的 (php),即 (www.example
我有以下代码行我想移植到 Torch Matmul rotMat = xmat @ ymat @ zmat 我能知道这是不是正确的顺序: rotMat = torch.matmul(xmat, tor
我正在尝试移植一个内部有一个联合的 C 结构。 Winapi.Winsock2.pas 中的默认结构记录中缺少某些字段。 但这是正确的方法吗?谢谢。 typedef struct _WSACOMPLE
我想将基于 webkit 的浏览器移植到我的堆栈中。谁能介绍一下 webkit 浏览器引擎的组织结构?目前我所知道的是它具有用于呈现 html 和解析 javascript 的核心。我想了解更多,比如
我目前有一个 ActiveX 控件,它链接到许多 c/c++ dll。问题是我们现在需要此控件在 IE 以外的浏览器(最重要的是 Firefox)上运行。 在我看来,我有以下选择: 将控件编写为 fi
我正在尝试在 Objective-C 中重写 Java 库。我想将其重写为 API,以便需要实现某些方法。我已经开始尝试重写代码,但遇到了一些问题。 Objective-C 是否支持抽象类? 如果没有
我已经有一段时间没有接触 SQL 了,所以我需要重新学习一下。我的计算机上运行着一个 SQL 数据库,我的服务器是 localhost。我在 VB.Net 中制作了一个连接到该数据库的应用程序。一切都
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit th
运行命令时出现错误 [root@himanshi busybox-1.20.2]# make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi- CON
我需要将为 iPhone 编写的现有游戏移植到 Flash。 iPhone 游戏主要是用纯 C 而不是 Objective C 编写的。 我想知道是否有任何好的工具可以将 C 代码直接转换为 Acti
我将要在 Smalltalk (Pharo) 中构建一个项目。还有一个 python 库,我打算将其用于相同的目的。现在,有 3 个选项: 那些 python 库的 Smalltalk 包装器 将 p
我必须在 GPU 上移植一个广泛使用随机数的结构。一切都可以毫无问题地移植,但随机生成器函数是唯一在该类的所有函数中被广泛调用的函数。我虽然可以简单地将它重新实现为类本身的内部设备函数。下面我放了一个
我对整个移植问题有点陌生,因为 Android SDK 提供的模拟器速度很慢,所以我解决了这个问题。 我下载了 android-x86-3.2-RC2-eeepc 和 android-x86-3.2-
我们的数据库 (PostgreSQL 9.x) 中有一些 PL/pgSQL 存储过程。 这些是严格顺序的,在某些情况下,可能会非常慢。 我们正在考虑将它们移植到 PL/Java、PL/Python 或
我有一个 Android 应用程序可以处理圆顶图像。出于性能原因,我想用 C++ 编写应用程序的某些部分,然后通过 NDK 调用这些方法。我是否需要一个特定的 C++ 编译器(例如用于嵌入式系统)或者
我正在从事一个将一大堆 OS-9(微软件)代码移植到 linux 的项目。 OS-9 中的信号处理功能允许您创建自己的信号,或者至少它是如何实现的(intercept() 函数)。我对 linux 信
目前我有这个 gtk2 代码: GList *input_devices = gdk_devices_list(); while(input_devices) { GdkDevice *devic
我正在尝试移植 Aether.Physics2D从 C# 到 Xojo 的库。这本质上是 Farseer 物理引擎的调整版本。大部分已经完成,但有一部分源代码我无法解决(可能是因为 C# 不是我的主要
我们正在开发采用 RISCV 架构的多核处理器。 我们已经为单核 RISCV 处理器移植了 Linux,它正在我们自己的基于 FPGA 的主板上使用 busybox rootfs。 我现在想为多核 R
我是一名优秀的程序员,十分优秀!