DelphiBASM
asm
mov ax, 1
sub ax, 1 //执行后ZF = 1
end;
//ZF标志相关指令的计算结果是否为0.大都是算术指令,进行逻辑运算后算术运算.
function MulInt2(I: Integer): Integer; 参数由EAX传入
Begin
asm
add eax, eax
end;
end;
function MulInt2(I: Integer): Integer;
Begin
asm
add eax, eax
end;
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
I, J: Integer;
begin
I := StrToInt('1');
J := MulInt2(I);
self.Caption := IntToStr(j);
end;
function Func(I: Integer): Integer;
Begin
asm
mov eax, 0
mov ecx, 12 //放循环次数
@s: add eax, 13
loop @s
mov @Result, eax //存放结果
end
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(Func(13)));
end;
function CopyStr(sStr: String):String;
var
count: Integer;
dStr: String;
Begin
count := Length(sStr);
GetMem(dStr, count);
asm
mov ecx, count
cld;
//////方向位DF操作指令
//////////////////清方向位指令CLD(Clear Direction Flag):DF←0
//////////////////置方向位指令STD(Set Direction Flag):DF←1
mov ESI, sStr;
mov EDI, dStr;
rep movsw;
end;
Result := dstr;
end;
无符号数的进位和借位.
asm
mov al, 97; //CF = 0
sub al, 98 //CF = 1
sub al, al //CF = 0
end
带借位的减法 用16位寄存器表示
function Sub1(const Num1, Num2: Integer):Integer;
Begin
asm
mov ax, word ptr Num1
mov dx, word ptr Num1 + 2
sub ax, word ptr Num2
sbb dx, word ptr Num2 + 2
mov word ptr @Result, ax
mov word ptr @Result + 2, dx
end
end;
//带进位的加法
function Add1(const Num1, Num2: Integer):Integer;
Begin
asm
mov ax, word ptr Num1
mov dx, word ptr Num1 + 2
add ax, word ptr Num2
adc dx, word ptr Num2 + 2
mov word ptr @Result, ax
mov word ptr @Result + 2, dx
end
end;
带借位减SBB(Subtract with Borrow Instruction)
指令的格式:SBB Reg/Mem, Reg/Mem/Imm
受影响的标志位:AF、CF、OF、PF、SF和ZF
指令的功能是把源操作数和标志位CF的值从目的操作数中一起减去。
//有符号数的溢出