英特尔8086 - 推送命令抛出错误

时间:2016-10-05 07:59:27

标签: assembly x86 emu8086

我应该为作业修改一些代码。我的问题是代码本身无法正常工作。我不是要求帮助完成任务,只是让示例代码工作。话虽如此,任何帮助都表示赞赏。

首先,这是代码我;我应该使用的代码:

char

当我尝试编译并运行它时,它引发的错误在第48行,并且是:

;Program to add two single digit numbers - answer must also be a single digit number.

.model small
.stack 100h
.data

prompt1 db  13, 10, 'Enter the first number to add:', 13, 10, '$'
prompt2 db  13, 10, 'Enter the second number:', 13, 10, '$'
answer      db  13, 10, 'The answer is:', '$'
num1        db  ?
num2        db  ?

.code

start:
        mov ax, @data
        mov ds, ax
        mov ax, offset prompt1  ;prompt to enter first number
        call puts
        call getc           ;collect first number
        mov num1, al            ;and save

        mov ax, offset prompt2  ;prompt to enter 2nd number
        call puts
        call getc           ;collect second number
        mov num2, al            ;and save





mov ax, offset answer       ;display answer message
        call puts

        mov al, num1
        add al, num2            ;calculate answer
        sub al, '0'         ;convert to a character for display

        mov dl, al
        call putc           ;and display it

        mov ax, 4c00h
        int 21h

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

puts:                   ; display a string terminating in $
    push ax bx cx dx    ; save ax, bx, cx, dx
    mov  dx, ax     ; address of string must be stored in dx
    mov  ah, 9h
    int   21h       ; MSDOS called to display string
    pop dx cx bx ax ; restore dx cx bx ax
ret

getc:   
    push   bx cx dx ; save bx cx dx
    mov  dx, ax     ; address of string must be stored in dx
    mov  ah, 1h     ; char read into al, and output on screen
    int   21h       ; MSDOS called to read char
    pop dx cx bx        ; restore dx cx bx
    ret

putc:   
    push   ax bx cx dx  ; save ax bx cx dx
    mov  ah, 02h
    int   21h               ; MSDOS called to display char
    pop  dx cx bx ax    ; restore dx cx bx ax
    ret

end start

有问题的一行是:

wrong parameters: PUSH ax bx cx dx

非常感谢任何和所有帮助。

1 个答案:

答案 0 :(得分:1)

就像Axel已经说过的那样,你会运行多个推送和弹出指令。或者也许可以使用PUSHA和POPA指令一次推/弹所有寄存器?