loops - Assembly programing bug -



loops - Assembly programing bug -

i'm new @ programming assembly. i'm trying write programme converts number decimal binary. got stuck 1 programme while trying input. after output msg2 , loop, programme doesn't turn off. can input lot of numbers , programme doesn't turn off. guess problem in convertnumber: cmp si,cx (si how many numbers have input, cx- how many numbers have written), not sure that. have made error , how right it?

.model little .stack 100h .data msg0 db 'how many numbers include input number(example. 123 3 numbers)? $' msg1 db 'now input number 0 65535: $' number db 255, ?, 256 dup ('$') numberinascii db 255, ?, 256 dup ('$') enterbutton db 13,10,'$' .code start: mov ax, @data mov ds,ax mov ah,09h mov dx, offset msg0 ; first message output int 21h xor ah,ah ; function 00h of int 16h ; int 16h gets character (ascii translation in al) int 3 mov bl,al mov dl,al mov ah,02h ; function 02h - display character int 21h ; phone call dos service mov ah,09h mov dx, offset enterbutton int 21h mov ah, 09h mov dx, offset msg1 ; output sec message int 21h jmp coverthowmany ; converting number entered next: xor si,si mov si, ax ; number entered in si xor cx,cx mov cx,0 ;cx=0 enterfirstnumber: ;entering first number (example 123, first number 1) xor ah,ah int 16h ; int 16h gets 1 character int 3 mov bl,al mov dl,al mov ah,02h ; function 02h - display character int 21h ; jmp convertnumber ; converting number input: ;converting number ascii char ascii integer mov ax,bx mov dx,10 mul dx ; ax:=ax*10 mov bx,ax ; number seek convert in bx xor ah,ah int 16h ; int 16h gets character (ascii translation in al) int 3 mov bl,al mov dl,al mov ah,02h ; function 02h - display character int 21h jmp convertnumber converthowmany: sub al,30h ; convert ascii character ascii number jmp next convertnumber: sub al,30h add together bx,ax inc cx cmp cx, si jne input jmp ending ending: mov ax,04c00h int 21h end start

i see @ to the lowest degree 2 problems code:

the first when reach converthowmany assume al still contains character user typed in. not case, since both int 21h/ah=02h , int 21h/ah=09h modify al. you'll have save , restore value of al somehow (e.g. pushing , popping ax).

the sec problem how initialize si before loop. you're moving value of ax si, means both al , ah. ah not 0 @ point, because you've used int 21h/ah=09h. alter sequence xor si,si / mov si,ax mov si,ax / and si,0ffh.

loops assembly typeconverting

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -