【问题标题】:push and pop error A2070推送和弹出错误 A2070
【发布时间】:2016-10-25 17:27:40
【问题描述】:

当我运行程序时,出现第 16 行错误,显示错误 A2070,第 16 行是 mov ax, message[si]。是因为我要从一个寄存器转移到一个寄存器吗?另外我该如何解决这个问题? 该程序是一个简单的push和pop字符串,将每个字符存储在堆栈中,递增堆栈消息,然后弹出堆栈以向后显示字符串。

;
.model small
.data
message db "Hello, DOS Here!",0 ; the string
nameSize = ($ - message) - 1        ;gives length of the string
.code
main proc
mov ax,@data
mov ds,ax

mov cx, nameSize        ;size of the string stored in cx
mov si, 0               ;stack index 0
Li:
    mov ax, message[si]     ;
    push ax                 ;push ax
    inc si                  ;incremting stack index
    loop Li                 ; looping through message character

mov cx, nameSize            ;Popping 
mov si, 0                   ; popping from stack

L2: 
    pop ax                  ;pop of the ax
    mov message[si], al     ;
    inc si
    loop L2

mov dx, offset message      ; displaying of string 
mov ah,9
int 21

mov ax,4c00h
int 21h
main endp
end main

【问题讨论】:

    标签: assembly x86 masm


    【解决方案1】:

    您将字符串声明为DB 类型:

            ▼
    message db "Hello, DOS Here!",0 ; the string
    

    DB 表示“一个字节”,但是您将一个字节移动到两个字节寄存器AX,这是大小冲突。让我们修复它:

    mov cx, nameSize        ;size of the string stored in cx
    mov si, 0               ;stack index 0
    xor ax, ax              ;◄■■■ CLEAR AX.
    Li:
        mov al, message[si]     ;◄■■■ USE AL.
        push ax                 ;push ax
        inc si                  ;incremting stack index
        loop Li                 ; looping through message character
    

    顺便说一句,您调用int 21 打印字符串时缺少“h”:int 21h

    【讨论】:

    • 谢谢你现在我明白它解决了问题但是当我在dos框中运行程序时它显示一个空程序不打印反向字符串@jose
    • @MikeShasaco,另一个错误:您的字符串应该以“$”而不是“0”结尾(因为您使用的是 int 21h ah=09)。
    • 感谢它的工作,但它也打印了一堆随机的 ascii 字符,但它确实向后打印了字符串。 @何塞
    • 非常感谢,我对汇编语言真的很陌生,有时会很困难。谢谢@jose
    猜你喜欢
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    • 2021-04-13
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多