(Resolved) Help with small real mode assembly kernel
Posted: Tue Aug 11, 2009 9:51 pm
I tried the tutorial at http://wiki.osdev.org/Real_mode_assembly_bare_bones and modified it a little. I added a function for the left and right arrow keys to move the cursor around. The problem is that I am using CL as a counter and every time I press the left and right arrows cl gets changed to some other value. I am new to assembly language so I don't know much about the registers.
Here is the code for left:
Here is for right:
Here is the whole thing:
Here is the code for left:
Code: Select all
cmp cl, 0 ; beginning of string?
je .again ; yes, ignore the key
dec di ; decrease the position in the buffer
mov ah, 0x03 ; get cursor pos
int 0x10
dec dl ; decrease the cursor pos
mov ah, 0x02 ; set cursor pos
int 0x10
jmp .again
Code: Select all
inc di ; increase the position in the buffer
mov ah, 0x03 ; get cursor pos
int 0x10
inc dl ; increase the cursor pos
mov ah, 0x02 ; set cursor pos
int 0x10
jmp .again
Code: Select all
;---------------------------------------------;
; a procedure to get user input from keyboard ;
;---------------------------------------------;
input:
xor cl, cl
.again:
mov ah, 0
int 0x16 ; wait for keypress
cmp al, 0x08 ; backspace pressed?
je .backspace ; yes, handle it
cmp al, 0x0D ; enter pressed?
je .done ; yes, we're done
cmp ah, 0x4B ; left arrow key
je .left ; move cursor left
cmp cl, 0x3F ; 63 chars inputted?
je .again ; yes, only let in backspace, enter and left
cmp ah, 0x4D ; same as above
je .right
cmp al, 0x00 ; special key?
je .again ; don't print special keys
mov ah, 0x0E
int 0x10 ; print out character
stosb ; put character in buffer
inc cl
jmp .again
.backspace:
cmp cl, 0 ; beginning of string?
je .again ; yes, ignore the key
dec di
mov byte [di], 0 ; delete character
dec cl ; decrement counter as well
mov ah, 0x0E
mov al, 0x08
int 0x10 ; backspace on the screen
mov al, ' '
int 0x10 ; blank character out
mov al, 0x08
int 0x10 ; backspace again
jmp .again ; go to the main loop
.left:
cmp cl, 0 ; beginning of string?
je .again ; yes, ignore the key
dec di ; decrease the position in the buffer
mov ah, 0x03 ; get cursor pos
int 0x10
dec dl ; decrease the cursor pos
mov ah, 0x02 ; set cursor pos
int 0x10
jmp .again
.right:
inc di ; increase the position in the buffer
mov ah, 0x03 ; get cursor pos
int 0x10
inc dl ; increase the cursor pos
mov ah, 0x02 ; set cursor pos
int 0x10
jmp .again
.done:
mov al, 0 ; null terminator
stosb
mov si, buffer
call print
call crlf
ret