我应该为作业修改一些代码。我的问题是代码本身无法正常工作。我不是在寻求任务帮助,只是让示例代码工作。话虽这么说,任何帮助表示赞赏。
首先,这是我应该使用的代码:
;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
当我尝试编译和运行它时它抛出的错误在第 48 行,并且是:
wrong parameters: PUSH ax bx cx dx
有问题的行是:
push ax bx cx dx ; save ax, bx, cx, dx
任何和所有的帮助将不胜感激。