News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Add number as Hex

Started by ragdog, August 07, 2011, 11:30:55 AM

Previous topic - Next topic

ragdog

Hi all

I have a problem to add a number as hex

example

i have a string "Ragdog" now get all odd signs and add by this number from counter as byte

R        g       o       g
52 01 67 03 6F 05 67

Get this odd signs code works fine but not add the number as byte

lea esi,szRagdog                   
lea edi,hTemp                                         
  xor  ecx,ecx
  .repeat
   mov  dl,byte ptr [esi+ecx]
   mov  byte ptr [edi],dl
    add  ecx,2
          inc  edi
mov [edi], ecx
inc edi
      .until   ecx >=7


qWord

mov esi,chr$("Ragdog")
mov edi,alloc(ADDR [len(esi)+1])
xor ebx,ebx
xor ecx,ecx
.while CHAR ptr [esi+ecx]
    movzx edx,CHAR ptr [esi+ecx]
    mov CHAR ptr [edi+ecx],dl
    mov edx,ecx
    and edx,1                        ; add 1 if ECX == odd (???)
    lea ebx,[ebx+edx]                ;
    lea ecx,[ecx+1]
.endw
FPU in a trice: SmplMath
It's that simple!

qWord

this one removes all odd char.:
mov esi,chr$("Ragdog")
mov edi,alloc(ADDR [len(esi)+1])
xor ebx,ebx
xor ecx,ecx
.while CHAR ptr [esi+ecx]
    .if !(ecx&1)
        movzx edx,CHAR ptr [esi+ecx]
        mov CHAR ptr [edi+ebx],dl
        lea ebx,[ebx+1]
    .endif
    lea ecx,[ecx+1]
.endw
mov CHAR ptr [edi+ebx],0
FPU in a trice: SmplMath
It's that simple!