I am prigramming in assembly Language, x86 in C++ and I need to know the getch equivalent in assembly language instead of C++ language as I dont want to use any function from the C++ programming language.
I found the code on the web but it saves the given value to a variable and created in C++. I want to use the function only to stop the program until any key is pressed. I dont have to use the entered key value in further programming.
This is an OS-specific question. For example if you're using Linux, you can issue a read
system call like this:
; Allocate some stack buffer...
sub esp, 256
mov eax, 3 ; 3 = __NR_read from <linux/asm/unistd.h>
mov ebx, 0 ; File descriptor (0 for stdin)
mov ecx, esp ; Buffer
mov edx, 256 ; Length
int 80h ; Execute syscall.
This is actually the more antiquated way to issue a syscall on x86 Linux, but it's the one I know off the top of my head. There's also sysenter
which is faster. And there is a shared library mapped into every process that abstracts the syscall interface based on what your hardware supports. (linux-gate.so
.)
As a matter of taste, I would argue against the approach of doing system calls from assembly language. It is much simpler to do it from C. Call into the assembly code (or produce inline assembly) for the stuff that absolutely needs to be in assembly language. But in general for most practical matters you will find it better not to waste your time talking to OS interfaces in assembly. (Unless it's a learning exercise, in which case I'm all for it.)
Update: You mentioned as a comment to @Anders K. that you are writing something to put on the MBR. You should have mentioned this earlier in the question. One approach is to use a BIOS call: I believe the one you want is int 16h
with ah=0
. Another would be to install a keyboard interrupt handler. Here's what the BIOS call would look like:
xor ah, ah ; ah = 0
int 16h ; call BIOS function 16h
; al now contains an ASCII code.
; ah now contians the raw scancode.
Looking at your previous questions, I'm assuming this is for your boot loader. In that case, you do not have any OS system calls available, so you'll have to rely on the BIOS. In particular, int 16h
can be used to access basic BIOS keyboard services on IBM-compatible PCs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With