Dealing with newline / CR in assembly BIOS calls
Question
I'm learning assembly and I'm trying to do a simple read from keyboard / print to keyboard using BIOS calls. So far I have the following:
loop:
xor ah, ah
int 0x16 ; wait for a charater
mov ah, 0x0e
int 0x10 ; write character
jmp loop
This works fine until someone presses the enter key - it seems that the CR (\r) is being processed but not the newline (\n), as the cursor moves to the start of the current line, rather than the start of the next line.
Any ideas?
Solution
Interrupt 0x16, function 0x00 returns only one ASCII character for the Enter key (CR, 0x0D) in AL, the call to interrupt 0x10, function 0x0E will then print this single ASCII character. If you want your code to spit out the LF too, you have to test for the CR and force the LF output.
loop:
xor ah, ah
int 0x16 ; wait for a charater
mov ah, 0x0e
int 0x10 ; write character
cmp al, 0x0d ; compare to CR
jne not_cr ; jump if not a CR
mov al, 0x0a ; load the LF code into al
int 0x10 ; output the LF
not_cr:
jmp loop
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow