StrToInt / IntToStr Asm For Delphi

 

ContractedBlock.gif ExpandedBlockStart.gif Code
function IntToStr(Value: Integer): ShortString;
// Value  = eax
// Result = edx
asm
  push ebx
  push esi
  push edi

  mov edi,edx
  
xor ecx,ecx
  mov ebx,
10
  
xor edx,edx

  cmp eax,
0 // check for negative
  setl dl
  mov esi,edx
  jnl @reads
  neg eax

  @reads:
    mov  edx,
0   // edx = eax mod 10
    
div  ebx     // eax = eax div 10
    add  edx,
48  // '0' = #48
    push edx
    inc  ecx
    cmp  eax,
0
  jne @reads

  dec esi
  jnz @positive
  push 
45 // '-' = #45
  inc ecx

  @positive:
  mov [edi],cl 
// set length byte
  inc edi

  @writes:
    pop eax
    mov [edi],al
    inc edi
    dec ecx
  jnz @writes

  pop edi
  pop esi
  pop ebx
end

 

ContractedBlock.gif ExpandedBlockStart.gif Code


function StrToInt(Value: ShortString): Integer;
// Value   = eax
// Result  = eax
asm
  push ebx
  push esi

  mov esi,eax
  
xor eax,eax
  movzx ecx,Byte([esi]) 
// read length byte
  cmp ecx,
0
  je @exit

  movzx ebx,Byte([esi
+1])
  
xor edx,edx // edx = 0
  cmp ebx,
45  // check for negative '-' = #45
  jne @loop

  dec edx 
// edx = -1
  inc esi 
// skip '-'
  dec ecx

  @loop:
    inc   esi
    movzx ebx,Byte([esi])
    imul  eax,
10
    sub   ebx,
48 // '0' = #48
    add   eax,ebx
    dec   ecx
  jnz @loop

  mov ecx,eax
  
and ecx,edx
  
shl ecx,1
  sub eax,ecx

  @exit:
  pop esi
  pop ebx
end;

转载于:https://www.cnblogs.com/bsoom/archive/2009/11/26/1611589.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值