News:

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

get word

Started by 0x58, September 15, 2010, 10:51:53 PM

Previous topic - Next topic

0x58

hi guys  :)

so we have this :
MOVZX ECX,WORD PTR DS:[EBX]
MOV WORD PTR DS:[EDX],CX

this get's two bytes (word) from ebx and put them in edx well i wan't to put this in a loop and then add an x char after every word an exemple if we have this 1234567890 it should gives us 12x34x56x78x90 as a result.

i've tried this but didn't succed it gives :

MOV ECX,EAX
LEA EBX,buff1
XOR EDX,EDX
LEA EDX,buff2
XOR ECX,ECX
@@:
MOVZX ECX,WORD PTR DS:[EBX]
TEST ECX,ECX
JE @END
MOV WORD PTR DS:[EDX],CX
INC EBX
JNZ @B


so if anyone here can help it would be appreciated  :bg

clive

  LEA EBX,buff1
  LEA EDX,buff2
  JMP foo_20
foo_10:
  MOV BYTE PTR [EDX],'x'
  INC EDX ; ADVANCE DST BYTE
foo_20:
  MOVZX ECX,WORD PTR [EBX] ; TWO ZERO BYTES
  ADD EBX,2 ; ADVANCE SRC WORD
  TEST ECX,ECX
  JZ foo_30
  MOV WORD PTR [EDX],CX
  ADD EDX,2 ; ADVANCE DST WORD
  JMP foo_10
foo_30:
  XOR ECX,ECX
  MOV DWORD PTR [EDX],ECX ; TERMINATION



buff1  DB "1234567890", 0, 0 ; TWO ZERO TERMINATION

It could be a random act of randomness. Those happen a lot as well.

0x58

w0w that works :cheekygreen: i really really appreciate it mate thank's alot  :bg

0x58

hi again :) and if i wan't to delete the last char that is x?

0x58

ok i got it it's mov byte ptr ds:[sizeofinput+input-X],0 :wink thank's anyway

clive

I thought I got the semantics right, but was only coding from memory. This should work, and should catch the case where the input string is empty. It will still need to be a multiple of two in size. But it looks more like a homework question than a practical application.

  LEA EBX,buff1
  LEA EDX,buff2

  MOVZX ECX,WORD PTR [EBX] ; TWO ZERO BYTES TERMINATE
  OR ECX,ECX
  JZ foo_30 ; END

  ADD EBX,2 ; ADVANCE SRC WORD

  MOV WORD PTR [EDX],CX
  ADD EDX,2 ; ADVANCE DST WORD

foo_10:

  MOVZX ECX,WORD PTR [EBX] ; TWO ZERO BYTES TERMINATE
  OR ECX,ECX
  JZ foo_30 ; END

  ADD EBX,2 ; ADVANCE SRC WORD

  MOV BYTE PTR [EDX],'x'
  INC EDX ; ADVANCE DST BYTE

  MOV WORD PTR [EDX],CX
  ADD EDX,2 ; ADVANCE DST WORD
  JMP foo_10 ; LOOP

foo_30:

; ECX IMPLICITLY ZERO

  MOV WORD PTR [EDX],CX ; TERMINATION WITH TWO ZEROS
It could be a random act of randomness. Those happen a lot as well.