Asm To Delphi

newyj 2001-09-18 03:17:32
加精

谁能帮我把下面的 汇编转为delphi

unit pcm;

interface
function ALowtoLinear(code:byte):word;
function LinearToALow(code:word):byte;

implementation
var
return :word;

function ALowtoLinear(code:byte):word;
begin
asm
mov al,[code]
xor al,0d5h //invert even bit
mov cl,al
and ax,0fh
shl al,1
inc al

shl cx,1 //ch=sign
shr cl,5 //cl=seg
dec cl
js @NoSeg
or al,20h
shl ax,cl
@NoSeg:
shl ax,3
shr ch,1
jnc @Positive
neg ax
@Positive:
mov [return],ax
end;
result := return;
end;

function LinearToALow(code:word):byte;
begin
asm
mov ax,[code]
cmp ax,8000h
jne @Normal
mov al,0ffh
jmp @Finally
@Normal:
xor cl,cl
mov ch,ah
and ch,80h //ch=sign
jz @Positive
neg ax
@Positive:
cmp ax,100h
jnb @Seg
shr al,4
or al,ch
jmp @Finally
@Seg:
cmp ax,4000h
jnb @NoSHL
inc cl //cl=seg
shl ax,1
jmp @Seg

@NoSHL:
and ax,3fffh
shr ax,10
sub cl,7
neg cl
shl cl,4
or al,cl
or al,ch
@Finally:
xor al,0d5h //invert even bit
mov byte ptr [return],al
end;
result := byte(return);
end;

end.
...全文
301 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
wilddragon 2001-09-22
  • 打赏
  • 举报
回复
值得注意
newyj 2001-09-22
  • 打赏
  • 举报
回复
ok;以后问题再请你帮忙
蚊子王 2001-09-21
  • 打赏
  • 举报
回复
先给你一个函数,测试测试看看有没有错(我的PASCAL很次):
function ALowtoLinear(code:byte):word;
var
sign:byte;
step:byte;
begin
code := code xor $d5;
step := code;
code := code and $0f;
code := code shl 1;
code := code + 1;

sign := step shr 7;
step := step shl 1;
step := step shr 5;
step := step - 1;
Result := code;

if step < $80 then
begin
Result := Result or $20;
Result := Result shl step;
end;

Result := Result shl 3;
if sign <> 0 then
begin
Result := Result * -1
end;

end;
newyj 2001-09-21
  • 打赏
  • 举报
回复
cui(蚊子王)再努力一下;
写成c的也可以
seeking 2001-09-21
  • 打赏
  • 举报
回复
reading
wilddragon 2001-09-21
  • 打赏
  • 举报
回复
天生我才必有用
wilddragon 2001-09-21
  • 打赏
  • 举报
回复
哈哈
蚊子王 2001-09-21
  • 打赏
  • 举报
回复
to newyj(方恨少;寻找第二把刷子的人):近来我很少来,“版务”都耽误了,是我失职;竟然没这么久没理newyj版主的问题,请包涵(以后关于DELPHI的问题还得找你啊)。
蚊子王 2001-09-21
  • 打赏
  • 举报
回复
newyj版主,我已经写好了(在楼上),请测试测试,有问题再来。
哈,我替ASM拉了一笔大买卖
蚊子王 2001-09-21
  • 打赏
  • 举报
回复
function LinearToALow(code:word):byte;
var
sign:byte;
count:byte;
begin
if code <> $8000 then
begin
count := 0;
sign := code shr 8;
sign := sign and $80;
if sign <> 0 then
begin
code := code * -1;
end;
if code < $100 then
begin
Result := code;
Result := Result shr 4;
Result := Result or sign
end
else
begin
while code < $4000 do
begin
count := count + 1;
code := code shl 1;
end;
code := code and $3fff;
code := code shr 10;
count := 7 - count;
count := count shl 4;
Result := code;
Result := Result or count;
Result := Result or sign;
end;
end
else
begin
Result := $ff;
end;
Result := Result xor $d5;
end;
newyj 2001-09-21
  • 打赏
  • 举报
回复
加分奖励
newyj 2001-09-21
  • 打赏
  • 举报
回复
本来我已经转到asm了没人回答;连加个关注的都没有;我又以回来了
蚊子王 2001-09-21
  • 打赏
  • 举报
回复
ok!
不过请把该贴转到ASM去(DELPHI人气旺旺,不必锦上贴花;ASM人气低低,须雪中送炭)。
newyj 2001-09-21
  • 打赏
  • 举报
回复
高手没问题;
第二个也一并解决如何
蚊子王 2001-09-20
  • 打赏
  • 举报
回复
错了,我以为是把DELPHI转化成ASM,SORRY
蚊子王 2001-09-20
  • 打赏
  • 举报
回复
这个贴我前几天看过,但当时有事没顾上。
但我不懂DELPHI,也不知道DELPHI的名字分裂的规则(从BCB用DELPHI的VCL看来应该是一样的),我就以BC/BCB来说吧。
如果是BC或是BCB,他们的工程是直接支持ASM源文件的(我不知道DELPHI是否可以),我写个ASM源文件再加上个头文件(C/C++可以用头文件引进外部函数的,不知DELPHI的语法是如何的):

ASM源文件如下:
.386p
.model flat

public @ALowtoLinear$qqruc
public @LinearToALow$qqri

.code
@ALowtoLinear$qqruc proc
xor al,0d5h ;invert even bit
mov cl,al
and ax,0fh
shl al,1
inc al

shl cx,1 ;ch=sign
shr cl,5 ;cl=seg
dec cl
js @NoSeg
or al,20h
shl ax,cl
@NoSeg:
shl ax,3
shr ch,1
jnc @Positive
neg ax
@Positive:
ret
@ALowtoLinear$qqruc endp

@LinearToALow$qqri proc
cmp ax,8000h
jne @Normal
mov al,0ffh
jmp @Finally
@Normal:
xor cl,cl
mov ch,ah
and ch,80h ;ch=sign
jz @Positive2
neg ax
@Positive2:
cmp ax,100h
jnb @Seg
shr al,4
or al,ch
jmp @Finally
@Seg:
cmp ax,4000h
jnb @NoSHL
inc cl ;cl=seg
shl ax,1
jmp @Seg

@NoSHL:
and ax,3fffh
shr ax,10
sub cl,7
neg cl
shl cl,4
or al,cl
or al,ch
@Finally:
xor al,0d5h ;invert even bit
@LinearToALow$qqri endp

end


头文件如下:
#ifndef __ALOWTOLINEAR_H__
#define __ALOWTOLINEAR_H__
int __fastcall ALowtoLinear(unsigned char);
unsigned char __fastcall LinearToALow(int);
#endif

名字分裂规则如下:
名字分裂:C++中为了实现重载而采取的一种方法,具体规则如下:
没分裂:
FunctionName(P1,P2...) --> _FunctionName
分裂:
FunctionName(P1,P2...) --> @ClassName@FunctionName$qqr+P1 TYPE+P2 TYPE+...

1.参数为普通类型:
void v
void* pv

unsigned char uc
unsigned char* puc
unsigned char& ruc

[signed] char zc
[signed] char* pzc
[signed] char& rzc

unsigned int ui
unsigned int* pui
unsigned int& rui

[signed] int i
[signed] int* pi
[signed] int& ri

unsigned long ul
unsigned long* pul
unsigned long& rul

[signed] long l
[signed] long* pl
[signed] long& rl

unsigned short us
unsigned short* pus
unsigned short& rus

[signed] short s
[signed] short* ps
[signed] short& rs

[signed] double d
[signed] double* pd
[signed] double& rd

unsigned double ud
unsigned double* pud
unsigned double& rud

unsigned float uf
unsigned float* puf
unsigned float& ruf

[signed] float f
[signed] float* pf
[signed] float& rf

2.参数为非普通类型:
ClassName LEN(ClassName)+ClassName
ClassName* p+LEN(ClassName)+ClassName
ClassName& r+LEN(ClassName)+ClassName

*用 extern "c" 可以阻止分裂

1999.8.15
Chen Wen-yao
newyj 2001-09-19
  • 打赏
  • 举报
回复
up
pathe 2001-09-18
  • 打赏
  • 举报
回复
up
ecgnis 2001-09-18
  • 打赏
  • 举报
回复
呵呵,收藏。
hellion 2001-09-18
  • 打赏
  • 举报
回复
为什么要转过来?
加载更多回复(5)

21,459

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧