16位程序集打印额外的未知字符

时间:2013-02-06 07:05:43

标签: assembly x86 masm

我想用16位汇编(winasm IDE和masm)打印简单的 hello world ,但在显示“hello world”未知字符之前。 这是代码:

.MODEL small
.STACK 100h
.data
message db "Hello, world!$"
.code
_start:
    mov ah,9
    lea dx,message ; addr of buffer
    int 21h
    mov ah,1
    int 21h
END _start

2 个答案:

答案 0 :(得分:3)

我不太确定MASM语法,但您必须将DS寄存器设置为:

    mov  ax, @data  ; if the .data labels points to your data segment
    mov  ds, ax
; then your code
    mov  ah, 9 ..........

答案 1 :(得分:0)

在执行任何代码之前,您必须将CS移动到DS中。

.code
start:
    push cs ; <-- important!
    pop ds ; <-- important!
    ; -- your codes here --
    mov eax, 9h
    ...
    mov ax, 4C00h
    int 21h
end start