执行汇编代码时控制台上出现垃圾字符
x86 汇编编程初学者。我有一个简单的 asm 文件,我使用 nasm 版本 - 2011 年 6 月 6 日编译的 NASM 版本 2.10rc6 进行汇编,适用于 Windows(我的 Windows 是 Windowa-7 64 位)。 NASM 可从此处下载 (nasm-2.10rc6-win32 。拉链)。
ORG 100
USE16
mov ah, 09
mov dx, msg
int 21h
mov ah, 01
int 21h
mov ah, 4ch
int 21h
msg db 'Hello assembly', 0Ah, '$'
然后我使用命令进行组装 -
nasm -f bin hello.asm -o hello.com
然后我使用 Dosbox(64 位操作系统 Windows-7 的 Dos 模拟器)运行生成的可执行文件 hello.com。 当它运行时,控制台上的输出有我的字符串“Hello assembly”以及在其前面打印的一些垃圾字符/控制字符,如下所示:
这是什么原因。代码有什么问题吗?
我需要做什么来解决这个问题?
编辑:当我尝试为 nasm 提供选项 -f 来生成特定类型的可执行输出(例如 Win32 或 Win64 输出)时,我不断收到错误消息:
nasm -f win64 hello.asm -o hello.com
hello.asm:1: error: parser: instruction expected
它期待什么?如何使用 nasm 生成 win32/win64 可执行文件?或者就此而言,任何其他可执行文件(例如 nasm 表示支持的 elf32/coff)?
Beginner to assembly programming for x86. I have a simple asm file which I assemble using nasm version - NASM version 2.10rc6 compiled on Jun 6 2011, for windows(My windows is Windowa-7 64 bit). NASM is downloaded from here ( nasm-2.10rc6-win32.zip).
ORG 100
USE16
mov ah, 09
mov dx, msg
int 21h
mov ah, 01
int 21h
mov ah, 4ch
int 21h
msg db 'Hello assembly', 0Ah, '
Then I assemble using command -
nasm -f bin hello.asm -o hello.com
Then I run the generated executable hello.com using Dosbox(Dos emulator for 64 bit OS Windows-7).
When it runs the output output on the console has my string 'Hello assembly' plus some junk characters/control characters printed before it, as shown below:
What is the reason for this. Anything wrong in the code?
What do I need to do to fix this?
EDIT: When i tried to give a option -f to nasm to generate a specific type of executable output , e.g. Win32 or Win64 output i keep getting error saying:
nasm -f win64 hello.asm -o hello.com
hello.asm:1: error: parser: instruction expected
What is it expecting? How can i generate a win32/win64 executable using nasm? or for that matter any other executable like elf32/coff, which nasm says it supports?
Then I assemble using command -
nasm -f bin hello.asm -o hello.com
Then I run the generated executable hello.com using Dosbox(Dos emulator for 64 bit OS Windows-7).
When it runs the output output on the console has my string 'Hello assembly' plus some junk characters/control characters printed before it, as shown below:
What is the reason for this. Anything wrong in the code?
What do I need to do to fix this?
EDIT: When i tried to give a option -f to nasm to generate a specific type of executable output , e.g. Win32 or Win64 output i keep getting error saying:
What is it expecting? How can i generate a win32/win64 executable using nasm? or for that matter any other executable like elf32/coff, which nasm says it supports?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是:
应该是:
二进制文件是
.COM
,因此无论如何都会在100h
加载并运行;该错误意味着汇编器为msg
计算的地址将比应有的位置早 156 个字节,因此会产生额外的垃圾。ORG
指令仅适用于bin
格式。其他可执行格式具有节(或段)。 (请参阅 “输出格式” 部分www.nasm.us/doc/" rel="nofollow">NASM 手册。)The problem is:
which should be:
The binary is a
.COM
so will load and run at100h
regardless; the error means that the address calculated by the assembler formsg
will be 156 bytes earlier than it should be, hence the extra junk.The
ORG
directive is for thebin
format only. Other executable formats have sections (or segments). (See the "Output Formats" section of the NASM manual.)