I'm trying to create a program where the user enters a digit(more than one digit) and am planning to print the ascii version afterwards. Here's my source code with comments on the INPUT area. The input is a LOOP where it keeps asking the user to enter a number until the USER hits enter then it displays the binary format.. No problems with the displaying of binary format. The code runs fine, using the formula TOTAL = TOTAL * 10 + VALUE I would be able to get all the digits which the user entered. Although When i'm about to display the binary code format, it's all ZEROOOoooooo.. THough i entered is 123 where output should be something like "0000000001111011"
mov cx, 10 ; using this as our multiplier we will be able to read decimal input from the program
xor bx, bx ; bx will hold the total value of the input, initialize it to zero
INPUT_LOOP:
mov ah, 1 ; set the input character function
int 21h ; prompt the user to enter a number from 0 - 9 assuming it is a number
cmp al, 13 ; check if the user has pressed the enter key
je INPUT_LOOP_EXIT ; get out of the loop if the user pressed the enter key
and al, 0fh ; here, we convert the input of the user(hex) to it's binary format
; using the formula TOTAL = 10 * TOTAL + VALUE, we will be able to read an unlimited any number of digit entered
; In the formula, total is the whole digit itself, 10 is CX, VALUE is the entered input of the user(al)
mov dl, al ; we temporarily move the input of the user to dl
mov ax, bx ; we move the TOTAL VALUE into ax for multiplication
imul cx ; we multiply 10 * Total value. This is the purpose we have to move BX to ax because ax will be the multiplier
add ax, dx ; Expected that after imul has been executed, the product value will automatically be stored in ax, then we add the TOTAL with the VALUE that was entered by the user
mov bx, ax ; then we move the TOTAL VALUE into BX
jmp INPUT_LOOP
INPUT_LOOP_EXIT: