Search code examples
assemblyx86masm

push and pop error A2070


When i run the program i get a line 16 error that says error A2070, line 16 is mov ax, message[si]. Is it because i am moving from a register to a register? Also how could i fix this problem? The program is a simple push and pop of a string storing each character in the stack increment the stack message, and then pop the stack to display the string backwards.

;
.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

Solution

  • You declared your string as type DB :

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

    DB means "one byte", but you are moving one byte into the two bytes register AX, which is a size conflict. Let's fix it :

    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
    

    By the way, your call to int 21 to print the string is missing the "h" : int 21h.