loops - printing output in assembly x86 -


i have code:

include irvine32.inc  .data     arry byte ?     prompt1 byte "enter first hex number: ",0     prompt2 byte "enter second hex number: ",0     prompt3 byte "the sum ",0     prompt4 byte "the sum out of range ",0     prompt5 byte "convert again? [y/n]: ",0     prompt6 byte "first number invalid ",0     prompt7 byte "second number invalid ",0  .code main proc     readinput:         l1:             mov edx, offset prompt1             call writestring             mov edx, 0             call readhex             call crlf             mov ecx, eax             jmp l3         l2:             mov eax, 0             mov edx, offset prompt2             call writestring             mov edx, 0             call readhex             call crlf             mov ebx, eax             mov eax, 0             jmp l4         l3:                 cmp ecx, 0ffffh                 ja l5                 jbe l2         l4:                 cmp ebx, 0ffffh                 ja  l6                 jbe addint         l5:                 mov edx, offset prompt6                 call writestring                             mov edx, 0                 call crlf                 jmp l1         l6:                 mov edx, offset prompt7                 call writestring                 mov edx, 0                 call crlf                 jmp l2      addint:         clc         mov ax, cx         add ax, bx         jc printerror         jmp convert  ; convert hex string     convert:            mov ecx, 0            mov esi, 0             mov si, 4             mov cx, 10h      convertdigit:             dec si             mov dx , 0             div cx             cmp dx, 9h             ja  convertletter             add dx, 30h             jmp printsucess      convertletter:                   add dx, 37h             jmp printsucess      printerror:             mov edx, offset prompt4             call writestring             call crlf      printsucess:             mov arry[si], dl             cmp ax , 0             jne convertdigit             mov edx, offset arry             add dx, si             call writestring             call crlf       exit main endp end main 

when tried print output this

enter first hex number: ff

enter second hex number: ff

1feer first hex number: press key continue . . .

as can see, there part of prompt1, er first hex number stuck value of sum 1fe, why did happen

the program loop edx register 3 times first time value e, second time f, , third time 1, writestring print output, seems program suppose doing, @ point edx value jump 00405911, why did happen?

thank in advance help

add null-terminator converted string. right before convertdigit loop:

mov byte ptr [arry+4],0 


way, don't need div when you're dividing power of 2 (like 16). can use faster bitwise , and shift instructions:

mov dx,ax , dx,15   ; dx = ax & 15 (== ax % 16)  shr ax,4    ; ax = ax >> 4 (== ax / 16) 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -