dwtoa.asm
来自「工欲善其事」· 汇编 代码 · 共 90 行
ASM
90 行
; #########################################################################
; ---------------------------------------------------------------
; This procedure was originally written by Tim Roberts
;
; Part of this code has been optimised by Alexander Yackubtchik
; ---------------------------------------------------------------
.386
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive
.code
; #########################################################################
dwtoa proc dwValue:DWORD, lpBuffer:DWORD
; -------------------------------------------------------------
; convert DWORD to ascii string
; dwValue is value to be converted
; lpBuffer is the address of the receiving buffer
; EXAMPLE:
; invoke dwtoa,edx,ADDR buffer
;
; Uses: eax, ecx, edx.
; -------------------------------------------------------------
push ebx
push esi
push edi
mov eax, dwValue
mov edi, [lpBuffer]
or eax,eax
jnz sign
zero:
mov word ptr [edi],30h
jmp dw2asc
sign:
jns pos
mov byte ptr [edi],'-'
neg eax
inc edi
pos:
mov ecx,429496730
mov esi, edi
.while (eax > 0)
mov ebx,eax
mul ecx
mov eax,edx
lea edx,[edx*4+edx]
add edx,edx
sub ebx,edx
add bl,'0'
mov [edi],bl
inc edi
.endw
mov byte ptr [edi], 0 ; terminate the string
; We now have all the digits, but in reverse order.
.while (esi < edi)
dec edi
mov al, [esi]
mov ah, [edi]
mov [edi], al
mov [esi], ah
inc esi
.endw
dw2asc:
pop edi
pop esi
pop ebx
ret
dwtoa endp
; #########################################################################
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?