Can anybody give me an idea how i can convert an unsigned DWORD value to its equivalent Octal value which should be written onto a null-terminated string?
Posted on 2006-06-26 03:40:53 by XCHG
Try this (untested - not got time atm):

Tested it now, works fine

dw2oct proc pszStr:DWORD, val:DWORD

    push edi

    mov edi, pszStr
    mov eax, val

    mov ecx, 10
    mov , ch

@@:
    mov edx, eax
    and dl, 07h
    add dl, '0'

    mov , dl
   
    shr eax, 3
    sub ecx, 1
    jns @B

    pop edi

    ret
dw2oct endp


Ossa
Posted on 2006-06-26 06:00:53 by Ossa
Probably overkill  :P :P but will use only exact number of bytes in output string, instead of the output being right aligned!!!

DwordToOctal	proc	dwNumber:DWORD, pszOutString:LPTSTR
LOCAL szLocal[32]:BYTE

push esi ;for the temp string
push edi ;for the final target
push eax ;for number
push ecx ;for counting length of string
push edx

mov ecx, 1
mov eax, dwNumber
lea esi, szLocal

.while eax != 0
mov edx, eax
and edx, 07h ;111b
add dl,'0'

mov , dl

inc esi
inc ecx ;counter
shr eax,3 ;div by 8
.endw

dec esi
mov edi, pszOutString
.while ecx != 0
mov al,
mov , al

dec esi
inc edi
dec ecx
.endw
mov byte ptr ,0

pop edx
pop ecx
pop eax
pop edi
pop esi

ret

DwordToOctal endp
Posted on 2006-06-26 07:44:20 by shantanu_gadgil
Okay i got the idea and coded my own algorithm. I don not think there is any need to do any tricks with the buffer as we can use ROL to first rotate the two leftmost bits of the number and convert it to its equivalent character, and the rest of the rotates to the left can be based on 3 bits now. so 32 - 2 = 30 now the result is divisible by 3 so 10 rotates to the left, each 3 times will do the job.


Posted on 2006-06-27 02:36:23 by XCHG