assembly - Reading Hex as String -


im not in coding in assembly, need write in assembly anyways here trying do. (i'm using masm32)

.data         msg    db    31h, 00h, 32h, 00h, 33h  ;convert string "123"      .code      start:          invoke messagebox, 0, addr msg, 0, 0         call exitprocess     end start 

as can see each character or byte separated null byte, can show 1 byte, "1" instead of "123"

if can concatenate each readable byte until reaches end of string.

mov ebx, offset msg mov ecx, ebx add ebx, 2 invoke lstrcat, ebx, ecx 

maybe add loop also, don't know better way code or if have better solution can share.

in order work on string, need know length of string. done using null terminate string. functions not take string length argument, 00h, , print string it, messagebox doing, printing "1" , seeing next character 00h, stops printing.

in case, there no null terminator @ end of string, can string length @ assembly time symbol "$" current value of location counter.

msg         db    31h, 00h, 32h, 00h, 33h  ;convert string "123" msg_len     equ $ - msg 

which means, take address of $ , subtract address of msg, , replace msg_len value.

include masm32rt.inc  .data msg         db    31h, 00h, 32h, 00h, 33h ;convert string "123" msg_len     equ $ - msg  .data? msg_new     db  msg_len + 1 dup (?)  .code start:      xor     ecx, ecx                ; index source array     xor     edx, edx                ; index dest array     lea     esi, msg     lea     edi, msg_new convertit:     mov     al, byte ptr[esi + ecx] ; byte @ pointer + index     cmp     al, 0                   ; 0?     jne     @f                      ; no, add dest array     inc     ecx                     ; yes, increase source index     jmp     checkforend             ; check see if @ end  @@:     mov     byte ptr [edi + edx], al; add byte dest array     inc     ecx                     ; increase both indexes     inc     edx                     ;   checkforend:     cmp     ecx, msg_len            ; check end - if ecx == msg_len done     jne     convertit               ; if ecx != msg_len, continue loop      mov     byte ptr [edi + edx], 0 ; don't forget null terminate dest string      invoke  messagebox, hwnd_desktop, offset msg_new, null, mb_ok     invoke  exitprocess, 0 end start 

this can done less code , "converting" string "in place" beyond scope here.

@nik, of love assembly , don't use else.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -