您好我想在emu8086中制作从屏幕输入的两个数字相加的程序,我喜欢程序结束后继续的程序 我调用程序sumUp并且它做得很好但是在程序中退出之后程序完成..我希望程序继续下面的代码调用sumUp 非常感谢你
; multi-segment executable file template.
data segment
message1 db "Enter 2 number..$"
num1 db 0
num2 db 0
suma dw 0
ends
stack segment
dw 128 dup(0)
ends
code segment
sumUp proc
pop bx
pop ax
sub ax,30h
mov suma,ax
pop ax
sub ax,30h
add suma,ax
ret
sumUP endp
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
; add your code here
lea dx,message1
mov ah,09h
int 21h
mov ah,1h
int 21h
mov num1,al
mov ah,1h
int 21h
mov num2,al
mov dh,0d
mov dl,num1
push dx
mov dh,0d
mov dl,num2
push dx
call sumUp
//I want the program to continue here after procedure is finished
**mov cx,0**
ends
end start ; set entry point and stop the assembler.
答案 0 :(得分:1)
您正在弄乱堆栈上的返回地址,因此当ret
想要将其弹出(IP
时)时它就不存在了。
不是弹出来访问堆栈上的数据,而是将bp
设置为帧指针,这样就可以使用它作为基址寄存器来访问堆栈内存。
您必须保存/恢复来电者bp
;通常使用push / pop,但在这种情况下,我们可以将其隐藏在cx
(您不必保存/恢复)中,因为该功能很简单,并且不需要多个临时寄存器。
; multi-segment executable file template.
data segment
message1 db "Enter 2 number..$"
ends
stack segment
dw 128 dup(0)
ends
code segment
; inputs: first arg in AX, 2nd arg on the stack
; clobbers: CX
; returns in: AX
sumUp proc
mov cx, bp ; save caller's BP
mov bp, sp
mov ax, ss:[bp+2] ; get the value of pushed parameter without messing with top of the stack
mov bp, cx ; restore it.
ret
sumUP endp
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
; add your code here
lea dx,message1
mov ah,09h
int 21h
mov ah,1h
int 21h
mov ah, 0
sub al, 30h
push ax
mov ah,1h
int 21h
mov ah, 0
sub al, 30h
; no need to push second operand because its already in ax
call sumUp
; result in ax
mov ah, 04ch
int 21h
ends
end start ; set entry point and stop the assembler.
答案 1 :(得分:0)
push bx
:
code segment
sumUp proc
pop bx
pop ax
sub ax, 30h
mov suma, ax
pop ax
sub ax, 30h
add suma, ax
push bx ; needs to be added here
ret
sumUP endp