Reputation: 3
The following code does assemble, build and run successfully but it doesn't do anything so I want it to output a character that's entered from the keyboard and display it to the screen. How can I do this? I've tried different lines of code and looked online but I can't find anything.
I'm still learning asm so any help or advice would be appreciated.
;NASM-IDE ASM Assistant Assembler Project File
;BITS 16 ;Set code generation to 16 bit mode
;ORG 0x0100 ;Set code start address to 0100h
SEGMENT .text ;Main code segment
PUTCH:
PUSH AX
MOV AH, 2H
INT 21H
POP AX
ret
GETCH:
PUSH BX
MOV BH, AH
MOV AH, 08H
INT 21H
MOV AH, BH
POP BX
ret
PUTLINE:
PUSH AX
PUSH BX
MOV AH, 004CH
INT 21H
POP AX
POP BX
ret
SEGMENT .data ;Initialised data segment
SEGMENT .bss ;Uninitialised data segment
Upvotes: 0
Views: 4924
Reputation: 1
mov ah,01
int 21h
;this service accepts a character, echoes it, and stores it into al
Upvotes: 0
Reputation: 1797
It looks like you only have 3 procedures: putch, getch and putline. But there is no "main" procedure. That's why you don't see any output.
If you add the following code at the beginning (before "PUTCH:"), you may get it to read a character from keyboard, then echo it to the STDOUT, and then terminates the program.
XOR AX,AX ; clear AX
call GETCH ; read a char into AL
call PUTCH ; print the char from AL
MOV AX, 4C00h
INT 21h ; exit with code 0
Upvotes: 1