几周前,我开始学习程序集,我编写了这个程序以获得用户的输入。我被挂了,因为程序在我声明msgOut之后冻结了dos框。但是,如果我把它和打印出来的代码一起注释掉,它就会工作得很好。任何帮助都将不胜感激。
; 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 .txt
; 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!发布于 2014-02-10 05:13:33
org 100h用于COM文件。您的代码部分名为.txt,这是错误的,应该是.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,无论您的数据在哪里,NASM都会将代码部分放在适当的位置
bin格式将.text部分放在文件中的第一位,因此您可以在开始编写代码之前声明数据或BSS项,如果您愿意的话,代码将仍然位于它所属的文件的前面。
发布于 2014-02-10 04:17:13
请看8.2.1 nasm文件部分。
我非常肯定,您需要将.text部分移到文件的第一位,而不是其他部分。我怀疑它试图执行您的数据段,这就是为什么额外的变量破坏了它。
https://stackoverflow.com/questions/21668922
复制相似问题