gpt4 book ai didi

assembly - 如何修复 “error:cannot generate COM file, stack segment present”?

转载 作者:行者123 更新时间:2023-12-02 10:49:47 25 4
gpt4 key购买 nike

我一直在尝试修复我的代码一段时间,但似乎无法使其正常工作,它总是告诉我错误:无法生成COM文件,存在堆栈段。有什么想法我可以解决这个问题吗?

这是我的代码:

.model small
.386
.stack 100h
.data
inpM db "Input string: $"
input db 19 ; max allowed 20
db ? ; # char entered
db 19 dup(0) ; chars entered
output db 19 dup("$")
.code
start: mov ax, @data
mov ds, ax

mov ah, 9 ; print inpM
lea dx, inpM
int 21h

mov ah, 0Ah ; get input
lea si, input
mov dx, si
int 21h

mov cl, [si+1] ; reverse
mov ch, 0
add si, cx
inc si
lea di, output

rev: mov al, [si]
mov [di], al
dec si
inc di
loop rev

again: mov ah, 6 ; clrscr
mov al, 0
mov cl, 0
mov ch, 0
mov dl, 4Fh
mov dh, 18h
mov bh, 0Fh
int 10h

mov ah, 0
mov bh, 0
mov dl, 27h ; column
mov dh, 0 ; row

mov ah, 9 ; print output
lea dx, output
int 21h

mov bx, 20000 ; delay
l1: mov cx, 0Fh

l2: dec bx
loop l2
jnz l1

add dh, 1 ; adds 1 to row

loop again

mov ah, 4Ch
int 21h
end start

附加信息:我的代码反转了字符串输入,然后将其显示在行中并有延迟。希望找出导致错误的原因以及如何解决该错误。

最佳答案

我从错误中假定您正在使用TASM和TLINK将其构建为.COM程序而不是EXE。您需要注意的事项:

  • COM程序应使用tiny模型,而不是small
  • COM程序需要在启动.code段后以100h的ORG开头。
  • COM程序中的堆栈从代码运行所在的段的顶部开始,因此需要删除设置堆栈的大小。
  • 因为使用COM程序CS = DS = ES = SS,所以不再需要像构建EXE文件那样设置DS。

  • 考虑到这些因素,您可以将代码的顶部修改为如下所示:
    .model tiny
    .386
    .data
    inpM db "Input string: $"
    input db 19 ; max allowed 20
    db ? ; # char entered
    db 19 dup(0) ; chars entered
    output db 19 dup("$")
    .code
    org 100h
    start:
    mov ah, 9 ; print inpM
    lea dx, inpM
    int 21h

    ...

    然后可以使用以下命令构建它:
    tasm myprg.asm
    tlink /t myprg.obj

    关于assembly - 如何修复 “error:cannot generate COM file, stack segment present”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47170656/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com