You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.ASCIIZ与DB的区别是什么?MASM环境下该如何选择?

MASM中DB字符串定义 vs .asciiz:该怎么选?

Hey there! Let's clear up this confusion since you're working in MASM, which has its own syntax rules that differ from other assemblers like NASM.

First off, a critical point: MASM does NOT support the .asciiz pseudo-instruction. That syntax you saw in reference programs is for other assemblers (like NASM or GAS) — if you try to use .asciiz in MASM, you'll get a syntax error.

Now let's break down the two approaches:

1. BPrompt DB 'Enter the value of B: ','$' (MASM标准写法)

This is the standard way to define strings in MASM for DOS-based assembly programs. Here's what's happening:

  • DB is MASM's "define byte" pseudo-instruction, which lets you allocate bytes in memory for your string.
  • The '$' at the end is a DOS-specific string terminator. When you use DOS interrupts like int 21h function 09h to print strings, the interrupt will keep outputting characters until it hits a $ — that's how it knows where the string ends.

2. .asciiz "Enter the value of B:" (Other assemblers only)

This syntax is used in assemblers like NASM or GNU Assembler (GAS). What it does is:

  • Define the string characters, then automatically append a null byte (0x00) at the end. This is the "C-style" string terminator, used by system calls (like Linux's write syscall) or C library functions that expect null-terminated strings.

So which should you use in MASM?

It all depends on what you're doing with the string:

  • If you're writing a classic DOS program using DOS interrupts for I/O, stick with DB plus '$' — this is the only way DOS will recognize and print your string correctly.
  • If you need a null-terminated string (for example, if you're interfacing with C code), you can manually add the null byte with MASM:
    BPrompt DB 'Enter the value of B:', 0
    
    This achieves the same result as .asciiz, but uses valid MASM syntax.

Quick recap

Forget about .asciiz when working in MASM — it's not supported. Use DB with the appropriate terminator: '$' for DOS I/O, or 0 for null-terminated strings.

内容的提问来源于stack exchange,提问作者Edward Talanian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:01:55