I'm using the SASM IDE by Dmitry Manushin to write a program in FASM. My code is as follows:
format ELF
section '.data' writeable
msg db 'Hello, world of Flat ASM!', 0Dh, 0Ah, 00h ; terminate with null string
buffer rb 20
inp_buf_size rw 1
pkey db 'Press any key to exit ...', 0h
formatStr db "%s", 0
section '.text' executable
public _main
extrn _printf
extrn _getch
extrn _getche
_main:
mov ebp, esp; for correct debugging
push msg ; push message onto the stack
push formatStr ; push formatter onto the stack
call _printf ; call the printf method to print the message
add esp, 8 ; clean up
xor eax, eax
; press any key to exit
mov ebp, esp; for correct debugging
push pkey ; push message onto the stack
push formatStr ; push formatter onto the stack
call _printf ; call the printf method to print the message
add esp, 8
xor eax, eax
; get input here, using getch or getche (how? What must be pushed)
; mov ebp, esp; for correct debugging
; push buffer
; call _getch
; add esp, 8
; xor eax, eax
ret
Printing the "Hello, world ..." and "Press any key ..." code works as expected. What I'm stuck on is how I go about getting the program to wait for/read a single character into the buffer using _getch
. (What, if anything, should I push onto the stack before calling _getch
?) I've tried moving values into ah
and using interrupts, but this causes the program to crash.
- OS: Windows 10 x86_64
- Assembly language: FASM (as included with SASM) --
$SOURCE$ $PROGRAM.OBJ$ -s $LSTOUTPUT$
- ** Mode:** x86
- Linker options:
$PROGRAM.OBJ$ $MACRO.OBJ$ -g -o $PROGRAM$ -m32