The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ragdog on August 07, 2011, 11:30:55 AM

Title: Add number as Hex
Post by: ragdog on August 07, 2011, 11:30:55 AM
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

Title: Re: Add number as Hex
Post by: qWord on August 07, 2011, 11:46:14 AM
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
Title: Re: Add number as Hex
Post by: qWord on August 07, 2011, 12:02:49 PM
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