第六章子程序结构 过程定义伪操作 子程序的调用与返回 保存与恢复寄存器 子程序的参数传送 子程序的嵌套与递归
1 第六章 子程序结构 • 过程定义伪操作 • 子程序的调用与返回 • 保存与恢复寄存器 • 子程序的参数传送 • 子程序的嵌套与递归
1.过程定义伪操作 过程名 PROC NEAR(FAR) 过程名ENDP (1)NEAR属性:调用程序和子程序在同一代码段中 (段内调用) (2)FAR属性:调用程序和子程序不在同一代码段中 (段间调用)
2 1. 过程定义伪操作 过程名 PROC NEAR ( FAR ) 过程名 ENDP (1)NEAR属性:调用程序和子程序在同一代码段中 (段内调用) (2)FAR属性:调用程序和子程序不在同一代码段中 (段间调用) . .
code segment segx segment subt proc far main proc far ret call subr1 subt endp ret call subt main endp segx ends subl proc near segy segment ret subl endp call subt code ends segy ends
3 code segment main proc far …… call subr1 …… ret main endp subr1 proc near …… ret subr1 endp code ends segx segment subt proc far …… ret subt endp …… call subt …… segx ends segy segment …… call subt …… segy ends
2.子程序的调用与返回 子程序调用:隐含使用堆栈保存返回地址 call near ptr subp (1)保存返回地址 2)转子程序 sP)→(IP) call far ptr subp (1)保存返回地址 (2)转子程序 sP)→(工P) (CS) 子程序返回:ret
4 子程序调用:隐含使用堆栈保存返回地址 call near ptr subp (1) 保存返回地址 (2) 转子程序 call far ptr subp (1) 保存返回地址 (2) 转子程序 子程序返回:ret 2. 子程序的调用与返回 (SP)→ (IP) (IP) (CS) (SP)→
3.保存与恢复寄存器 subt proc far push ax push bx push CX push d 面面面面面面 pop dx pop CX pop bx pop ret subt endp 5
5 3. 保存与恢复寄存器 subt proc far push ax push bx push cx push dx …… …… pop dx pop cx pop bx pop ax ret subt endp