资源描述
第六章习题答案6.1 C6.2 D6.3 D6.4 C 6.5 B6.6 错。在L0: MOV AL,0语句后面加上RET语句6.7段内调用:保存IP内容入栈;更新IP内容段间调用:保存CS,IP内容入栈;更新CS,IP内容6.8段内返回:从栈中弹出一个字的内容送入IP寄存器;SP=(SP)+n(如果带有操作数n)段间返回:从栈中弹出两个字的内容分别送入IP,CS;SP=(SP)+n(如果带有操作数n)6.9从栈中弹出两个字的内容分别送入IP,CS;SP=(SP)+46.10在需要和主程序共享寄存器的时候需要保护寄存器6.11寄存器传递参数;堆栈传递参数;地址表传递参数6.12相同点:都进行一次程序跳转不同点:CALL会保存原地址IP入栈,而JMP不会6.13错误:子程序是FAR类型的,CALL时用的是NEAR6.14BX;(BX);SHIFT6.15图略6.16DATA SEGMENT N DB 5DATA ENDSSTACK SEGMENTDW 20H DUP(0)STACK ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,SS:STACKBEGIN:MOV AX,DATAMOV DS,AXMOV AL,NCALL FACT;调用阶乘子程序计算5!MOV RESULT,DXDEC NMOV AL,NCALL FACT;调用阶乘子程序计算4!ADD RESULT,DXDEC NMOV AL,NCALL FACT;调用阶乘子程序计算3!ADD RESULT,DXMOV AH,4CHINT 21HFACT PROC NEAR;阶乘子程序MOV DX,1CMP AL,0JZ DONEPUSH AXDEC ALCALL FACTPOP AXMUL DLMOV DX,AXDONE:RETFACT ENDPCODE ENDSEND BEGIN6.17略618(1)寄存器传值MOV AX,DATAMOV DS,AXMOV SI,OFFSET NUMMOV CX,COUNTMOV DX,0CALL FMOV AH,4CHINT 21HF PROCLOP:MOV DI,OFFSET NUM20ADD DI,DXINC DXXOR BL,BLMOV AX,SILOP20:CMP AX,20JC SUB5SUB AX,20INT BLJMP LOP20SUB5:MOV DI,BLXOR BL,BLLOP5:CMP AX,5JC SUB2SUB AX,5INT BLJMP LOP5SUB2:ADD DI,COUNT; DI=DI+2*COUNTMOV DI,BLXOR BL,BLLOP2:CMP AX,2JC SUB1SUB AX,2INT BLJMP LOP2SUB1:ADD DI,COUNT SHL 1;DI=DI+2*COUNTMOV DI,BLXOR BL,BLLOP1:CMP AX,1JC DONESUB AX,1INT BLJMP LOP1DONE:ADD DI,COUNT ADD DI,COUNTADD DI,COUNT;DI=DI+3*COUNTMOV DI,BLADD SI,2LOOP LOPRETF ENDPEODE ENDS(2)堆栈传值BEGIN:MOV AX,DATAMOV DS,AXMOV SI,OFFSET NUMMOV DI OFFSET NUM20MOV CX,COUNTPUSH SIPUSH DIPUSH CXCALL FMOV AH,4CHINT 21HF PROCPUSH AXPUSH BXPUSH CXPUSH SIPUSH DIMOV BP,SPMOV CX,12BPMOV DI,14BPMOV SI,16BPLOP:XOR BL,BLMOV AX,SILOP20:CMP AX,20JC SUB5SUB AX,20INC BLJMP LOP20SUB5:MOV DI,BLXOR BL,BLLOP5:CMP AX,5JC SUB2SUB AX,5INC BLJMP LOP5SUB2:MOV DI+COUNT,BLXOR BL,BLLOP2:CMP AX,2JC SUB1SUB AX,2INC BLJMP LOP2SUB1:MOV DI+COUNT+COUNT,BLXOR BL,BLLOP1:CMP AX,1JC DONESUB AX,1INC BLJMP LOP1DONE:MOV DI+COUNT+COUNT+COUNT,BLADD SI,2INT DILOOP LOPRETF ENDPCODE ENDSEND BEGIN
展开阅读全文