Please help me i want to get keyboard input in assembly.
example: if user types "help" and enter it should show help. I want code ina ssembly language please!!??!?!?!?!
Thanks in advance.
How to get keyboard input in assmebly
Re: How to get keyboard input in assmebly
You are missing so many abstractions.
First, the input driver. What keyboard do you want to support, the good old PS/2 keyboard or USB? For the latter, you need USB support. And good luck with that.
For the former, you need to program the PS/2 controller. It will give you an interrupt once a key is pressed. Then you read out the code from the keyboard controller and save that in a buffer somewhere. How that is read out is up to your system design.
Then, the terminal driver. If the "echo" option is set, you should read the input and then write it out back to the terminal again, so that the user can see what they have typed,
Then the output driver, which needs to keep track of cursor position and maybe render the characters.
And finally, the application that actually consumes the input and does something with it.
First, the input driver. What keyboard do you want to support, the good old PS/2 keyboard or USB? For the latter, you need USB support. And good luck with that.
For the former, you need to program the PS/2 controller. It will give you an interrupt once a key is pressed. Then you read out the code from the keyboard controller and save that in a buffer somewhere. How that is read out is up to your system design.
Then, the terminal driver. If the "echo" option is set, you should read the input and then write it out back to the terminal again, so that the user can see what they have typed,
Then the output driver, which needs to keep track of cursor position and maybe render the characters.
And finally, the application that actually consumes the input and does something with it.
Carpe diem!
Re: How to get keyboard input in assmebly
You do it the same way in assembler as you would in C. It's just more difficult because higher-level languages make things easier.
No insult intended but, from your posts so far, you just aren't ready for OS programming. Asking others to do the programming for you isn't going to help.
No insult intended but, from your posts so far, you just aren't ready for OS programming. Asking others to do the programming for you isn't going to help.
- Schol-R-LEA
- Member

- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: How to get keyboard input in assmebly
@motosftos: Have you read the sticky post Links and advice for new members yet? It gives a fair amount of advice on OS Dev, and links to several relevant pages in the wiki - pages which, based on this post, you don't seem to have read yet.
The pages How To Ask Questions and Beginner Mistakes seem particularly relevant, as does the developer archetype/anti-pattern page Duct von Tape.
To sum up, we are ready to help you, but you need to be ready to receive that help first. Asking for other people to write your code for you definitely doesn't count. What does count? Having enough experience and understanding, and the drive to gain more, before you even consider a project of this scale. I won't say you'll never be able to write an operating system, but it doesn't sound like you are ready now.
The pages How To Ask Questions and Beginner Mistakes seem particularly relevant, as does the developer archetype/anti-pattern page Duct von Tape.
To sum up, we are ready to help you, but you need to be ready to receive that help first. Asking for other people to write your code for you definitely doesn't count. What does count? Having enough experience and understanding, and the drive to gain more, before you even consider a project of this scale. I won't say you'll never be able to write an operating system, but it doesn't sound like you are ready now.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Re: How to get keyboard input in assmebly
Figured the code:
Thanks for all of your help.
Thank you WikiOSdev Forum.
Code: Select all
get_string:
xor cl, cl
.loop:
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 cl, 0x3F ; 63 chars inputted?
je .loop ; yes, only let in backspace and enter
mov ah, 0x0E
int 0x10 ; print out character
stosb ; put character in buffer
inc cl
jmp .loop
.backspace:
cmp cl, 0 ; beginning of string?
je .loop ; 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 10h ; backspace on the screen
mov al, ' '
int 10h ; blank character out
mov al, 0x08
int 10h ; backspace again
jmp .loop ; go to the main loop
.done:
mov al, 0 ; null terminator
stosb
mov ah, 0x0E
mov al, 0x0D
int 0x10
mov al, 0x0A
int 0x10 ; newline
retThanks for all of your help.
Thank you WikiOSdev Forum.
Re: How to get keyboard input in assmebly
You've figured out how to get keyboard input in real mode.