0

我正在尝试使用 INT 21h 在屏幕上显示一个字符串,但程序似乎立即崩溃......

我正在使用 MASM

这是我的代码:

.stack 200h

    .data?
      value dd ?

    .data
      item dd 0
      str1 db 'Hello world!$'
    .code

start:

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


    mov edx, offset str1
    mov al, 09h
    int 21h
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start
4

2 回答 2

2

A few problems:

  1. Your program doesn't exit to DOS correctly, it just lets the CPU execute whatever garbage is there in the memory after your int 21h. Use function 4ch to terminate your program.
  2. Your stack may be too little. Interrupt service routines and resident programs, drivers included (and probably DOS as well), use the current stack. If they need more than 200h bytes at any moment, they'll overwrite whatever code or data happens to be where they think there's still some stack space. That too can cause a crash or hang. Bump up the size to 1000h.
  3. You did not indicate what processor your program was run on. The problem is, you used an i80386+ instruction (mov edx, offset str1), which naturally isn't available on i8086/8088, i80186 and i80286 and their clones. Btw, DOS does not support 32-bit addresses or offsets. It should be mov dx, offset str1.

There might be something else, but let's fix these first.

于 2012-04-06T13:46:53.727 回答
0

如果您真的使用 8086,请使用: .model small org 100h .data message db "Hello World $" .code main proc mov ah,09h mov dx,offset message int 21h mov ah,4ch int 21h endp end main

更简单,更清洁的imo。

于 2014-10-01T11:57:30.807 回答