资源描述
,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,第五章课后习题参考答案,P86_4.16,若在数组字变量AQTAB平方表中有十进制数020的平方值,从表中找出16的平方值,结果送字变量NUM单元中。,1,第五章课后习题参考答案P86_4.16 若在数组字变量AQT,参考答案,DATA SEGMENT,AQTAB DW 0,1,4,9,16,25,36,49,64,81,100,121,144,DW 169,196,225,256,289,324,361,400,BUF DW 16,NUM DW?,DATA ENDS,CODE SEGMENT,ASSUME CS:CODE,DS:DATA,BEGIN:MOV AX,DATA,MOV DS,AX,MOV BX,OFFSET AQTAB,MOV AX,BUF,ADD AX,AX,ADD BX,AX,MOV AX,BX,MOV NUM,AX,MOV AH,4CH,INT 21H,CODE ENDS,END BEGIN,2,参考答案DATA SEGMENT MOV AX,P86_4.17,计算D=B*2-4AC,设A=2,B=9,C=8,结果存放在RESUT中。(A、B、C均为有符号字节数据),DATA SEGMENT,A DB 2,B DB 9,C DB 8,RESULT DW?,?,DATA ENDS,CODE SEGMENT,ASSUME DS:DATA,CS:CODE,START:MOV AX,DATA,MOV DS,AX,3,P86_4.17 计算D=B*2-4AC,设A=2,B=9,MOV AL,2,IMUL B,CWD,MOV BX,DX,MOV CX,AX,MOV AL,A,IMUL C,MOV DX,4,IMUL DX,SUB CX,AX,SBB BX,DX,MOV RESULT,CX,MOV RESULT+2,BX,MOV AH,4CH,INT 21H,CODE ENDS,ENDSTART,思考:,用移位指令代替乘法指令要注意什么问题,4,MOV AL,2思考:用移位指令代替乘法指令要,P102_5.6参考答案1,BUF1偶数?,Y,N,开始,结束,BUF2偶数?,Y,N,BUF1与BUF2交换,BUF2偶数?,Y,N,BUF1中数1,BUF2中数1,5,P102_5.6参考答案1BUF1偶数?YN开始结束BUF2,DATA SEGMENT,BUF1 DB 30H,BUF2 DB 23H,DATA ENDS,CODE SEGMENT,ASSUME DS:DATA,CS:CODE,START:MOV AX,DATA,MOV DS,AX,MOV AL,BUF1,MOV BL,BUF2,TEST AL,01H,JZ OS1,;BUF1中为偶数,TEST BL,01H,JZ EXIT,;BUF1中奇数,BUF2为偶数,INC BUF1,;均为奇数,INC BUF2,JMP EXIT,6,DATA SEGMENT6,OS1:TEST BL,01H,JZ EXIT,;均为偶数,MOV BUF1,BL,;BUF1中偶数,BUF2为奇数,MOV BUF2,AL,EXIT:MOV AH,4CH,INT 21H,CODE ENDS,ENDSTART,7,OS1:TEST BL,01H7,BUF2偶数?,Y,N,开始,结束,N,BUF1与BUF2交换,BUF1偶数?,Y,BUF11;BUF21,P102_5.6参考答案2,8,BUF2偶数?YN开始结束NBUF1与BUF2交换BUF1偶,DATA SEGMENT,BUF1 DB 30H,BUF2 DB 23H,DATA ENDS,CODE SEGMENT,ASSUME DS:DATA,ASSUME CS:CODE,START:MOV AX,DATA,MOV DS,AX,MOV AL,BUF1,MOV BL,BUF2,TEST BL,01H,JZ EXIT,;BUF2中为偶数,TEST AL,01H,JZ JIAOHUAN,;BUF1中偶数,BUF2为奇数,INC BUF1,;均为奇数,INC BUF2,JMP EXIT,JIAOHUAN:MOV BUF1,BL,MOV BUF2,AL,EXIT:MOV AH,4CH,INT 21H,CODE ENDS,ENDSTART,9,DATA SEGMENT INC BUF1;均为,DATA SEGMENT,BUF DB 30H,02H,10H,11H,56H,78H,65H,54H,85H,19H,CNT EQU$-BUF,SUM DB?,DATA ENDS,CODE SEGMENT,ASSUME CS:CODE,DS:DATA,START:MOV AX,DATA,MOV DS,AX,MOV SI,OFFSET BUF,MOV CX,CNT,MOV AX,0,P102_57,ADD1:ADD AL,SI,ADC AH,0,INC SI,LOOP ADD1,MOV CL,CNT,DIV CL,MOV SUM,AL,MOV AH,4CH,INT 21H,CODE ENDS,END START,10,DATA SEGMENTP102_57ADD1:ADD,DATA SEGMENT,X DW -123,Y DW 50,Z DW 1234H,DATA ENDS,CODE SEGMENT,ASSUME DS:DATA,CS:CODE,START:MOV AX,DATA,MOV DS,AX,MOV AX,X,MOV BX,Y,MOV CX,Z,CMP AX,BX,JGE L1,P102_58,CMP BX,CX,JL L2,MOV AX,BX,JMP EXIT,L2:MOV AX,CX,JMP EXIT,L1:CMP AX,CX,JL L2,EXIT:MOV AH,4CH,INT 21H,CODE ENDS,ENDSTART,11,DATA SEGMENTP102_58 CMP,P102_5.9,从STRING开始存放一以为结束标志的字符串,把字符串中的字符分类,数字送入NUM开始的内存区,大写字母送入BCHAR开始的内存区,小写字母送入LCHAR开始的内存区,其它字符存到OTHER开始的内存区。,参考程序1:,DATA SEGMENT,STRING DB 1$2AaDd#,CNT EQU$-STRING-1,NUM DB CNT DUP(?),BCHAR DB CNT DUP(?),LCHAR DB CNT DUP(?),OTHER DB CNT DUP(?),DATA ENDS,CODE SEGMENT,ASSUME CS:CODE,DS:DATA,START:MOV AX,DATA,MOV DS,AX,12,P102_5.9从STRING开始存放一以为结束标志的字符,MOV SI,OFFSET STRING,MOV DI,OFFSET NUM,MOV BP,OFFSET BCHAR,MOV CX,OFFSET LCHAR,MOV DX,OFFSET OTHER,LOP1:MOV AL,SI,CMP AL,#,JZ EXIT,CMP AL,0,JB OTHER1,CMP AL,9,JBE NUM1,CMP AL,A,JB OTHER1,CMP AL,Z,JBE BCHAR1,CMP AL,a,JB OTHER1,CMP AL,z,JA OTHER1,LCHAR1:MOV BX,CX,MOV BX,AL,INC CX,JMP NEXT,BCHAR1:MOV DS:BP,AL,INC BP,JMP NEXT,NUM1:MOV DI,AL,INC DI,JMP NEXT,OTHER1:MOV BX,DX,MOV BX,AL,INC DX,NEXT:INC SI,JMP LOP1,EXIT:MOV AH,4CH,INT 21H,CODE ENDS,END START,13,MOV SI,OFFSET STRINGLCH,参考程序2:,DATA SEGMENT,STRING DB 1$2AaDd#,CNT EQU$-STRING-1,NUM DB CNT DUP(?),BCHAR DB CNT DUP(?),LCHAR DB CNT DUP(?),OTHER DB CNT DUP(?),ADD1 DW?,?,?,?,DATA ENDS,CODE SEGMENT,ASSUME CS:CODE,ASSUME DS:DATA,START:MOV AX,DATA,MOV DS,AX,MOV SI,OFFSET STRING,MOV DI,OFFSET NUM,MOV ADD1,DI,MOV DI,OFFSET BCHAR,MOV ADD1+2,DI,MOV DI,OFFSET LCHAR,MOV ADD1+4,DI,MOV DI,OFFSET OTHER,MOV ADD1+6,DI,14,参考程序2:START:MOV AX,DATA14,LOP1:MOV AL,SI,CMP AL,#,JZ EXIT,CMP AL,0,JB,OTHER1,CMP AL,9,JBE,NUM1,CMP AL,A,JB,OTHER1,CMP AL,Z,JBE,BCHAR1,CMP AL,a,JB,OTHER1,CMP AL,z,JA,OTHER1,LCHAR1:MOV BX,ADD1+2,MOV BX,AL,INC ADD1+2,JMP NEXT,BCHAR1:MOV BX,ADD1+4,MOV BX,AL,INC ADD1+4,JMP NEXT,NUM1:MOV BX,ADD1,MOV BX,AL,INC ADD1,JMP NEXT,OTHER1:MOV BX,ADD1+6,MOV BX,AL,INC ADD1+6,NEXT:INC SI,JMP LOP1,EXIT:MOV AH,4CH,INT 21H,CODE ENDS,END START,15,LOP1:MOV AL,SIBCHAR1:MOV B,ERR:,DATA SEGMENT,STRING DB 1$2AaDd#,CNT EQU$-STRING-1,NUM DB CNT DUP(?),BCHAR DB CNT DUP(?),LCHAR DB CNT DUP(?),OTHER DB CNT DUP(?),DATA ENDS,CODE SEGMENT,ASSUME CS:CODE,DS:DATA,START:MOV AX,DATA,MOV DS,AX,MOV SI,OFFSET STRING,16,ERR:16,LOP1:MOV AL,SI,CMP AL,#,JZ EXIT,CMP AL,0,JB,OTHER1,CMP AL,9,JBE,NUM1,CMP AL,A,JB,OTHER1,CMP AL,Z,JBE,BCHAR1,CMP AL,a,JB,OTHER1,CMP AL,z,JA,OTHER1,LCHAR1:MOV LCHAR,AL,INC LCHAR,JMP NEXT,BCHAR1:MOV BCHAR,AL,INC BCHAR,JMP NEXT,NUM1:MOV NUM,AL,INC NUM,JMP NEXT,OTHER1:MOV OTHER,AL,INC OTHER,NEXT:INC SI,JMP LOP1,EXIT:MOV AH,4CH,INT 21H,CODE ENDS,END START,17,LOP1:MOV AL,SIBCHAR1:MOV BC,P102_5.10,DATA SEGMENT,SCORE DB 96,87,88,85,78,67,77,90,81,100,DB 92,81,83,89,71,61,74,95,88,100,CNT EQU$-SCORE,G6 DB?,G7 DB?,G8 DB?,G9 DB?,G10 DB?,DATA ENDS,CODE SEGMENT,ASSUME CS:CODE,D
展开阅读全文