Thanks for any help.
The following code produces a negative value in FileBuffer,
when it should be a positive value.
FileBuffer db 59 DUP (0)
BufAdd dq 0
GTotalAccum dq 0
1st I clear FileBuffer to 0h
GTotalAccum is a positive value
after the below code FileBuffer is negative
It should be a positive value
mov rcx,Q[GTotalAccum] ; input
lea rbx,FileBuffer ; output
mov Q[BufAdd],rbx
; changed rdx to rcx in a 64 bit program
invoke dwtoa, rcx,[BufAdd] ; Hex DD to string
; output is in FileBuffer
dwtoa:
FRAME dwValue,lpBuffer
USES esi,edi
; -------------------------------------------------------------
; 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.
; -------------------------------------------------------------
mov eax,[dwValue]
mov edi,[lpBuffer]
test eax, eax ; is the value negative
jns >
mov B[edi], '-' ; store a minus sign
inc edi
neg eax ; and invert the value
:
mov esi, edi ; save pointer to first digit
mov ecx, 10
.convert
test eax,eax ; while there is more to convert
jz >
xor edx, edx
div ecx ; put next digit in edx
add dl, '0' ; convert to ASCII
mov [edi],dl ; store it
inc edi
jmp <.convert
:
mov B[edi], 0 ; terminate the string
.reverse ; We now have all the digits,
; but in reverse order.
cmp esi,edi
jae >
dec edi
mov al,[esi]
mov ah,[edi]
mov [edi],al
mov [esi],ah
inc esi
jmp <.reverse
:
ret
ENDF