IBM-PC»ã±àÓïÑÔ³ÌÐòÉè¼Æ´ð°¸£¨µÚ2°æ£© ÏÂÔر¾ÎÄ

END START

5.14 ÔÚÊ×µØַΪTABLEµÄÊý×éÖа´µÝÔö´ÎÐò´æ·Å×Å100H¸ö16λ²¹ÂëÊý£¬ÊÔ±àдһ¸ö³ÌÐò°Ñ³öÏÖ´Î

Êý×î¶àµÄÊý¼°Æä³öÏÖ´ÎÊý·Ö±ð´æ·ÅÓÚAXºÍCXÖС£ ´ð£º³ÌÐòÈçÏ£º

DSEG SEGMENT TABLE DW 100H DUP (?) £»Êý×éÖеÄÊý¾ÝÊÇ°´ÔöÐòÅÅÁÐµÄ DATA DW ? COUNT DW 0 DSEG ENDS

£»-------------------------------------------------------------------------- CSEG SEGMENT MAIN PROC FAR

ASSUME CS: CSEG, DS: DSEG

START: PUSH DS £»ÉèÖ÷µ»ØDOS

SUB AX, AX PUSH AX

MOV AX, DSEG MOV DS, AX £»¸øDS¸³Öµ

BEGIN: MOV CX, 100H £»Ñ­»·¼ÆÊýÆ÷

MOV SI, 0

NEXT: MOV DX, 0

MOV AX, TABLE [SI]

COMP: CMP TABLE [SI], AX £»¼ÆËãÒ»¸öÊýµÄ³öÏÖ´ÎÊý

JNE ADDR INC DX ADD SI, 2 LOOP COMP

ADDR: CMP DX, COUNT £»´ËÊý³öÏֵĴÎÊý×î¶àÂð£¿

JLE DONE

MOV COUNT, DX £»Ä¿Ç°´ËÊý³öÏֵĴÎÊý×î¶à£¬¼ÇÏ´ÎÊý MOV DATA, AX £»¼ÇÏ´ËÊý

DONE: LOOP NEXT £»×¼±¸È¡ÏÂÒ»¸öÊý

MOV CX, COUNT £»³öÏÖ×î¶àµÄ´ÎÊý´æÈë(CX) MOV AX, DATA £»³öÏÖ×î¶àµÄÊý´æÈë(AX) RET

MAIN ENDP CSEG ENDS £»ÒÔÉ϶¨Òå´úÂë¶Î £»--------------------------------------------------------------------------

END START 5.15 Êý¾Ý¶ÎÖÐÒѶ¨ÒåÁËÒ»¸öÓÐn¸ö×ÖÊý¾ÝµÄÊý×éM£¬ÊÔ±àдһ³ÌÐòÇó³öMÖоø¶ÔÖµ×î´óµÄÊý£¬°ÑËü·Å

ÔÚÊý¾Ý¶ÎµÄM+2nµ¥ÔªÖУ¬²¢½«¸ÃÊýµÄÆ«ÒƵØÖ·´æ·ÅÔÚM+2(n+1)µ¥ÔªÖС£ ´ð£º³ÌÐòÈçÏ£º

DSEG SEGMENT n EQU 100H £»¼ÙÉèn=100H M DW n DUP (?) DATA DW ? £»M+2nµ¥Ôª ADDR DW ? £»M+2(n+1)µ¥Ôª DSEG ENDS

£»-------------------------------------------------------------------------- CSEG SEGMENT MAIN PROC FAR

ASSUME CS: CSEG, DS: DSEG

START: PUSH DS £»ÉèÖ÷µ»ØDOS

SUB AX, AX PUSH AX

MOV MOV

BEGIN:

AX, DSEG DS, AX

£»¸øDS¸³Öµ

MOV CX, n £»Ñ­»·¼ÆÊýÆ÷ LEA DI, M MOV AX, [DI] £»È¡µÚÒ»¸öÊý MOV ADDR, DI £»¼ÇϾø¶ÔÖµ×î´óµÄÊýµÄµØÖ· CMP AX, 0 £»´ËÊýÊÇÕýÊýÂ𣿠JNS ZHEN £»ÊÇÕýÊý£¬¼´Îª¾ø¶ÔÖµ£¬×ªÈ¥ÅжÏÏÂÒ»¸öÊý NEG AX £»²»ÊÇÕýÊý£¬±äΪÆä¾ø¶ÔÖµ

ZHEN: MOV BX, [DI]

CMP BX, 0 £»´ËÊýÊÇÕýÊýÂ𣿠JNS COMP £»ÊÇÕýÊý£¬¼´Îª¾ø¶ÔÖµ£¬×ªÈ¥±È½Ï¾ø¶ÔÖµ´óС NEG BX £»²»ÊÇÕýÊý£¬±äΪÆä¾ø¶ÔÖµ

COMP: CMP AX, BX £»ÅжϾø¶ÔÖµ´óС

JAE ADDRESS MOV AX, BX £»(AX)<(BX)£¬Ê¹(AX)ÖÐΪ¾ø¶ÔÖµ×î´óµÄÊý MOV ADDR, DI £»¼ÇϾø¶ÔÖµ×î´óµÄÊýµÄµØÖ·

ADDRESS: ADD DI, 2

LOOP ZHEN

MOV DATA, AX £»¼ÇÏ´ËÊý RET

MAIN ENDP CSEG ENDS £»ÒÔÉ϶¨Òå´úÂë¶Î £»--------------------------------------------------------------------------

END START

5.16 ÔÚÊ×µØַΪDATAµÄ×ÖÊý×éÖдæ·Å×Å100H¸ö16λ²¹ÂëÊý£¬ÊÔ±àдһ¸ö³ÌÐòÇó³öËüÃǵÄƽ¾ùÖµ·Å

ÔÚAX¼Ä´æÆ÷ÖУ»²¢Çó³öÊý×éÖÐÓжàÉÙ¸öÊýСÓÚ´Ëƽ¾ùÖµ£¬½«½á¹û·ÅÔÚBX¼Ä´æÆ÷ÖС£ ´ð£º³ÌÐòÈçÏ£º

DSEG SEGMENT DATA DW 100H DUP (?) DSEG ENDS

£»-------------------------------------------------------------------------- CSEG SEGMENT MAIN PROC FAR

ASSUME CS: CSEG, DS: DSEG

START: PUSH DS £»ÉèÖ÷µ»ØDOS

SUB AX, AX PUSH AX

MOV AX, DSEG MOV DS, AX £»¸øDS¸³Öµ

BEGIN: MOV CX, 100H £»Ñ­»·¼ÆÊýÆ÷

MOV SI, 0

MOV BX, 0 £»ºÍ((DI),(BX))µÄ³õʼֵ MOV DI, 0

NEXT: MOV AX, DATA [SI]

CWD

ADD BX, AX £»ÇóºÍ ADC DI, DX £»¼ÓÉϽøλλ ADD SI, 2 LOOP NEXT MOV DX, DI £»½«((DI),(BX))ÖеÄÀۼӺͷÅÈë((DX),(AX))ÖÐ MOV AX, BX MOV CX, 100H IDIV CX £»´ø·ûºÅÊýÇóƽ¾ùÖµ£¬·ÅÈë(AX)ÖÐ

MOV BX, 0 MOV SI, 0

COMP: CMP AX, DATA [SI] £»Ñ°ÕÒСÓÚƽ¾ùÖµµÄÊý

JLE NO INC BX £»Ð¡ÓÚƽ¾ùÖµÊýµÄ¸öÊý+1

NO: ADD SI, 2

LOOP COMP RET

MAIN ENDP CSEG ENDS £»ÒÔÉ϶¨Òå´úÂë¶Î £»--------------------------------------------------------------------------

END START

5.17 ÊÔ±àÖÆÒ»¸ö³ÌÐò°ÑAXÖеÄ16½øÖÆÊýת»»ÎªASCIIÂ룬²¢½«¶ÔÓ¦µÄASCIIÂëÒÀ´Î´æ·Åµ½MEMÊý

×éÖеÄËĸö×Ö½ÚÖС£ÀýÈ磬µ±(AX)=2A49Hʱ£¬³ÌÐòÖ´ÐÐÍêºó£¬MEMÖеÄ4¸ö×Ö½ÚÄÚÈÝΪ39H£¬34H£¬41H£¬32H¡£ ´ð£º³ÌÐòÈçÏ£º

DSEG SEGMENT MEM DB 4 DUP (?) N DW 2A49H DSEG ENDS

£»-------------------------------------------------------------------------- CSEG SEGMENT MAIN PROC FAR

ASSUME CS: CSEG, DS: DSEG

START: PUSH DS £»ÉèÖ÷µ»ØDOS

SUB AX, AX PUSH AX

MOV AX, DSEG MOV DS, AX £»¸øDS¸³Öµ

BEGIN: MOV CH, 4 £»Ñ­»·¼ÆÊýÆ÷

MOV CL, 4 MOV AX, N LEA BX, MEM

ROTATE: MOV DL, AL £»´Ó×îµÍËÄλ¿ªÊ¼×ª»»ÎªASCIIÂë

AND DL, 0FH ADD DL, 30H CMP DL, 3AH £»ÊÇ0~9Â𣿠JL NEXT ADD DL, 07H £»ÊÇA~F

NEXT: MOV [BX], DL £»×ª»»µÄASCIIÂëËÍÈëMEMÖÐ

INC BX ROR AX, CL £»×¼±¸×ª»»ÏÂһλ DEC CH JNZ ROTATE RET

MAIN ENDP CSEG ENDS £»ÒÔÉ϶¨Òå´úÂë¶Î £»--------------------------------------------------------------------------

END START 5.18 °Ñ0~100DÖ®¼äµÄ30¸öÊý´æÈëÒÔGRADEΪÊ×µØÖ·µÄ30×ÖÊý×éÖУ¬GRADE+i±íʾѧºÅΪi+1µÄ

ѧÉúµÄ³É¼¨¡£ÁíÒ»¸öÊý×éRANKΪ30¸öѧÉúµÄÃû´Î±í£¬ÆäÖÐRANK+iµÄÄÚÈÝÊÇѧºÅΪi+1µÄѧÉúµÄÃû´Î¡£±àдһ³ÌÐò£¬¸ù¾ÝGRADEÖеÄѧÉú³É¼¨£¬½«Ñ§ÉúÃû´ÎÌîÈëRANKÊý×éÖС£(Ìáʾ£ºÒ»¸öѧÉúµÄÃû´ÎµÈÓڳɼ¨¸ßÓÚÕâ¸öѧÉúµÄÈËÊý¼Ó1¡£) ´ð£º³ÌÐòÈçÏ£º

DSEG SEGMENT

GRADE DW 30 DUP (?) £»¼ÙÉèÒÑÔ¤ÏÈ´æºÃ30ÃûѧÉúµÄ³É¼¨ RANK DW 30 DUP (?) DSEG ENDS

£»-------------------------------------------------------------------------- CSEG SEGMENT MAIN PROC FAR

ASSUME CS: CSEG, DS: DSEG

START: PUSH DS £»ÉèÖ÷µ»ØDOS

SUB AX, AX PUSH AX

MOV AX, DSEG MOV DS, AX £»¸øDS¸³Öµ

BEGIN: MOV DI, 0

MOV CX, 30 £»ÍâÑ­»·¼ÆÊýÆ÷

LOOP1: PUSH CX

MOV CX, 30 £»ÄÚÑ­»·¼ÆÊýÆ÷ MOV SI, 0

MOV AX, GRADE [DI] MOV DX, 1 £»ÆðʼÃû´ÎΪµÚ1Ãû

LOOP2: CMP GRADE [SI], AX £»³É¼¨±È½Ï

JBE GO_ON INC DX £»Ãû´Î+1

GO_ON: ADD SI, 2

LOOP LOOP2 POP CX

MOV RNAK [DI], DX £»Ãû´Î´æÈëRANKÊý×é ADD DI, 2 LOOP LOOP1 RET

MAIN ENDP CSEG ENDS £»ÒÔÉ϶¨Òå´úÂë¶Î £»--------------------------------------------------------------------------

END START

5.19 ÒÑÖªÊý×éA°üº¬15¸ö»¥²»ÏàµÈµÄÕûÊý£¬Êý×éB°üº¬20¸ö»¥²»ÏàµÈµÄÕûÊý¡£ÊÔ±àÖÆÒ»³ÌÐò°Ñ¼ÈÔÚ

AÖÐÓÖÔÚBÖгöÏÖµÄÕûÊý´æ·ÅÓÚÊý×éCÖС£ ´ð£º³ÌÐòÈçÏ£º

DSEG SEGMENT A DW 15 DUP (?) B DW 20 DUP (?) C DW 15 DUP (? ¡®) DSEG ENDS

£»-------------------------------------------------------------------------- CSEG SEGMENT MAIN PROC FAR

ASSUME CS: CSEG, DS: DSEG

START: PUSH DS £»ÉèÖ÷µ»ØDOS

SUB AX, AX PUSH AX

MOV AX, DSEG MOV DS, AX £»¸øDS¸³Öµ

BEGIN: MOV SI, 0

MOV BX, 0 MOV CX, 15 £»ÍâÑ­»·¼ÆÊýÆ÷

LOOP1: PUSH CX

MOV CX, 20 £»ÄÚÑ­»·¼ÆÊýÆ÷