为什么程序完成后程序不继续(emu8086)?

Why program is not continuing after the procedure is done(emu8086)?

你好,我想制作一个程序,将两个从屏幕输入的数字相加在 emu8086 中,我希望程序在程序完成后继续 我调用程序 sumUp 并且它做得很好但是在程序中 ret 之后程序完成..我希望程序继续调用代码调用 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.

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

你弄乱了堆栈上的 return 地址,所以当 ret 想要弹出它(进入 IP)时它不在那里。

不要弹出来访问堆栈上的数据,而是将 bp 设置为帧指针,以便您可以将其作为基址寄存器来访问堆栈内存。

您必须 save/restore 您的来电者 bp;通常使用 push/pop,但在这种情况下我们可以将其存储在 cx 中(您不必 save/restore),因为该功能很简单并且不需要多个临时寄存器。

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