分类: WINDOWS
2007-10-23 16:29:23
6.2.5 |
用代码流传递参数 |
由位于CALL指令之后的代码流(Code Stream)传递参数。
DESG SEGMENT |
||
COUNT |
DW 5 |
;DW:1个字,即16bit或两个字节 |
ARRAY |
DW 8,-1,32766,0,100 |
;32766=7FFEH |
MAX |
DW ? |
|
DESG ENDS |
||
SSEG SEGMENT STACK |
||
DW 128 DUP(?) |
||
SSEG ENDS |
||
CSEG1 SEGMENT |
||
ASSUME CS:CSEG1,DS:DSEG,SS:SSEG | ||
START: |
||
MOV AX,DSEG |
||
MOV DS,AX |
||
CALL FINDMAX |
||
DD COUNT,ARRAY,MAX |
||
MOV AH,4CH |
||
INT 21H |
||
CSEG1 ENDS |
||
CSEG2 SEGMENT |
||
ASSUME CS:CSEG2,SS:SSEG | ||
FINDMAX PROC FAR |
||
MINSW |
=8000H |
;16位带符号数的最小值 |
PUSH BP |
||
MOV BP,SP |
||
PUSH AX |
||
PUSH BX |
||
PUSH CX |
||
PUSH SI |
||
PUSH DS |
||
PUSH ES |
||
LDS BX,2[BP] |
;装入返回地址到DS:BX | |
LES SI,[BX] |
;取元素个数所在地址到ES:SI | |
MOV CX,ES:[SI] |
;取得元素个数 | |
LES SI,4[BX] |
;取得数组首地址 | |
MOV AX,MINSW |
||
NEXT: |
CMP AX,ES:[SI] |
|
JG SKIP |
||
MOV AX,ES:[SI] |
||
SKIP: |
ADD SI,2 |
|
LOOP NEXT |
||
LES SI,8[BX] |
;取得存放最大值的地址 | |
MOV ES:[SI],AX |
||
ADD BX,12 |
;代码流有12个字节 | |
MOV 2[BP],BX |
;修改返回地址 | |
POP ES |
||
POP DS |
||
POP SI |
||
POP CX |
||
POP BX |
||
POP AX |
||
POP BP |
||
RET |
||
FINDMAX ENDP |
||
CSEG2 ENDS |
||
END START |