您的代码失败的原因是因为您的原始代码在顶部有这个:
ORG 100h
在 EMU8086 中,这具有将程序创建为 DOS COM 程序(不是 DOS EXE 程序)的副作用。使用 COM 程序 - 如果您将数据放在代码之前,它将开始将您的 DATA 作为代码执行。在您的情况下,它开始执行vect数组中的垃圾,然后尝试(未成功)运行您的实际代码。这是您的程序在运行时和通过 EMU8086 调试时表现出的所有奇怪行为的原因。
由于您显然有一个数据区域,并且堆栈只是org 100h从顶部删除,这将允许 EMU8086 将您的代码作为 DOS EXE 而不是 DOS COM 程序执行。
如果要创建 DOS COM 程序,则需要删除该.stack指令。将data段移到最后一段可执行代码之后,在本例中是由.exit. 这可确保当 DOS 在顶部启动您的程序时,DATA 不会作为代码执行。这不是 EMU8086 中的 DOS EXE 程序的问题。
DIM EQU 20
COUNT EQU 18
org 100h ; COM programs are placed 256 from beginning of
; of segment so we need ORG 100h. This
; also informs EMU8086 you want to make a COM program
; and not an EXE program.
; No Stack specified for a COM program as DOS
; automatically places it at the top of the 64K segment
; and grows downward toward the code and data.
.model tiny ; Normally COM programs are TINY model (CS=DS=SS)
.code
.startup ; This isn't needed for COM programs but won't hurt.
mov ax,1
mov bx,1
mov cx,COUNT
lea si,vect
mov word ptr [si],1 ; To avoid a bug we want to update the WORD at [si]
; not the BYTE.
add si,2
ciclo: mov [si],bx
mov dx,bx
add bx,ax
mov ax,dx
add si,2
LOOP ciclo
.exit ; Program exits here
.data ; Place the data after the code for a COM program
vect dw DIM dup ?
end