My task is to read a number from a terminal (aka atoi) and then write it back to terminal (aka itoa).
To read a string I use int 21h, ah 0ah
. It seems nice when I check it in the debugger. And then my atoi and itoa also look nice except that in itoa I use int 21h, ah 02h
to display one character, but for some reason it is not displayed. So I went back to the beginning and noticed that writing int 21h, ah 02h
(print char) right after int 21h, ah 0ah
(read string) gives no result.
; STACK SEGMENT
STSEG SEGMENT PARA STACK "STACK"
DB 64 DUP (0)
STSEG ENDS
; DATA SEGMENT
DSEG SEGMENT PARA PUBLIC "DATA"
startStr db "Enter a number : $"
inputError db "Number has incorrect chars.", 10, "$"
buffError db "Number is too big", 10, "$"
bufferSize DB 16 ; 15 chars + RETURN
inputLength DB 0 ; number of read chars
buffer DB 16 DUP('?') ; actual buffer
DSEG ENDS
; CODE SEGMENT
CSEG SEGMENT PARA PUBLIC "CODE"
MAIN PROC FAR
ASSUME cs: CSEG, ds: DSEG, ss:STSEG
mov ax, DSEG
mov ds, ax
;lea dx, startStr
;call WRITING
;call READING
xor ax, ax
xor dx, dx
mov ah, 2
mov dl, 56
int 21h
;test display char before reading string - works fine
xor dx, dx
xor ax, ax
lea dx, bufferSize
mov ah, 10
int 21h
; reading string - works fine
xor ax, ax
xor dx, dx
mov ah, 2
mov dl, 56
int 21h
; trying to display char again - nothing
; call ATOI
; add ax, 15
; call ITOA
ret
MAIN ENDP
CSEG ENDS
END MAIN
Screenshoot
'8' is the char I've displayed in the beginning. '123' is a string I've entered and then hit enter.
Once the DOS buffered input function 0Ah receives the enter key, depending on how your DOS emulator works, will the cursor move to the start of the current line OR to the next line.
Since outputting that second "8" is the only thing left before your program exits, the DOS prompt could be overwriting that second "8". See the screenshot.
Try deferring terminating the program. Just wait for a key.
Also print something different from your first character.
mov dl, "*"
mov ah, 02h ; DOS.PrintChar
int 21h
mov ah, 00h ; BIOS.GetKey
int 16h
ret
MAIN ENDP
CSEG ENDS
END MAIN