org 100h
is for a COM file. You have your code section named .txt
, that is wrong; it should be .text
; This program gets a character from the user and prints it out
org 100h ; program start point
section .data
msgIn: DB "Enter a character: $"
msgOut: DB 13, 10, "Character value: $"
section .bss
char resb 1 ; storage for input character
section .text ; <<<<<<< notice the name!!!
; print enter message
mov dx, msgIn ; offset address of message to display
mov ah, 9 ; print string function
int 21h
; get user input
mov ah, 1 ; keyboard input sub-program
int 21h ; read character into al
; store character in char variable
mov [char], al ; move entered char into char variable
; print second message
mov dx, msgOut ; offset of second message
mov ah, 9 ; print string function
int 21h ; display message
; display character
mov dl, [char] ; char to display
mov ah, 2 ; print char function
int 21h
; exit program
mov ah, 4ch ; exit to DOS function
int 21h ; see you later!
nasm -f bin DOSTest.asm -o DOSTest.com
@Tim, it does not matter where your data is, NASM will place the code section in the proper place
The bin format puts the .text section first in the file, so you can declare data or BSS items before beginning to write code if you want to and the code will still end up at the front of the file where it belongs.