I have a problem...I don' know why this code doesn't work...can anyone help me ? PLZZZ

prompt_msg1 DB 'Please input the first number: ',0
prompt_msg2 DB 'Please input the second number: ',0
sum_msg DB 'The sum is ',0


main PROC
mov ah,02
mov dl,prompt_msg1
int 21h ; request first number
mov CX,08
int 21h ; CX := first number
mov ah,02
mov dl,prompt_msg2
int 21h
mov DX,08
int 21h
mov AX,CX
add AX,DX
mov ah,02
mov dl,sum_msg
int 21h ; returns sum in AX ; display sum
mov AX,08
int 21h

main ENDP

int function 08 will read just one key from the input keyboard and wait if no key is available. So if I type "12 <Enter>" that is three keys -- '1', '2', and <Enter>. If you want the user to type more than one key then you need to write a short keyboard handling function that will put all the keys into a buffer or immediately convert it to an integer so that the result can be returned to the function that called it.

and how it's correct ?

Pseudocode for keyboard input: when loop finished cx contains the integer

clear cx integer
start of loop
get key from keyboard
is key <Enter>
if yes, exit loop
add key to cx then subtract '0' (decimal 48)
jump back to top of loop

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.