德尔福/ ASM code与64位兼容? [英] Delphi/ASM code incompatible with 64bit?

查看:260
本文介绍了德尔福/ ASM code与64位兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些示例源$ C ​​$ C的OpenGL,我想编写一个64位版本(使用Delphi XE2),但有一些ASM code的编译失败,而我什么都不知道ASM。这里的$ C $低于C,而且我把两个错误信息上失败......

  //从复制源的像素到dest和交换的RGB颜色值
程序CopySwapPixel(const的来源,目的地:指针);
ASM
  按EBX // [DCC错误]:欧普code和操作数E2116无效组合
  MOV BL,[EAX + 0]
  MOV BH,[EAX + 1]
  MOV [EDX + 2],BL
  MOV [EDX + 1],bh的
  MOV BL,[EAX + 2]
  MOV BH,[EAX + 3]
  MOV [EDX + 0],BL
  MOV [EDX + 3],bh的
  流行EBX // [DCC错误]:欧普code和操作数E2116无效组合
结束;
 

解决方案

这个过程交换ABGR字节顺序ARGB,反之亦然。
在这32位code应该做的所有工作:

  MOV ECX,[EAX] // ABGR从SRC
BSWAP ECX // RGBA
ROR ECX,8 // ARGB
MOV [EDX],ECX //到dest
 

正确的$ C $下X64是

  MOV ECX,[RCX] // ABGR从SRC
BSWAP ECX // RGBA
ROR ECX,8 // ARGB
MOV [RDX],ECX //到dest
 

还有另一个选择 - 让纯帕斯卡尔版本,这改变秩序的字节数组重新presentation:0123至2103(交换0级和二路字节)。

 程序SWP(const的来源,目的地:指针);
变种
  S,D:PByteArray;
开始
  S:= PByteArray(来源);
  D:= PByteArray(目标);
  D [0]:= S [2];
  D [1]:= S [1];
  D [2]:= S [0];
  D [3]:= S [3];
结束;
 

I have some sample source code for OpenGL, I wanted to compile a 64bit version (using Delphi XE2) but there's some ASM code which fails to compile, and I know nothing about ASM. Here's the code below, and I put the two error messages on the lines which fail...

// Copy a pixel from source to dest and Swap the RGB color values
procedure CopySwapPixel(const Source, Destination: Pointer);
asm
  push ebx //[DCC Error]: E2116 Invalid combination of opcode and operands
  mov bl,[eax+0]
  mov bh,[eax+1]
  mov [edx+2],bl
  mov [edx+1],bh
  mov bl,[eax+2]
  mov bh,[eax+3]
  mov [edx+0],bl
  mov [edx+3],bh
  pop ebx //[DCC Error]: E2116 Invalid combination of opcode and operands
end;

解决方案

This procedure swaps ABGR byte order to ARGB and vice versa.
In 32bit this code should do all the job:

mov ecx, [eax]  //ABGR from src
bswap ecx       //RGBA  
ror ecx, 8      //ARGB 
mov [edx], ecx  //to dest

The correct code for X64 is

mov ecx, [rcx]  //ABGR from src
bswap ecx       //RGBA  
ror ecx, 8      //ARGB 
mov [rdx], ecx  //to dest

Yet another option - make pure Pascal version, which changes order of bytes in array representation: 0123 to 2103 (swap 0th and 2th bytes).

procedure Swp(const Source, Destination: Pointer);
var
  s, d: PByteArray;
begin
  s := PByteArray(Source);
  d := PByteArray(Destination);
  d[0] := s[2];
  d[1] := s[1];
  d[2] := s[0];
  d[3] := s[3];
end;

这篇关于德尔福/ ASM code与64位兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆