汇编语言程序设计(第二版)(清华大学IBM-PC 汇编语言程序设计(第二版)沈美明温冬婵编著)第二章1、答:直接由指令指定的I/O端口数为256个。
2、答:3、答:字节单元:(30022H)= AB H,(30024H)= EF H字单元:(30021H)= AB34 H,(30022H)= CDAB H。
4、答:3017:000A的存储单元的物理地址是3017AH,3015:002A的存储单元的物理地址是3017AH,3010:007A的存储单元的物理地址是3017AH。
5、答:该程序的第一个字的物理地址是0AAA40H。
6、答:条件标志OF、SF、ZF、CF的值依次分别为0、0、0、0。
7、答:(1)AX、BX、CX、DX、AH、AL、BH、BL、CH、CL、DH、DL、SP、BP、DI、SI(注意:学生尽量不要用SP参与加减运算)(2)CX(3)DX、AX、AH、AL(4)CS、DS、ES、SS(5)FLAGS(6)IP(7)SS、SP、BP8、答:可以用来指示存储器地址的寄存器有BX、SP、BP、DI、SI、IP、CS、DS、ES、SS。
9、答:唯一正确的是D。
第三章2、答:(1)ADD DX, BX(2)ADD AL, [BX][SI](3)ADD [BX+0B2H], CX(4)ADD [0524H], 2A59H(5)ADD AL, 0B5H3、答:(1)MOV BX, OFFSET BLOCK + 0AHMOV DX, [BX](2)MOV BX, 0AHMOV DX, BLOCK[BX](3)MOV BX, OFFSET BLOCKMOV SI, 0AHMOV DX, [BX][SI]4、答:(1)1200H(2)0100H(3)4C2AH(4)3412H(5)4C2AH(6)7856H(7)65B7H6、答:MOV BX, 2000HLES DI, [BX]MOV AX, ES : [DI]7、答:(1)064DH(2)0691H(3)05ECH9、答:(1)MOV AX, [ BX+0CH ]MOV ZERO, AX(2)MOV AX, ARRAY[BX]MOV ZERO, AX10、答:(1)(AX)= 1234H(2)(AX)= 0032H11、答:(AX)= 1E00H12、答:LEA BX, CSTRINGMOV DL, [BX]MOV DH, [BX+6]13、答:14、答:LES BX, [2000]MOV AX, ES:[BX]16、答:(1)74D4H SF=0 ZF=0 CF=0 OF=0 (2)A5C1H SF=1 ZF=0 CF=0 OF=1 (3)3240H SF=0 ZF=0 CF=1 OF=0 (4)0000H SF=0 ZF=1 CF=1 OF=017、答:(1)0C754H SF=1 ZF=0 CF=1 OF=0 (2)12B0H SF=0 ZF=0 CF=0 OF=0 (3)45B0H SF=0 ZF=0 CF=0 OF=1 (4)9F24H SF=1 ZF=0 CF=0 OF=021、答:(1)MOV AX, ZSUB AX, XADD AX, WMOV Z, AX(2)MOV BX, XADD BX, 6MOV CX, RADD CX, 9MOV AX, WSUB AX, BXSUB AX, CXMOV Z, AX(3)MOV AX, W IMUL XMOV BX, YADD BX, 6IDIV BXMOV Z, AXMOV R, DX22、答:NEG DXNEG AXSBB DX, 016、答:MOV AX, AMOV DX, A+2 TEST DX, 8000H JZ STORE ; 为正NEG DXNEG AXSBB DX, 0STORE : MOV B, AX MOV B+2, DX17、答:(1)MOV AL, SSUB AL, 6DASADD AL, VDAAMOV U, AL(2)MOV AL, ZSUB AL, UDASMOV U, ALMOV AL, XADD AL, WDAASUB AL, UDASMOV U, AL23、答:(1)(BX)= 9AH (2)(BX)= 61H (3)(BX)= 0FBH (4)(BX)= 1CH (5)(BX)= 0 (6)(BX)= 0E3H把(DX)(AX)中的双字左移四位(乘以16)。
20、答:MOV CL, 4SHR AX, CLMOV BL, DLSHR DX, CLSHL BL, CLOR AH, BL31、答:(1)CLDMOV CX, 132MOV AL, 20HLEA DI, ARRAYREP STOSB(2)CLDMOV CX, 9MOV AL, ‘*’LEA DI, ADDRREPNE SCASBJNE L1L2 : …… ; 找到L1 : …… ; 未找到(3)CLDMOV CX, 30MOV AL, 20HLEA DI, NAMEREPE SCASBJNE DO_NOTMOV CX, 30MOV AL, ‘$’LEA DI, NAMEREP STOSB…DO_NOT: …(4)CLDMOV CX, 30LEA SI, NAMELEA DI, ARRAYREP MOVSBSTDMOV CX, 9LEA SI, ADDR+8LEA DI, ARRAY+131REP MOVSB34、答:(1)转L1(2)转L1(3)转L2(4)转L5(5)转L536、答:2 p £q 时,(AX)22 p > q 时,(AX)1(1)(AX)= 5 (BX)= 16 (CX)= 0 (DX)= 0(2)(AX)= 2 (BX)= 4 (CX)= 3 (DX)= 1(3)(AX)= 3 (BX)= 7 (CX)= 2 (DX)= 039、答:第四章1、答:(2)源*作数和目的*作数同为存储器寻址方式。
(3)SI、DI同为变址寄存器。
(7)目的*作数不能是代码段段寄存器CS。
(5)缺少PTR5、答:BYTE_VAR 42 59 54 45 0C EE 00 ?? - 01 02 01 02 ?? 00 ?? 01 02 01 02 ?? 00 ?? 01 02 - 01 02 ??WORD_VAR 00 00 01 00 02 00 00 00 - 01 00 02 00 00 00 01 00 02 00 00 00 01 00 02 00 - 00 00 01 00 02 00 ?? ??FB FF 59 42 45 54 56 02 -8、答:PLENTH的值为22(16H)。
12、答:(1)10025(2)25(3)2548(4)3(5)103(6)0FFFFH(7)1(8)35假设数据段中数据定义如下:VAR DW '34'VAR1 DB 100, 'ABCD'VAR2 DD 1COUNT EQU $-VAR1X DW 5 DUP (COUNT DUP (0))Y LABEL WORDZ DB '123456'V DW 2, $-VAR执行下面程序段并回答问题。
MOV AX, COUNT ; (AX) = ?MOV BX, Z-X ; (BX) = ?MOV CX, V+2 ; (CX) = ?MOV DX, VAR ; (DX) = ?MOV Y+3, 2MOV SI, Y+4 ; (SI) = ?ADD Z+5, 1MOV DI, WORD PTR Z+4 ; (DI) = ?、答:(AX)= 9(BX)= 90(CX)= 109(DX)= 3334H(SI)= 3600H(DI)= 3700H14、答:(1)(AX)= 1(2)(AX)= 2(3)(CX)= 20(4)(DX)= 40(5)(CX)= 117、答:D_SEG SEGMENTD_WORD LABEL WORDAUGEND DD 99251S_WORD LABEL WORDSUM DD ?D_SEG ENDSE_SEG SEGMENTE_WORD LABEL WORDADDEND DD -15962E_SEG ENDSC_SEG SEGMENTASSUME CS:C_SEG, DS:D_SEG, ES:E_SEGMAIN PROC FARSTART: PUSH DSMOV AX, 0PUSH AXMOV AX, D_SEGMOV DS, AXMOV AX, E_SEGMOV ES, AXMOV AX, D_WORDMOV BX, D_WORD+2ADD AX, ES:E_WORDADC BX, ES:E_WORD+2MOV S_WORD, AXMOV S_WORD+2, BXRETMAIN ENDPC_SEG ENDSEND START16、答:DATASG SEGMENT AT 0E000HWORD_ARRAY LABEL WORDBYTE_ARRAY DB 100 DUP (?)DATASG ENDSSTACKSG SEGMENT PARA STACK 'STACK'DW 32 DUP (?)TOS LABEL WORDSTACKSG ENDSCODESG SEGMENTORG 1000HMAIN PROC FARASSUME CS:CODESG, DS:DATASG, ES:DATASG, SS:STACKSG START:MOV AX, STACKSGMOV SS, AXMOV SP, OFFSET TOSPUSH DSSUB AX, AXMOV AX, DATASGMOV DS, AXMOV ES, AX……RETMAIN ENDPCODESG ENDSEND START9编写一个完整的程序,要求把含有23H,24H,25H,26H四个字符数据的数据区复制20次。
、答:DSEG SEGMENTVAR1 DB 23H,24H,25H,26HDSEG ENDSESEG SEGMENTVAR2 DB 80 DUP ('?')ESEG ENDSCSEG SEGMENTASSUME CS:CSEG, DS:DSEG, ES:ESEGMAIN PROC FARSTART:PUSH DSMOV AX, 0PUSH AXMOV AX, DSEGMOV DS, AXMOV AX, ESEGMOV ES, AXMOV DX, 20CLDLEA DI, VAR2AGAIN:LEA SI, VAR1MOV CX, 4REP MOVSBDEC DXJNZ AGAINRETMAIN ENDPCSEG ENDSEND START第五章1、答:……mov cx, countlea si, string1lea di, string2again:mov al, [si]mov [di], alinc siinc di2、答:code segment assume cs: code main proc farstart:push dsmov ax, 0push axmov ah, 1int 21hsub al, 30hcmp al, 0jz exitmov cl, almov ch, 0again:mov ah, 2mov dl, 7int 21hloop againexit:retmain endpcode endsend start……8、答:MOV CX,8MOV DL,0NEXT3:ROR AX,1 JNC NEXT1ROR AX,1JNC NEXT2INC DLNEXT2:LOOP NEXT3 ADD DL, 30HMOV AH, 2INT 21HMOV AH, 4CHINT 21HNEXT1:ROR AX, 1 JMP NEXT212、答:……mov cx, 100lea di, memmov ax, 0cldcomp:repne scaswjcxz exitpush cxmov si, disub di, 2mov bx, direp movswmov word ptr [di], 0mov di, bxpop cxjmp compexit:……13、答:……mov dx, 100mov si, 0repeat:mov al, string[si]cmp al, 30hjb gooncmp al, 39hja goonor cl, 20h ; (cl)51jmp exitgoon:inc sidec dxjnz repeatand cl, 0dfh ; (cl)50exit:……14、答:……table dw 100h dup (?)mdata dw ? ; 存放出现次数最多的数count dw 0 ; 存放出现次数……mov bx, 100hmov di, 0 ; di为数组TABLE的指针next:mov dx, 0mov si, 0mov ax, table[di]mov cx, 100hcomp:cmp table[si], axjne addrinc dxaddr:add si, 2loop compcmp dx, countjle changmov count, dxmov mdata, axchang:add di, 2dec bxjnz nextmov cx, countmov ax, mdata……19、答:……a dw 15 dup (?)b dw 20 dup (?)c dw 15 dup (?)……mov si, 0 ; si为数组A的指针mov bx, 0 ; bx为数组C的指针mov cx, 15loop1:mov di, 0 ; di为数组B的指针push cxmov cx, 20mov ax, a[si]loop2:cmp b[di], axjne nomov c[bx], axadd bx, 2jmp nextno:add di, 2loop loop2next:add si, 2pop cxloop loop121、答:……mov dx, 0lea si, arraymov ax, [si]mov bx, [si+2]cmp ax, bxjne next1inc dxnext1:cmp [si+4], axjne next2inc dxnext2:cmp [si+4], bxjne numinc dxnum:cmp dx, 3jl dispdec dxdisp:mov ah, 2add dl, 30hint 21h……第六章2、答:2、答:(1) NAME1 NAMELIST < >(2) MOV AX,DATA ;假设结构变量NAME1定义在数据段DATA中MOV DS,AXMOV ES,AX;MOV AH,10LEA DX,NAME1INT 21H;MOV CL,NAME1.ACTLENMOV CH,0LEA SI,INLEA DI,DISPFILECLDREP MOVSB6、答:SKIPLINES PROC NEARPUSH CXPUSH DXMOV CX,AXNEXT:MOV AH,2MOV DL,0AHINT 21HMOV AH,2MOV DL,0DHINT 21HLOOP NEXTPOP DXPOP CXRETSKIPLINES ENDP7、答:dseg segmentnum dw 76,69,84,90,73,88,99,63,100,80 n dw 10s6 dw 0s7 dw 0s8 dw 0s9 dw 0s10 dw 0dseg endscode segmentmain proc farassume cs:code, ds:dsegstart:push dssub ax, axpush axmov ax, dsegmov ds, axcall sub1retmain endpsub1 proc nearpush axpush bxpush cxpush simov si, 0mov cx, nnext:mov ax, num[si]mov bx, 10div blmov bl, alcbwsub bx, 6sal bx, 1inc s6[bx]add si,2loop nextpop sipop cxpop bxpop axretsub1 endpcode endsend start8、答:data segmentmaxlen db 40n db ?table db 40 dup (?)char db 'a' ; 查找字符’a’evenaddr dw 3 dup (?)data endscode segmentassume cs:code, ds:datamain proc farstart:push dsmov ax, 0push axmov ax, datamov ds, axlea dx, maxlenmov ah, 0ahint 21h ; 从键盘接收字符串mov addr, offset tablemov addr+2, offset nmov addr+4, offset charmov bx, offset addr ; 通过地址表传送变量地址call count ; 计算CHAR的出现次数call display ; 显示retmain endpcount proc near ; count子程序push sipush dipush axpush cxmov di, [bx]mov si, [bx+2]mov cl, byte ptr[si]mov si, [bx+4]mov al, byte ptr[si]mov bx, 0again:cmp al, byte ptr[di]jne l1inc bxl1: inc diloop againpop cxpop axpop dipop siretcount endpdisplay proc near ; display子程序call crlf ; 显示回车和换行mov dl, charmov ah, 2int 21hmov dl, 20hmov ah, 2int 21hmov al, bland al, 0fhadd al, 30hcmp al, 3ahjl printadd al, 7print:mov dl, alint 21hcall crlfretdisplay endpcrlf proc near ; crlf子程序mov dl, 0dhmov ah, 2int 21hmov dl, 0ahmov ah, 2int 21hretcrlf endpcode endsend start第七章1、答:CLRB MACRO N, ARRAYCLDMOV CX, NMOV AL, 20HLEA DI, ARRAYENDM2、答:WAGES MACRO RATE,HOUR MOV AL,RATEMOV BL,HOURMUL BL ;计算周工资;ADD AX,AXADD AX,AX ;一个月有4周MOV WAG,AX ;暂存中间结果ADD BL,BLADD BL,BL ;计算月出工小时数MOV AL,BLMOV AH,0MOV BL,10DIV BLMOV BL,3MUL BL ;计算奖金ADD WAG,AX ;计算工资总数ENDM宏展开:1 MOV AL,R11 MOV BL,421 MUL BL1 ADD AX,AX1 ADD AX,AX1 MOV WAG,AX1 ADD BL,BL1 ADD BL,BL1 MOV AL,BL1 MOV AH,01 MOV BL,101 DIV BL1 MOV BL,31 MUL BL1 ADD WAG,AX3、答:(1) 调用有效1 PUSH AX2 MOV AX, P12 SUB AX, P21 CMP AX, 01 JGE ??00001 NEG AX1 ??0000: MOV DISTANCE, AX1 POP AX(2) 调用有效1 PUSH AX2 MOV AX, [BX]2 SUB AX, [SI]1 CMP AX, 01 JGE ??00011 NEG AX1 ??0001: MOV X[DI], AX1 POP AX(3) 调用无效,有错误指令1 ??0002: MOV 240H, AX(4) 调用有效,但无意义宏展开略。