΢»úÔ­ÀíÏ° Ìâ 2 ÏÂÔر¾ÎÄ

Ï° Ìâ 2

2.1 8086/8088 CPU·ÖΪÄÄÁ½´ó¹¦Äܲ¿¼þ£¿Æä¸÷×ÔµÄÖ÷Òª¹¦ÄÜÊÇʲô£¿8086/8088 CPU

ÖÐÓÐÄÄЩ¼Ä´æÆ÷£¿¸÷ÓÐʲôÓÃ;£¿

½â£º´Ó¹¦ÄÜÉÏÀ´¿´£¬Intel 8086/8088΢´¦ÀíÆ÷¿É·ÖΪÁ½²¿·Ö£¬¼´Ö´Ðе¥ÔªEU(Execution Unit) ºÍ×ÜÏß½Ó¿Úµ¥ÔªBIU(Bus Interface Unit)¡£

Ö´Ðе¥ÔªEU µÄ¹¦ÄÜÊǸºÔðÖ¸ÁîµÄÒëÂë¡¢Ö´ÐУ¬°üÀ¨ËãÊõ¡¢Âß¼­ÔËË㣬¿ØÖƵȡ£×ÜÏß½Ó¿Úµ¥ÔªBIU µÄ¹¦ÄÜÊǸºÔð8086/8088¶Ô´æ´¢Æ÷ºÍI/O É豸µÄËùÓзÃÎʲÙ×÷¡£¾ßÌå°üÀ¨£º¸ºÔð´ÓÄÚ´æµ¥ÔªÖÐԤȡָÁ²¢½«ÆäË͵½Ö¸Áî¶ÓÁлº³åÆ÷Ôݴ棻´ÓÄÚ´æµ¥Ôª»òÍâÉè¶Ë¿ÚÖжÁÈ¡²Ù×÷Êý»òÕß½«Ö¸ÁîµÄÖ´Ðнá¹û´«Ë͵½Ö¸¶¨µÄÄÚ´æµ¥Ôª»òÍâÉè¶Ë¿Ú£»¸ù¾ÝÓÐЧµØÖ·£¨EA£©ÐγÉÎïÀíµØÖ·£¨PA£©¡£

8086/8088ÓÐ4¸ö16λÊý¾Ý¼Ä´æÆ÷£ºAX¡¢BX£¬CX£¬DX£¬ËüÃǼȿÉ×÷Ϊ16λ¼Ä´æÆ÷ʹÓ㬴æ·ÅÊý¾Ý»òµØÖ·£¬Ò²¿ÉÒÔ·Ö±ð×÷ΪÁ½¸ö 8 λ¼Ä´æÆ÷ʹÓá£

8086/8088ÓÐ2¸ö16λ±äÖ·¼Ä´æÆ÷£ºSI ¡¢DI£¬Í¨³£ÓëDSÁªÓã¬Îª·ÃÎʵ±Ç°Êý¾Ý¶ÎÌṩ¶ÎÄÚÆ«ÒƵØÖ·»òÆ«ÒƵØÖ··ÖÁ¿¡£

8086/8088ÓÐ2¸ö16λµØÖ·Ö¸Õë¼Ä´æÆ÷£ºSP£¬BP£¬ËüÃÇÒ»°ãÊÇÓÃÀ´´æ·Å¶ÑÕ»²Ù×÷ÊýµÄÆ«ÒƵØÖ·¡£

×ÜÏß½Ó¿Úµ¥Ôª(BIU) ÖÐÉèÖÃÓÐ4 ¸ö16λµÄ¶Î¼Ä´æÆ÷£¬·Ö±ðÊÇ´úÂë¶Î¼Ä´æÆ÷(CS)£¬Êý¾Ý¶Î¼Ä´æÆ÷(DS)£¬¶ÑÕ»¶Î¼Ä´æÆ÷(SS)ºÍ¸½¼Ó¶Î¼Ä´æÆ÷(ES)¡£

Ö¸ÁîÖ¸Õë¼Ä´æÆ÷ (Instruction Pointer£¬IP) ÓÃÀ´´æ·ÅÏÂÒ»ÌõÒªÖ´ÐеÄÖ¸ÁîÔÚµ±Ç°´úÂë¶ÎÖеÄÆ«ÒƵØÖ·¡£

±êÖ¾¼Ä´æÆ÷Ò²³Æ³ÌÐò״̬×Ö(PSW) ¼Ä´æÆ÷£¬ÓÃÀ´´æ·ÅÔËËã½á¹ûµÄÌØÕ÷ºÍ»úÆ÷¹¤×÷״̬¡£

2.2 8086/8088 CPUÖбêÖ¾¼Ä´æÆ÷ÓÐÄÄÁ½Àà±êÖ¾£¿¼òÊö¸÷±ê־λµÄº¬Òå¡£

½â£º¢Ù(Zero Flag £¬ZF)¡ª¡ªÁã±êÖ¾¡£Èô±¾´ÎÔËËã½á¹ûΪ0£¬ÔòZF£½1£¬·ñÔòZF£½0¡£ ¢Ú(Sign F1ag SF)¡ª¡ª·ûºÅ±êÖ¾¡£´Ë±êÖ¾ÓÃÓÚ·´Ó³ÓзûºÅÊýÔËËã½á¹ûµÄ·ûºÅÊÇÕý»¹ÊǸº¡£¶ÔÓÚÓзûºÅÊý£¬ÓÃ×î¸ßλ±íʾÊýµÄ·ûºÅ£¬µ±±¾´ÎÔËËã½á¹û×î¸ßλΪ1 £¬±íʾ½á¹ûΪ¸ºÊý£¬ÔòSF£½1£¬·ñÔòSF£½0¡£

¢Û(Parity Flag£¬PF)¡ª¡ªÆæż±êÖ¾¡£´Ë±êÖ¾ÊÇ·´Ó³ÔËËã½á¹ûÖÐ×îµÍ×Ö½ÚÖк¬¡°1¡±µÄ¸öÊýΪ0»òżÊýʱ£¬PF£½1£¬ÎªÆæÊýʱ£¬PF£½0¡£ ×¢Ò⣬PF±êÖ¾½ö·´Ó³ÔËËã½á¹ûµÄ×îµÍ8λÖС°1¡±µÄ¸öÊýÊÇżÊý»òÆæÊý£¬¼´Ê¹ÊǽøÐÐ16λ×Ö²Ù×÷Ò²ÊÇÈç´Ë¡£

¢Ü(Auxiliary Carry Flag £¬AF)¡ª¡ª¸¨Öú½øλ±êÖ¾¡£µ±½øÐÐ8 λÊý( ×Ö½Ú)»ò16λÊý( ×Ö)µÄµÍ8 λÔËËãʱ£¬µÍ4 λÏò¸ß4 λ( ¼´D3 λÏòD4 λ) Óнøλ»ò½èλʱ£¬AF£½1£¬

1

·ñÔòAF£½0¡£AF±êÖ¾Ö÷Òª¹© BCDÂëÊ®½øÖÆËãÊõÖ¸ÁîÅбðÊÇ·ñÒª½øÐÐÊ®½øÖƵ÷Õû£¬Óû§Ò»°ã²»±Ø¹ØÐÄ¡£

¢Ý(Carry Flag£¬CF)¡ª¡ª½øλ±êÖ¾¡£µ±±¾´ÎËãÊõÔËËã½á¹ûʹ×î¸ßλ²úÉú½øλ( ¼Ó·¨ÔËËã)»ò½èλ( ¼õ·¨ÔËËã) ʱ£¬Ôò´Ë±ê־λÖá°1¡±£¬¼´CF£½1£»Èô¼Ó·¨ÔËËã½á¹û×î¸ßλÎÞ½ø룬»ò¼õ·¨ÔËËã½á¹û×î¸ßλÎÞ½è룬ÔòCF£½0¡£

¢Þ(Overflow Flag £¬OF)¡ª¡ªÒç³ö±êÖ¾¡£µ±ÔËËã½á¹û²úÉúÒç³öʱ£¬Ê¹OF£½1£¬·ñÔòOF£½0¡£

2.3 ¼òÊöαָÁî¡°EQU¡±Óë¡°=¡±Ö®¼äÓÐʲôÇø±ð£¿

½â£º¡°EQU¡±Î±Ö¸Áî²»ÄÜÖظ´¶¨Ò壬¶ø¡°=¡±Î±Ö¸Áî¿ÉÒÔÖظ´¶¨Òå¡£

2.4 »­Í¼ËµÃ÷ÏÂÁÐÓï¾ä·ÖÅäµÄ´æ´¢¿Õ¼ä¼°³õʼ»¯µÄÊýÖµ

£¨1£©FF1 DB '0100',2+5,?,'ABC'

£¨2£©FF2 DW 2 DUP(?),'A','BC',1000H,25H £¨3£©FF3

DB 2 DUP(1,2 DUP(2,3),4)

Æ«ÒƵØÖ· ÄÚÈÝ ±äÁ¿Ãû 0000H 30H FF1 0001H 31H 0002H 30H 0003H 30H 0004H 07H 0005H 00H 0006H 41H 0007H 42H 0008H 43H 0009H 00H FF2 000AH 00H 000BH 00H 000CH 00H 000DH 41H 000EH 00H 000FH 43H 2

0010H 0011H 0012H 0013H 0014H 0015H 42H 00H 10H 25H 00H 01H FF3 0016H 02H 0017H 03H 0018H 02H 0019H 03H 001AH 04H 001BH 01H 001CH 02H 001DH 03H 001EH 02H 001FH 03H 0020H 04H

2.5 Ö¸³öÏÂÁÐÖ¸ÁîµÄ´íÎó¡£

A1 DB £¿ A2 DB 10

K1 EQU 1024

£¨1£©MOV K1£¬AX £¨2£©MOV A1£¬AX £¨3£©CMP A1£¬A2 £¨4£©K1 EQU 2048 £¨5£©MOV AX£¬BH £¨6£©MOV [BP]£¬[DI] £¨7£©XCHG CS£¬AX

£¨8£©POP CS

½â£º

£¨1£© Á¢¼´Êý²»ÄÜΪĿµÄ²Ù×÷Êý

£¨2£© Á½¸ö²Ù×÷ÊýµÄÀàÐͲ»Ò»ÖÂ

£¨3£© Á½¸ö²Ù×÷Êý²»ÄÜͬʱΪ´æ´¢Æ÷²Ù×÷Êý £¨4£© K1²»ÄÜÓÃEQUÖظ´¶¨Òå £¨5£© Á½¸ö²Ù×÷ÊýÀàÐͲ»Æ¥Åä

£¨6£© Á½¸ö²Ù×÷Êý²»ÄÜͬʱΪ´æ´¢Æ÷²Ù×÷Êý £¨7£© CS²»ÄÜ×÷ΪXCHGµÄ²Ù×÷Êý

3

£¨8£© CS²»ÄÜΪĿµÄ²Ù×÷Êý

2.6 ¼ÙÉèÔÚÊý¾Ý¶Î½øÐÐÈçϵĶ¨Ò壺

DATA

Segment

XX DB -50,71,5,65,0 YY DB 200 DUP('ABCD') ZZ DW 100 DUP(?)

WW DW 25H,1052H,370H,851H

ENDS

DATA

£¨1£©ÓÃÒ»ÌõÖ¸ÁYYµÄÆ«ÒƵØÖ·ËÍÈëBX £¨2£©ÓÃÒ»ÌõαָÁî¸ø³ö¸ÃÊý¾Ý¶ÎÕ¼ÓÃËùÓÐ×Ö½Ú³¤¶È £¨3£©ÓÃÒ»ÌõαָÁî¸ø³ö±äÁ¿ZZ·ÖÅäµÄ×Ö½ÚÊýÄ¿

£¨4£©±àдһ¶Î³ÌÐò½«WWÊý×éÖеÄÊý¾ÝÈ«²¿ËÍÈëYY»º³åÇø £¨5£©½«Êý×éXXÖеĵڶþ¸öÊý¾ÝÓëµÚÎå¸öÊý¾Ý½øÐе÷»» ½â£º£¨1£©LEA BX, YY

£¨2£©ÔÚÊý¾Ý¶ÎµÄ×îºó¼ÓÉÏ£ºLEN EQU $-XX £¨3£©ZZLEN EQU WW-ZZ £¨4£©MOV AX,WW

MOV YY,AX

MOV AX,WW+2 MOV YY+2,AX MOV AX,WW+4 MOV YY+4,AX MOV AX,WW+6 MOV YY+6,AX £¨5£©MOV AL,XX+1 MOV XX+4,AL

2.7 ʲô½ÐÑ°Ö··½Ê½£¿8086/8088Ö¸ÁîϵͳÓÐÄÄЩѰַ·½Ê½£¿ ½â£ºÖ¸ÁîÖвÙ×÷ÊýµÄÑ°ÕÒ·½·¨³ÆΪѰַ·½Ê½¡£

8086/8088ϵͳËùÖ§³ÖµÄÆßÖÖ»ù±¾Ñ°Ö··½Ê½£ºÁ¢¼´Ñ°Ö·£¬ ¼Ä´æÆ÷Ñ°Ö·£¬ Ö±½ÓÑ°Ö·£¬ ¼Ä´æÆ÷¼ä½ÓÑ°Ö·£¬¼Ä´æÆ÷Ïà¶ÔÑ°Ö·£¬»ùÖ·±äÖ·Ñ°Ö·ºÍÏà¶Ô»ùÖ·±äÖ·Ñ°Ö·¡£

2.8 ½«Ê×µØַΪBLOCKµÄ×ÖÊý×éÖеĵÚ100¸öÊýËÍÈëAXÖУ¬ÊÔд³öÏà¹ØÖ¸ÁîÐòÁУ¬

ÒªÇó·Ö±ðʹÓÃÒÔÏÂÈýÖÖÑ°Ö··½Ê½£º

4

£¨1£©ÒÔBX¼Ä´æÆ÷µÄ¼ä½ÓÑ°Ö· £¨2£©ÒÔBX¼Ä´æÆ÷µÄÏà¶ÔÑ°Ö· £¨3£©ÒÔBX¡¢SI¼Ä´æÆ÷µÄ»ùÖ·±äÖ·Ñ°Ö· ½â£º£¨1£©MOV BX, OFFSET BLOCK +99*2

MOV AX, [BX] £¨2£©MOV BX, 99*2 MOV AX, BLOCK[BX]

»ò£º

LEA BX, BLOCK MOV AX, [BX+99*2]

£¨3£©LEA BX, BLOCK MOV SI, 99*2

MOV AX,[BX+SI] »ò£º

LEA SI, BLOCK MOV BX, 99*2 MOV AX,[BX+SI]

2.9 ÒÑÖª£º£¨BX£©=1200H£¬£¨BP£©=2400H£¬£¨SI£©=0100H£¬£¨DI£©=0200H£¬£¨SS£©=1000H£¬

£¨DS£©=2000H£¬£¨ES£©=3000H£¬±äÁ¿VAR1¶ÔÓ¦µØַΪ2000H£¬ÊÔ·Ö±ðÖ¸³öÏÂÁÐ

Ö¸ÁîÖд洢Æ÷µÄÑ°Ö··½Ê½¼°ÎïÀíµØÖ·¡£ (1)MOV AL,[020H] (2)MOV AL,[BP+010H] (3)MOV [BX+SI-20H],AX (4)MOV BL,ES:[BX+10H] (5)MOV VAR1[BX+DI],AL

½â£º£¨1£©Ö±½ÓÑ°Ö· PA=£¨DS£©*16+EA=20000h+020H=20020H

£¨2£©¼Ä´æÆ÷Ïà¶ÔÑ°Ö·PA=£¨SS£©*16+EA=10000H+2400H+010H=12410H

£¨3£©Ïà¶Ô»ùÖ·¼Ó±äÖ·Ñ°Ö·PA=£¨DS£©*16+EA=20000H+1200H+0100H-20H=212E0H £¨4£©¼Ä´æÆ÷Ïà¶ÔÑ°Ö·PA=£¨ES£©*16+EA=30000H+1200H+10H=31210H

£¨5£©Ïà¶Ô»ùÖ·¼Ó±äÖ·Ñ°Ö·PA=£¨DS£©*16+EA=20000H+2000H+1200H+0200H=23400H

2.10 ÉèBlockΪ×Öµ¥Ôª1000H:001FHµÄ·ûºÅµØÖ·£¨±äÁ¿£©£¬¸Ãµ¥ÔªµÄÄÚÈÝÊÇ01A1H£¬ÊÔ

ÎÊÒÔÏÂÁ½Ìõº¬ÓÐBlockµÄÖ¸ÁîÓÐʲô²»Í¬£¿Ö¸ÁîÖ´ÐкóBXµÄÄÚÈÝÊǶàÉÙ£¿ £¨1£©MOV

BX£¬Block

5

£¨2£©LEA

BX£¬Block

½â£º£¨1£©BXµÄÄÚÈÝΪ01A1H

£¨2£©BXµÄÄÚÈÝΪ001FH

2.11 ʲô½Ð¶ÑÕ»£¿²ÉÓöÑÕ»µÄÒâÒ壿 ½â£º

2.12 ÈôÔÚÊý¾Ý¶ÎÖдÓ×Ö½Ú±äÁ¿TABLEÏàÓ¦µÄµ¥Ôª¿ªÊ¼´æ·ÅÁË0~15µÄƽ·½Öµ£¬ÊÔд³ö°ü

º¬ÓÐXLATÖ¸ÁîµÄÖ¸ÁîÐòÁвéÕÒN£¨0~15£©ÖеÄij¸öÊýµÄƽ·½¡£(ÉèNµÄÖµ´æ·ÅÔÚCLÖÐ)

½â£º LEA BX, TABLE

2.13 ±àд³ÌÐò¶Ô´æ·ÅÔÚDX£¬AXÖеÄË«×Ö½Ú³¤Êý¾ÝµÄÇó²¹ ½â£ºNOT

NOT ADD

ADC

2.14 д³öʵÏÖÏÂÁмÆËãµÄÖ¸ÁîÐòÁС££¨¼Ù¶¨X¡¢Y¡¢Z¡¢W¡¢R¶¼ÎªÓзûºÅÊý×Ö±äÁ¿£©

£¨1£©Z=£¨W*X£©/£¨R+6£© £¨3£©Z= (X+Y)/R - W ½â£º

£¨1£©

MOV

IMUL MOV ADD IDIV MOV MOV

£¨2£©

MOV

MOV IMUL

AX, W X BX, R BX, 6 BX Z, AX R, DX AX, Y BX, 5 BX

6

£¨2£©Z=£¨£¨W-X£©/£¨5*Y£©£©*2 £¨4£©Z= (X/Y+ W )*100+R

DX AX AX, 1

DX, 0

£»×îµÍλ¼Ó1£¬×¢Ò⣺²»ÄÜÓÃINCÖ¸Áî £»°Ñ½ø루Èç¹ûÓУ©´«µÝµ½¸ßλ £»Ê×ÏȽ«£¨DX, AX£©È¡·´

MOV AL, N XLAT

MOV MOV SUB MOV IMUL IDIV MOV

BX, AX AX, W AX, X CX, 2 CX BX Z, AX

£¨3£©

MOV AX, X

ADD AX,Y CWD IDIV SUB MOV MOV CWD IDIV ADD MOV IMUL MOV MOV MOV CWD ADD ADC

AX,BX DX,CX R AX,W Z,AX AX,X Y AX,W BX,100 BX BX,AX CX,DX AX,R

£¨4£©

;½á¹û´æ·ÅÔÚDX¡¢AXÖÐ

2.15 ÉèÔÚAX¡¢BX¡¢CX¡¢DXÖоù´æ·ÅµÄÊÇÓÃѹËõµÄBCDÂë±íʾµÄ4λʮ½øÖÆÊý£¬ÊÔ

±àд³ÌÐòÍê³ÉÒÔϵļÆË㣺 (1)(AX)+(BX) ¡úAX (2)(DX)-(CX) ¡úDX ½â£º£¨1£©ADD AL, BL

DAA

ADC AL, BH

7

XCHG AL, AH

DAA

XCHG AL, AH £¨2£©MOV AL,DL

SUB AL, CL

DAS

MOV DL, AL MOV AL, DH SBB AL, CH DAS

MOV DH, AL

2.16 ¼òÊöÖ¸ÁîµÄ¡°DAA¡±ºÍ¡°DAS¡±¶ÔBCDÂëÔËËãºó½øÐе÷ÕûµÄ¹æÔò¡£½â£ºDAAµÄµ÷Õû¹æÔò£º

if £¨ALµÍ4λ>9 »ò AF=1£©then AL=AL+06H ; AF=1 ; endif

if £¨AL¸ß4λ>9 »ò CF=1£©then AL=AL+60H ; CF=1 ; endif

DASµÄµ÷Õû¹æÔò£º

if £¨ALµÍ4λ>9 »ò AF=1£©then AL=AL£­06H ; AF=1 ; endif

if £¨AL¸ß4λ>9 »ò CF=1£©then AL=AL£­60H ; CF=1 ; Endif

2.17 ÓóÌÐò¶ÎʵÏÖ¶Ô´æÈëÔÚBX£¬AXµÄË«×Ö½øÐÐ×óÒÆ5λ¡£ ½â£º

SHL

AX,1

8

RCL SHL RCL SHL RCL SHL RCL SHL RCL

BX,1 AX,1 BX,1 AX,1 BX,1 AX,1 BX,1 AX,1 BX,1

2.18 ÊÔ·ÖÎöÏÂÁгÌÐòÍê³Éʲô¹¦ÄÜ£¿

MOV SHL MOV SHL SHR OR

CL£¬4 DX£¬CL BL£¬AH AX,CL BL£¬CL DL£¬BL

½â£º°Ñ32λ¶þ½øÖÆ´úÂ루DX, AX£©ÁªºÏ×óÒÆ4λ¡£

2.19 ÒÑÖª³ÌÐò¶ÎÈçÏ£º

MOV AX£¬1234H MOV CL£¬4 ROL AX£¬CL DEC AX MOV CX£¬4 MUL CX

ÊÔÎÊ£º£¨1£©Ã¿ÌõÖ¸ÁîÖ´Ðкó£¬AX¼Ä´æÆ÷µÄÄÚÈÝÊÇʲô£¿ £¨2£©Ã¿ÌõÖ¸ÁîÖ´Ðкó£¬CF£¬SF¼°ZFµÄÖµ·Ö±ðÊÇʲô£¿ £¨3£©³ÌÐòÔËÐнáÊøʱ£¬AX¼°DX¼Ä´æÆ÷µÄֵΪ¶àÉÙ£¿ ½â£º

MOV MOV ROL DEC MOV MUL

AX£¬1234H CL£¬4 AX£¬CL AX CX

CX£¬4

£»AXÄÚÈÝΪ1234H£¬CF¡¢SF¡¢ZFµÄÖµ±£Áô³õÖµ £»AXÄÚÈÝΪ1234H£¬CF¡¢SF¡¢ZFͬÉÏ £»AXÄÚÈÝΪ2341H£¬CF=1¡¢SF=0¡¢ZF=0 £»AXÄÚÈÝΪ2340H£¬CF=1¡¢SF=0¡¢ZF=0 £»AXÄÚÈÝΪ2340H£¬CF=1¡¢SF=0¡¢ZF=0 £»AXÄÚÈÝΪ8D00H£¬CF=0¡¢SF=0¡¢ZF=0

9

2.20 ³ÌÐòÖеġ°×ªÒÆ¡±ÊǸöʲô¸ÅÄCPUÖ´ÐÐתÒÆÖ¸ÁîÊÇÈçºÎʵÏÖתÒƵģ¿ ½â£º³ÌÐòÖеġ°×ªÒÆ¡±ÊÇÖ¸¸Ä±ä³ÌÐòµÄ˳ÐòÖ´Ðйý³Ì£¬Ä³ÌõÖ¸ÁîÖ´ÐÐÍêºó£¬²»Êǽô½Ó×ÅÖ´ÐиÃÖ¸ÁîºóÃæµÄÖ¸Á¶øÊÇÖ´ÐÐÆäËüµÄÖ¸Áî¡£CPUÊÇͨ¹ý¸Ä±äCSºÍIPÖ¸ÁîÖ¸ÕëµÄÖµÀ´ÊµÏÖתÒƵġ£

2.21 É裨DS£©=2000H£¬£¨BX£©=0030H£¬£¨SI£©=0202H£¬£¨20232H£©=00H£¬£¨200233H£©

=06H£¬·Ö±ðÖ´ÐÐÏÂÊöÁ½ÌõÖ¸Áîºó£¬Êµ¼ÊתÒƵÄÄ¿±êµØÖ·ÎïÀíµØÖ·¶àÉÙ£¿ £¨1£©JMP £¨2£©JMP

BX

Word PTR[BX+SI]

½â£º(1)Ä¿µÄµØַΪ0030H

(2)תÒƵÄÄ¿±êµØַΪ£ºÓÉ[BX+SI]Ñ°Ö·µÃ´æ´¢µ¥ÔªµÄµØַΪ20232H£¬Ä¿µÄµØַΪ0600H¡£

2.22 ±àдָÁîÐòÁУ¬ÊµÏÖÏÂÊöÒªÇó

(1) ʹAX¼Ä´æÆ÷µÄµÍ 4 λÇåÁ㣬ÆäÓàλ²»±ä¡£ (2) ʹBX¼Ä´æÆ÷µÄµÍ4 λÖÃ1£¬ÆäÓàλ²»±ä¡£

(3) ²âÊÔ BXÖеÄλ0 ºÍλ4£¬µ±ÕâÁ½Î»Í¬Ê±ÎªÁãʱ£¬½«ALÖÃ1£¬·ñÔòALÖÃ0¡£ ½â£º£¨1£©AND AX, 0FFF0H

£¨2£©OR

JZ

AX, 000FH NEXT

;ZF=1£¬±íÃ÷ÕâÁ½Î»Í¬Ê±Îª0£¬×ª×ß½«ALÖÃ1 ;ZF=0£¬±íÃ÷ÕâÁ½Î»²»Í¬Ê±Îª0£¬½«ALÇå0

£¨3£©TEST AX, 0011H

MOV AL,0 JMP EXIT

NEXT: MOV AL,1 EXIT:

2.23 ÏÂÃæ³ÌÐò¶ÎÔÚʲôÇé¿öÏÂÖ´Ðнá¹ûÊÇ(AH)=0£¿

BEGIN: IN AL, 60H

TEST AL, 80H JZ BRCH1 XOR AX, AX JMP STOP

BRCH1: MOV AH, 0FFH

10

STOP: ??

½â£º´Ó60H¶Ë¿Ú¶Áµ½ÊÇÊý¾Ý×î¸ßλΪ1ʱ£¬Ê¹£¨AH£©Îª0£»Êý¾Ý×î¸ßλΪ0ʱ£¬Ê¹£¨AH£©Îª0FFH¡£

2.24 ¡°CALL¡±Ö¸ÁîÓë¡°JMP¡±Ö¸ÁîÏà֮ͬ´¦ÊÇʲô£¿²»Í¬Ö®´¦ÊÇʲô£¿

½â£ºÏà֮ͬ´¦£º¡°CALL¡±Ö¸ÁîºÍ¡°JMP¡±Ö¸ÁÄÜʵÏÖ³ÌÐòµÄ¿ØÖÆתÒÆ£¬¸Ä±ä³ÌÐò˳ÐòÖ¸ÁîµÄ¹ý³Ì¡£

²»Í¬Ö®´¦£º¡°CALL¡±Ö¸ÁîÖ´ÐÐʱ£¬Ê¹³ÌÐòתÒƵ½×Ó³ÌÐòÖÐÖ´ÐУ¬Ö´ÐÐÍê×Ó³ÌÐòºó£¬»¹ÊÇ»á»Øµ½µ÷ÓóÌÐò£¬¼ÌÐøÖ´Ðнô¸úÔÚ¡°CALL¡±Ö¸ÁîÖ®ºóµÄÄÇÌõÖ¸Áî¡£µ«¡°JMP¡±Ö¸ÁîÖ´ÐÐÍêºóÒ»°ã²»»áÈ¥Ö´Ðнô¸úÔÚ¡°JMP¡±Ö¸ÁîÖ®ºóµÄÄÇÌõÖ¸Áî¡£

2.25 ÐðÊö8086/8088CPUÖ´ÐÐÖ¸Áî¡°CALL DWORD PTR[100H]¡±µÄ²½Öè¡£

2.26 ÉèÏÂÁгÌÐòÖ´ÐÐÇ°£¬Õ»¶¥Ö¸ÕëSS:SPΪ1000H:0220H£¬ÊÔÇó£º

POP CX POP BX POP AX RET 4

£¨1£© »­³ö¸Ã³ÌÐòÖ´ÐкóµÄ¶ÑÕ»´æ´¢Çé¿öʾÒâͼ¡£ ½â£ºÊ¹¶ÑÕ»Ö¸Õë¼Ó10£¬ÉÏÃæµÄ5¸ö×ÖµÄÄÚÈݳöÕ»£¬Í¼ÂÔ¡£ £¨2£© ¸ø³öµ±Ç°Õ»¶¥SSºÍSPµÄÖµ¡£

£¨SS£©=1000H£¬ £¨SP£©=022AH

2.27 һ˫×Ö³¤µÄ´ø·ûºÅÊý·ÅÔÚXºÍX+2ÖУ¨XΪ±äÁ¿£©£¬ÊÔ±àдһ³ÌÐò¶ÔÕâ¸öÊýÇóÆä¾ø

¶ÔÖµ¡£ ½â£º

TEST [X+2], 8000H ;²âÊÔ×î¸ß룬ÅжÏÕý¸º£¬¸ºÊýºÃÈ¡¾ø¶ÔÖµ JZ MOV MOV NOT NOT ADD ADC

DONE AX, X DX, [X+2] AX DX AX, 1 DX, 0

11

MOV MOV

[X], AX [X+2], DX

DONE:

2.28 ÊÔ±àдһ¸ö»ã±àÓïÑÔ³ÌÐò£¬ÒªÇ󽫼üÅÌÊäÈëµÄСд×ÖĸÓôóд×ÖĸÏÔʾ³öÀ´¡£ ½â£ºCODE SEGMENT

2.29 ÊÔ±àд³ÌÐòʵÏÖ´íÎó£¡Î´ÕÒµ½ÒýÓÃÔ´¡£µÄ¹¦ÄÜ£¬µ«ÊDz»ÒªÊ¹ÓÃ×Ö·û´®²Ù×÷Ö¸Áî¡£ ½â£º

LEA LEA INC INC MOV CMP

SI, STRING1-1

DI, STRING2-1 SI DI AL, [SI] AL, ES:[DI]

ASSUME

MOV INT CMP JZ OR INT JMP INT END

CS: CODE AH, 01H 21H

AL, 0DH ;ÊäÈë»Ø³µÍƳö³ÌÐò EXIT AL, 20H 21H START 21H START

START:

MOV AH, 02H

EXIT: MOV AX, 4C00H

CODE ENDS

MOV CX, 20

AGA:

LOOPZ AGA

2.30 ÊÔ±àд³ÌÐòʵÏÖ´íÎó£¡Î´ÕÒµ½ÒýÓÃÔ´¡£µÄ¹¦ÄÜ£¬µ«ÊDz»ÒªÊ¹ÓÃ×Ö·û´®²Ù×÷Ö¸Áî¡£ ½â£º LEA DI, STRING2

MOV AL, ¡®A¡¯ MOV CMP

CX, 20 AL, ES:[DI]

12

AGA:

JZ INC LOOP

EXIT DI AGA

EXIT:

2.31 ÔÚʹÓá°REPNZ CMPSB¡±Ö¸Áîʱ£¬Ó¦ÊÂÏÈ×öºÃÄÄЩ¹¤×÷£¿

½â£º½«Ô´´®µÄÆ«ÒƵØÖ·ËÍÈëSI£¬Ä¿µÄ´®µÄÆ«ÒƵØÖ·ËÍÈëDI£¬·½Ïò±êÖ¾DFÇå0£¬±È½ÏµÄ×Ö½ÚÊýËÍÈëCX¡£

2.32 ÒÑÖªÔÚÒÔARRAYΪÊ×µØÖ·µÄÄÚ´æÇøÓò´æ·ÅÁË100¸ö×Ö½ÚÊý£¬ÊÔ±àдÏà¹ØµÄ³ÌÐò¶Î

ÓÃÒÔÍê³É½«¸ÃÊý¾Ý´«Ë͵½BUFFΪÊ×µØÖ·µÄ´æ´¢ÇøÓòÖС£·Ö±ðÓÃÒÔϲ»Í¬·½·¨ÊµÏÖ¡£ £¨1£©ÓÃÒ»°ãÊý¾Ý´«ËÍÖ¸Áî¡°MOV¡±ÊµÏÖ¡£ £¨2£©ÓÃ×Ö·û´«ËÍÖ¸Áî¡°MOVSB¡±ÊµÏÖ¡£

£¨3£©ÓÃÖظ´²Ù×÷ǰ׺´«ËÍÖ¸Áî¡°REP MOVSB¡±ÊµÏÖ¡£ £¨4£©ÓÃLODSB/STOSBʵÏÖ¡£ ½â£º£¨1£©

LEA LEA MOV MOV INC INC LOOP LEA

£¨3£©

LEA

LEA

SI, ARRAY

DI, BUFF

13

LEA MOV

SI, ARRAY DI, BUFF AL, [SI] [DI], AL SI DI AGA SI, ARRAY DI, BUFF AX, DS

MOV CX, 100

AGA:

£¨2£©

MOV ES, AX MOV CX, 100 CLD

MOVSB

LOOP AGA

AGA:

MOV AX, DS

MOV ES, AX MOV CX, 100 CLD REP LEA

MOVSB SI, ARRAY DI, BUFF AX, DS

£¨4£©

2.33 ÅжÏSTRING1ºÍSTRING2ΪÊ×µØÖ·µÄÄÚ´æÇøÓò´æ·ÅÁ˶þ¸ö³¤¶ÈΪ20µÄ×Ö·û´®ÊÇ

·ñÏàµÈ¡£ÈôÏàµÈ½«SIGNµ¥ÔªÖÃ1£¬·´Ö®£¬½«SIGNµ¥ÔªÖÃ0¡£·Ö±ðÓÃÒÔϲ»Í¬·½·¨ÊµÏÖ¡£

£¨1£©ÓñȽÏÌõ¼þתÒÆÖ¸ÁîʵÏÖ¡£ £¨2£©ÓÃÖظ´²Ù×÷ǰ׺ËÑË÷Ö¸ÁîʵÏÖ¡£ ½â£º£¨1£©

LEA

LEA INC INC MOV CMP JZ MOV JMP

14

SI, STRING1-1 DI, STRING2-1 SI DI AL, [SI] AL [DI] EQ

SIGN, 0 EXIT

LEA MOV

MOV ES, AX MOV CX, 100 CLD LODSB STOSB LOOP

AGA

AGA:

MOV CX, 20

AGA:

LOOPZ AGA

EQ: EXIT:

MOV SIGN, 1

£¨2£©

LEA

SI, STRING1 LEA DI, STRING2 MOV

AX, DS

MOV ES, AX MOV CX, 20 CLD REPE CMPSB JZ EQ MOV SIGN, 0

JMP EXIT

EQ: MOV SIGN, 1

EXIT:

2.34 ÊÔÓÃÆäËûÖ¸ÁîÐòÁÐÀ´´úÌæÍê³ÉÒÔÏÂÖ¸ÁîµÄ¹¦ÄÜ£º(1)LOOP NEXT (2)LDS BX,[100H] (3)XLAT (4)LOOPZ NEXT (5)LAHF

(6)XCHG AX,[BX]

(7)NEG Word PTR[1000H] (8)ADC AL,[SI+BX] (9)TEST AL,00001111B (10)MOVSW(DF=0) (11)REPZ CMPSB(DF=0)

½â£º£¨1£©DEC CX

JNZ

NEXT

£¨2£©MOV BX, [100H]

MOV DS, [102H] £¨3£© MOV

AH,0 ADD

BX, AX MOV

AL, [BX]

£¨4£© JNZ EIXT

15

LOOP NEXT EXIT£º

£¨5£© ÌâÄ¿ºÃÏñ²»¶Ô £¨6£© MOV

CX, [BX] MOV

[BX], AX MOV

AX, CX £¨7£© MOV

AX, 0

SUB

AX, [1000H] MOV

[1000H], AX

£¨8£©

JNC NEXT

ADD AL, [SI+BX] INC AL JMP

DONE

NEXT: ADD AL,[SI+BX] DONE:

£¨9£© MOV

BL,AL

AND BL, 00001111B £¨10£© MOV

AX,[SI] MOV

ES:[DI],AX INC SI INC SI INC DI INC

DI

£¨11£© NEXT:MOV AL,[SI]

CMP AL,ES:[DI]

JNE EXIT INC SI INC DI

LOOP

NEXT

EXIT:

16