汇编第六章答案.doc
《汇编第六章答案.doc》由会员分享,可在线阅读,更多相关《汇编第六章答案.doc(24页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、【精品文档】如有侵权,请联系网站删除,仅供学习与交流汇编第六章答案.精品文档.第六章答案=1.下面的程序段有错吗?若有,请指出错误.CRAY PROCPUSH AXADD AX,BXRETENDP CRAY解:当然有错误,ENDP CRAY写反了,应该将其改成CRAY ENDP.2.已知堆栈寄存器SS的内容是0F0A0H,堆栈指示器SP的内容是00B0H,先执行两条把8057H和0F79BH分别入栈的PUSH指令.然后再执行一POP指令.试画出示意图说明堆栈及SP内容的变化过程.3.分析下面6,3的程序,画出堆栈最满时各单元的地址及内容.; 6.3题的程序;=S_SEG SEGMENT AT
2、1000H ;DEFINE STACK SEGMENTDW 200 DUP(?)TOS LABEL WORDS_SEG ENDSC_SEG SEGMENT ;DEFINE CODE SEGMENTASSUME CS:C_SEG,SS:S_SEGMOV AX,S_SEGMOV SS,AXMOV SP,OFFSET TOSPUSH DSMOV AX,0PUSH AX.PUSH T_ADDRPUSH AXPUSHF.POPFPOP AXPOP T_ADDRRETC_SEG ENDS ;END OF CODE SEGMENTEND C_SEG ;END OF ASSEMBLY4.分析下面6.4题的程序
3、的功能,写出堆栈最满时各单元的地址及内容.; 6.4题的程序;=STACK SEGMENT AT 500HDW 128 DUP(?)TOS LABEL WORDSTACK ENDSCODE SEGMENT ;DEFINE CODE SEGMENTMAIN PROC FAR ;MAIN PART OF PROGRAMASSUME CS:CODE,SS:STACKSTART: ;STARTING EXECUTION ADDRESSMOV AX,STACKMOV SS,AXMOV SP,OFFSET TOSPUSH DSSUB AX,AXPUSH AX;MAIN PART OF PROGRAM GO
4、ES HEREMOV AX,4321HCALL HTOARET ;RETURN TO DOSMAIN ENDP ;END OF MAIN PART OF PROGRAMHTOA PROC NEAR ;DEFINE SUBPROCEDURE HTOACMP AX,15JLE B1PUSH AXPUSH BPMOV BP,SPMOV BX,BP+2AND BX,000FHMOV BP+2,BXPOP BPMOV CL,4SHR AX,CLCALL HTOAPOP AXB1:ADD AL,30HCMP AL,3AHJL PRINTITADD AL,07HPRINTIT:MOV DL,ALMOV AH
5、,2INT 21HRETHTOA ENDP ;END OF SUBPROCEDURECODE ENDS ;END OF CODE SEGMENTEND START ;END OF ASSEMBLY5.下面是6.5题的程序清单,请在清单中填入此程序执行过程中的堆栈变化.0000 STACKSG SEGMENT0000 20 . DW 32 DUP(?)?0040 STACKSG ENDS0000 CODESG SEGMENT PARA CODE0000 BEGIN PROC FAR ASSUME CS:CODESG,SS:STACKSG0000 1E PUSH DS0001 2B C0 SUB
6、AX,AX0003 50 PUSH AX0004 E8 0008 R CALL P100007 CB RET0008 BEGIN ENDP0008 B10 PROC0008 E8 000C R CALL C10000B C3 RET000C B10 ENDP000C C10 PROC000C C3 RET000D C10 ENDP000D CODESG ENDS END BEGIN6.写一段子程序SKIPLINES,完成输出空行的功能.空行的行数在AX寄存器中.解:SKIPLINES PROC NEAR PUSH CX PUSH DX MOV CX,AX NEXT: MOV AH,2 MOV
7、DL,0AH INT 21H MOV AH,2 MOV DL,0DH INT 21H LOOP NEXT POP DX POP CX RET SKIPLINES ENDP7.设有10个学生的成绩分别是76,69,81,90,73,88,99,63,100和80分.试编制一个子程序统计60-69,70-79,80-89,90-99和100分的人数并分别存放到S6,S7,S8,S9和S10单元中.DSEG SEGMENT NUM DW 76,69,84,90,73,88,99,63,100,80 N DW 10 S6 DW 0 S7 DW 0 S8 DW 0 S9 DW 0 S10 DW 0 DS
8、EG ENDS CODE SEGMENT MAIN PROC FAR ASSUME CS:CODE, DS:DSEG START: PUSH DS SUB AX, AX PUSH AX MOV AX, DSEG MOV DS, AX CALL SUB1 RET MAIN ENDP SUB1 PROC NEAR PUSH AX PUSH BX PUSH CX PUSH SI MOV SI, 0 MOV CX, N NEXT: MOV AX, NUMSI MOV BX, 10 DIV BL MOV BL, AL CBW SUB BX, 6 SAL BX, 1 INC S6BX ADD SI,2 L
9、OOP NEXT POP SI POP CX POP BX POP AX RET SUB1 ENDP CODE ENDS END START (解法二)datasg segmentgrade db 76,69,84,90,73,88,99,63,100,80s6 db 0s7 db 0s8 db 0s9 db 0s10 db 0mess6 db 6069:$mess7 db 7079:$mess8 db 8089:$mess9 db 9099:$mess10 db 100:$datasg endscodesg segmentmain proc far assume cs:codesg,ds:d
10、atasgstart: push ds sub ax,ax push ax mov ax,datasg mov ds,ax call sub1 lea dx,mess6 call dispstr mov dl,s6 call dispscore call crlf lea dx,mess7 call dispstr mov dl,s7 call dispscore call crlf lea dx,mess8 call dispstr mov dl,s8 call dispscore call crlf lea dx,mess9 call dispstr mov dl,s9 call disp
11、score call crlf lea dx,mess10 call dispstr mov dl,s10 call dispscore call crlf retmain endpsub1 proc near mov cx,10 mov si,0loop1: mov al,gradesi cmp al,60 jl next5 cmp al,70 jge next1 inc s6 jmp short next5next1: cmp al,80 jge next2 inc s7 jmp short next5next2: cmp al,90 jge next3 inc s8 jmp short
12、next5next3: cmp al,100 jg next5 je next4 inc s9 jmp short next5next4: inc s10next5: inc si loop loop1 retsub1 endpdispstr proc near mov ah,9 int 21hdispstr endpdispscore proc near add dl,30h mov ah,2 int 21hdispscore endpcrlf proc near mov dl,0dh mov ah,2 int 21h mov dl,0ah mov ah,2 int 21h retcrlf
13、endpcodesg endsend start8.编写一个有主程序和子程序结构的程序模块.子程序的参数是一个N字节数组的首地址TABLE,数N及字符CHAR.要求在N字节数组中查找字符CHAR,并记录该字符的出现次数.;主程序则要求从键盘接收一串字符以建立字节数组TABLE,并逐个显示从键盘输入的每个字符CHAR以及它在TABLE数组中出现的次数.(为简化起见,假设出现次数=15,可以用十六进制形式显示出来)解:DATA SEGMENT MAXLEN DB 40 N DB ? TABLE DB 40 DUP (?) CHAR DB A ; 查找字符A EVEN _ADDR DW 3 DUP(
14、?) DATA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA MAIN PROC FAR START: PUSH DS MOV AX, 0 PUSH AX MOV AX, DATA MOV DS, AX LEA DX, MAXLEN MOV AH, 0AH INT 21H ; 从键盘接收字符串 MOV _ADDR, OFFSET TABLE MOV _ADDR+2, OFFSET N MOV _ADDR+4, OFFSET CHAR MOV BX, OFFSET _ADDR ; 通过地址表传送变量地址 CALL COUNT ; 计算CHAR的出现次数 CA
15、LL DISPLAY ; 显示 RET MAIN ENDPCOUNT PROC NEAR ; COUNT子程序 PUSH SI PUSH DI PUSH AX PUSH CX MOV DI, BX MOV SI, BX+2 MOV CL, BYTE PTRSI MOV CH, 0 MOV SI, BX+4 MOV AL, BYTE PTRSI MOV BX, 0 AGAIN: CMP AL, BYTE PTRDI JNE L1 INC BX L1: INC DI LOOP AGAIN POP CX POP AX POP DI POP SI RET COUNT ENDP DISPLAY PROC
16、 NEAR ; DISPLAY子程序 CALL CRLF ; 显示回车和换行 MOV DL, CHAR MOV AH, 2 INT 21H MOV DL, 20H MOV AH, 2 INT 21H MOV AL, BL AND AL, 0FH ADD AL, 30H CMP AL, 3AH JL PRINT ADD AL, 7 PRINT: MOV DL, AL INT 21H CALL CRLF RET DISPLAY ENDP CRLF PROC NEAR ; CRLF子程序 MOV DL, 0DH MOV AH, 2 INT 21H MOV DL, 0AH MOV AH, 2 INT
17、21H RET CRLF ENDP CODE ENDS END START9.编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及8个字符的电话号码,并以一定的格式显示出来.主程序TELIST:(1)显示提示符INPUT NAME:;(2)调用子程序INPUT_NAME输入姓名:(3)显示提示符INPUT A TELEPHONE NUMBER:;(4)调用子程序INPHONE输入电话号码;(5)调用子程序PRINTLINE显示姓名及电话号码;子程序INPUT_NAME:(1)调用键盘输入子程序GETCHAR,把输入的姓名存放在INBUF缓冲区中;(2)把INBUF中的姓名移入输出行OUTNA
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 汇编 第六 答案
限制150内