Assembly 需要从MASM转换为NASM
附件: 文件dosbox_003.png 5.722 KB 编写一个NASM,它将: 在一行上显示您的姓名。使用int 21h,函数9。回车符和换行符分别为0Dh和0Ah。 在下一行,再次使用int 21h,function9显示提示,并使用int 21h,fcn 1从键盘读取三个字符。将字符存储在适当标记的字节变量中。 打印三个字符,每行一个,具体取决于实现方式,可选择使用int 21h、函数9或函数2。 使用NASM组装程序并使用DOSBox执行 使用命令提示符组装 给定此代码,错误以粗体显示,线条突出显示 我有这些错误Assembly 需要从MASM转换为NASM,assembly,x86,dos,x86-16,Assembly,X86,Dos,X86 16,附件: 文件dosbox_003.png 5.722 KB 编写一个NASM,它将: 在一行上显示您的姓名。使用int 21h,函数9。回车符和换行符分别为0Dh和0Ah。 在下一行,再次使用int 21h,function9显示提示,并使用int 21h,fcn 1从键盘读取三个字符。将字符存储在适当标记的字节变量中。 打印三个字符,每行一个,具体取决于实现方式,可选择使用int 21h、函数9或函数2。 使用NASM组装程序并使用DOSBox执行 使用命令提示符组装 给定此代码,错误以粗体显
C:\NASM>nasm bal-lab2.asm -o bal-lab2.com
bal-lab2.asm:5: error: attempt to define a local label before any non-local
labels
bal-lab2.asm:5: error: parser: instruction expected
bal-lab2.asm:6: error: attempt to define a local label before any non-local
labels
bal-lab2.asm:6: error: parser: instruction expected
bal-lab2.asm:7: warning: label alone on a line without a colon might be in
error [-w+orphan-labels]
bal-lab2.asm:7: error: attempt to define a local label before any non-local
labels
bal-lab2.asm:17: warning: label alone on a line without a colon might be in
error [-w+orphan-labels]
bal-lab2.asm:18: error: parser: instruction expected
bal-lab2.asm:127: error: symbol `main' redefined
bal-lab2.asm:127: error: parser: instruction expected
bal-lab2.asm:128: error: parser: instruction expected
使用此代码
;ff
;ff
;ff
.model small line ***LINE 5***
.stack 100h ***LINE 6***
.data ***LINE 7***
nameString db 'my name here $' ;replace by your name
prompt1 db 'Enter first character : $' ;ask for character
prompt2 db 'Enter second character : $' ;ask for character
prompt3 db 'Enter third character : $' ;ask for character
character1 DB ? ;memory to store character
character2 DB ? ;memory to store character
character3 DB ? ;memory to store character
.code ***LINE 17**
main proc ***LINE 18***
mov ax,@data ;move data address to ax
mov ds,ax ;move ax to data segment
lea dx , nameString ;move content to dx
mov ah,9 ;ask to print array of string
int 21h
mov dx,10 ;print \n
mov ah,2
int 21h
mov dx,13 ;cursor at first position
mov ah,2
int 21h
lea dx , prompt1 ;if use lea no need to use offset
mov ah,9 ;print prompt
int 21h
;ask for character input
mov ah,1
int 21h
mov character1,al ; move to labled memory
mov dx,10 ;print \n
mov ah,2
int 21h
mov dx,13 ;cursor at first position
mov ah,2
int 21h
lea dx , prompt2 ;if use lea no need to use offset
mov ah,9 ;print prompt
int 21h
;ask for character input
mov ah,1
int 21h
mov character2,al ; move to labled memory
mov dx,10 ;print \n
mov ah,2
int 21h
mov dx,13 ;cursor at first position
mov ah,2
int 21h
lea dx , prompt3 ;if use lea no need to use offset
mov ah,9 ;print prompt
int 21h
;ask for character input
mov ah,1
int 21h
mov character3,al ; move to labled memory
mov dx,10 ;print \n
mov ah,2
int 21h
mov dx,13 ;cursor at first position
mov ah,2
int 21h
mov dl,character1 ;move character value to dl for print
mov ah,2
int 21h
mov dx,10 ;print \n
mov ah,2
int 21h
mov dx,13 ;cursor at first position
mov ah,2
int 21h
mov dl,character2 ;move character value to dl for print
mov ah,2
int 21h
mov dx,10 ;print \n
mov ah,2
int 21h
mov dx,13 ;cursor at first position
mov ah,2
int 21h
mov dl,character3 ;move character value to dl for print
mov ah,2
int 21h
mov ah,4ch
int 21h
main endp ***LINE 127***
end main ***LINE 128***
错误会高亮显示,线条也会高亮显示
谢谢你的帮助,我对汇编语言很陌生
删除程序的前7行并替换为org 0x100
将.data中的所有内容移动到文件末尾。COM文件中不需要节。
是否更改数据库的所有事件?至分贝0
拆除线路17至22 mov ax、@data和mov ds,不需要ax
你去过的每一个地方都换成了电影
是否更改角色的所有实例?到[字符?]
进行这些更改,您的程序就会工作,我使用DOSBox 0.74对其进行了测试,其输出如下所示
这是你的程序在修改为NASM和一些个人调整,如缩短标签
org 256
mov dx, Nme ;move content to dx
mov ah, 9 ;ask to print array of string
int 21h
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah, 2
int 21h
mov dx, prompt1 ;if use lea no need to use offset
mov ah, 9 ;print prompt
int 21h
mov ah, 1 ;ask for chr input
int 21h
mov [chr1] ,al ; move to labled memory
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah, 2
int 21h
mov dx , prompt2 ;if use lea no need to use offset
mov ah, 9 ;print prompt
int 21h
mov ah,1 ;ask for chr input
int 21h
mov [chr2], al ; move to labled memory
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah,2
int 21h
mov dx, prompt3 ;if use lea no need to use offset
mov ah, 9 ;print prompt
int 21h
mov ah, 1
int 21h
mov [chr3], al ; move to labled memory
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah, 2
int 21h
mov dl, [chr1] ;move chr value to dl for print
mov ah, 2
int 21h
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah, 2
int 21h
mov dl, [chr2] ;move chr value to dl for print
mov ah, 2
int 21h
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah, 2
int 21h
mov dl, [chr3] ;move chr value to dl for print
mov ah, 2
int 21h
mov ah,4ch
int 21h
Nme: db 'my name here $' ;replace by your name
prompt1: db 'Enter first chr: $' ;ask for chr
prompt2: db 'Enter second chr: $' ;ask for chr
prompt3: db 'Enter third chr: $' ;ask for chr
chr1: DB 0 ;memory to store chr
chr2: DB 0 ;memory to store chr
chr3: DB 0 ;memory to store chr
您的代码似乎使用的是MASM语法,而不是NASM。NASM无法处理MASM语法。您需要使用MASM或类似于TASM甚至JWASM的兼容工具来组装此文件。否则,您必须将其转换为NASM语法。更改字符的所有实例是什么意思?到[character?]为止,我唯一的错误是mov字符1-3上的操作码和操作数组合无效,所有行都会替换1、2或3的问号。因此,您的character3需要更改为[character3]。与MASM不同,当您需要内存位置的内容时,需要将其括在括号中。当更改为[character?]时,我收到错误:无法识别的方向对不起,我应该澄清一下,错误是?替换为1-3,当没有[]时,我会收到错误,当我使用此@ArthurL声明时,我会收到无法识别的指令,声明仍然保留为character1 db 0,但当您要将内容移动到DL中时,则在该内存位置保存DL时将使用mov DL、[character1]或mov[character1],DL。
org 256
mov dx, Nme ;move content to dx
mov ah, 9 ;ask to print array of string
int 21h
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah, 2
int 21h
mov dx, prompt1 ;if use lea no need to use offset
mov ah, 9 ;print prompt
int 21h
mov ah, 1 ;ask for chr input
int 21h
mov [chr1] ,al ; move to labled memory
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah, 2
int 21h
mov dx , prompt2 ;if use lea no need to use offset
mov ah, 9 ;print prompt
int 21h
mov ah,1 ;ask for chr input
int 21h
mov [chr2], al ; move to labled memory
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah,2
int 21h
mov dx, prompt3 ;if use lea no need to use offset
mov ah, 9 ;print prompt
int 21h
mov ah, 1
int 21h
mov [chr3], al ; move to labled memory
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah, 2
int 21h
mov dl, [chr1] ;move chr value to dl for print
mov ah, 2
int 21h
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah, 2
int 21h
mov dl, [chr2] ;move chr value to dl for print
mov ah, 2
int 21h
mov dx, 10 ;print \n
mov ah, 2
int 21h
mov dx, 13 ;cursor at first position
mov ah, 2
int 21h
mov dl, [chr3] ;move chr value to dl for print
mov ah, 2
int 21h
mov ah,4ch
int 21h
Nme: db 'my name here $' ;replace by your name
prompt1: db 'Enter first chr: $' ;ask for chr
prompt2: db 'Enter second chr: $' ;ask for chr
prompt3: db 'Enter third chr: $' ;ask for chr
chr1: DB 0 ;memory to store chr
chr2: DB 0 ;memory to store chr
chr3: DB 0 ;memory to store chr