X86汇编应用(3)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41400276/article/details/80322391

1.一个用于进制转换和乘除法的综合程序

;程序功能:1.将16个数字组成的数组分别进行16进制输出和10进制输出,
;			并且进行排序,之后再次输出排好的16进制和10进制
;          2.将一个2进制的数字转化成10进制
;		   3.乘除法子程序
STACK1 SEGMENT PARA STACK
STACK_AREA DW 100H DUP(?)
STACK_BTM EQU $-STACK_AREA
STACK1 ENDS

DATA1 SEGMENT
TABLE_LEN DW 16
TABLE DW 260,701,400,5,4,0,11,43,61H,40,63H,50,60,0FECAH,12,34
BIN1 DW  1011101010110101B
DEC1 DB 6 DUP(0)
BIN2 DB '1011101010110101B$'  
TRAN DB '-->$'
FG 	DB '--$'
D1  DW ? 
D2  DW ? 
D3  DD ?  
DATA1 ENDS

CODE1 SEGMENT
      ASSUME CS:CODE1,DS:DATA1,SS:STACK1
MAIN PROC FAR
     MOV AX,STACK1
     MOV SS,AX
     MOV SP,STACK_BTM
	 MOV AX,DATA1
     MOV DS,AX
	 
	CALL TRAN16
	CALL TRAN10
	CALL PX
	CALL TRAN16
	CALL TRAN10	  
	CALL TRAN2TO10
	CALL MULTI
	CALL DIVI
EXIT1: MOV AX,4C00H
      INT 21H
MAIN ENDP

TRAN16 PROC
EXIT2:	
	MOV CX,17		
	DEC CX
	MOV SI,OFFSET TABLE
START2:	
	MOV   BX,[SI]
	MOV	  DL,BH
    SHR   DL,1		
	SHR   DL,1
	SHR   DL,1
	SHR   DL,1
    CMP   DL, 0AH
    JB    STEP5
    ADD   DL, 07H
STEP5:
    ADD   DL, 30H
    MOV   AH, 02H
    INT   21H

    MOV   DL, BH
    AND   DL, 0FH
    CMP   DL, 0AH
    JB    STEP6
    ADD   DL, 07H
STEP6:
    ADD   DL, 30H
    INT   21H

	MOV	  DL,BL
    SHR   DL,1
	SHR   DL,1
	SHR   DL,1
	SHR   DL,1
    CMP   DL, 0AH
    JB    STEP7
    ADD   DL, 07H
STEP7:
    ADD   DL, 30H
    MOV   AH, 02H
    INT   21H

    MOV   DL, BL
    AND   DL, 0FH
    CMP   DL, 0AH
    JB    STEP8
    ADD   DL, 07H
STEP8:
    ADD   DL, 30H
    INT   21H
	
	
    MOV DL,48h			;输出'H'
    MOV AH,02h
    INT 21h
	MOV AH,2			;输出空格
	MOV DL,32
	INT 21h

	ADD SI,2
	LOOP START2
	
	MOV AH,02h			;输出回车
    MOV DL,0dh
    INT 21h
    MOV AH,02h
    MOV DL,0ah
    INT 21h
	RET
TRAN16 ENDP

TRAN10 PROC

	MOV CX,17
	DEC CX
	MOV SI,OFFSET TABLE
START1:	
	MOV AX,[SI]			;10进制结果输出
	PUSH CX
	XOR CX,CX
	MOV BX,10
	nx1:
	XOR DX,DX
	DIV BX
	OR DX,0e30h
	INC CX
	PUSH DX
	CMP AX,0
	JNZ nx1
	nx2: 
	POP AX
	INT 10H
	LOOP nx2
	POP CX
	MOV AH,2
	MOV DL,32
	INT 21h
	ADD SI,2
	LOOP START1
	
	MOV AH,02h			;输出回车
    MOV DL,0dh
    INT 21h
    MOV AH,02h
    MOV DL,0ah
    INT 21h
	RET
TRAN10 ENDP
TRAN2TO10 PROC
	  MOV DX, OFFSET BIN2
	  MOV AH, 9
   	  INT 21H
	  MOV DX, OFFSET TRAN
	  MOV AH, 9
	  INT 21H
      MOV DX,BIN1
      MOV DI,OFFSET DEC1
      MOV CX,0
 LOP1:PUSH CX
      MOV AX,DX
      MOV DX,0
      MOV CX,10
      DIV CX
      XCHG AX,DX
      ADD AL,30H
      MOV [DI],AL
      INC DI
      POP CX
      INC CX
      CMP DX,0
      JNZ LOP1
 DEC2:DEC DI
      MOV AL,[DI]
      MOV DL,AL
      MOV AH,2
      INT 21H
      LOOP DEC2
      MOV AH,02h		;输出回车
      MOV DL,0dh
      INT 21h
      MOV AH,02h
      MOV DL,0ah
      INT 21h
	  RET
TRAN2TO10 ENDP

DIVI PROC				;除法
 

  SUB DX,DX
  MOV AX,0DCBAH
  MOV BX,0111H
  DIV BX


add word ptr D3,DX



MOV SI,OFFSET D3
START:	
	;PUSH  DX
	MOV   BX,AX
	MOV	  DL,BH
    SHR   DL,1
	SHR   DL,1
	SHR   DL,1
	SHR   DL,1
    CMP   DL, 0AH
    JB    STEP1
    ADD   DL, 07H
STEP1:
    ADD   DL, 30H
    MOV   AH, 02H
    INT   21H

    MOV   DL, BH
    AND   DL, 0FH
    CMP   DL, 0AH
    JB    STEP2
    ADD   DL, 07H
STEP2:
    ADD   DL, 30H
    INT   21H

	MOV	  DL,BL
    SHR   DL,1
	SHR   DL,1
	SHR   DL,1
	SHR   DL,1
    CMP   DL, 0AH
    JB    STEP3
    ADD   DL, 07H
STEP3:
    ADD   DL, 30H
    MOV   AH, 02H
    INT   21H

    MOV   DL, BL
    AND   DL, 0FH
    CMP   DL, 0AH
    JB    STEP4
    ADD   DL, 07H
STEP4:
    ADD   DL, 30H
    INT   21H
	MOV DL,48h
    MOV AH,02h
    INT 21h
	
	MOV DX, OFFSET FG
	MOV AH, 9
	INT 21H
	
	
	MOV   BX,[SI]
	MOV	  DL,BH
    SHR   DL,1
	SHR   DL,1
	SHR   DL,1
	SHR   DL,1
    CMP   DL, 0AH
    JB    STEP9
    ADD   DL, 07H
STEP9:
    ADD   DL, 30H
    MOV   AH, 02H
    INT   21H

    MOV   DL, BH
    AND   DL, 0FH
    CMP   DL, 0AH
    JB    STEP10
    ADD   DL, 07H
STEP10:
    ADD   DL, 30H
    INT   21H

	MOV	  DL,BL
    SHR   DL,1
	SHR   DL,1
	SHR   DL,1
	SHR   DL,1
    CMP   DL, 0AH
    JB    STEP11
    ADD   DL, 07H
STEP11:
    ADD   DL, 30H
    MOV   AH, 02H
    INT   21H

    MOV   DL, BL
    AND   DL, 0FH
    CMP   DL, 0AH
    JB    STEP12
    ADD   DL, 07H
STEP12:
    ADD   DL, 30H
    INT   21H

	MOV DL,48h
    MOV AH,02h
    INT 21h
	MOV AH,02h;换行
      MOV DL,0dh
      INT 21h
      MOV AH,02h
      MOV DL,0ah
      INT 21h
	RET
DIVI ENDP

MULTI PROC					;乘法
	SUB DX,DX
	MOV AX,1234H
	MOV BX,0F10FH
	MUL BX
	mov word ptr D3, ax
	mov word ptr D3+2, dx




	MOV SI,OFFSET D3


	MOV   BX,[SI+2]
	MOV	  DL,BH
    SHR   DL,1
	SHR   DL,1
	SHR   DL,1
	SHR   DL,1
    CMP   DL, 0AH
    JB    STEP21
    ADD   DL, 07H
STEP21:
    ADD   DL, 30H
    MOV   AH, 02H
    INT   21H

    MOV   DL, BH
    AND   DL, 0FH
    CMP   DL, 0AH
    JB    STEP22
    ADD   DL, 07H
STEP22:
    ADD   DL, 30H
    INT   21H

	MOV	  DL,BL
    SHR   DL,1
	SHR   DL,1
	SHR   DL,1
	SHR   DL,1
    CMP   DL, 0AH
    JB    STEP23
    ADD   DL, 07H
STEP23:
    ADD   DL, 30H
    MOV   AH, 02H
    INT   21H

    MOV   DL, BL
    AND   DL, 0FH
    CMP   DL, 0AH
    JB    STEP24
    ADD   DL, 07H
STEP24:
    ADD   DL, 30H
    INT   21H
	
	
	MOV   BX,[SI]
	MOV	  DL,BH
    SHR   DL,1
	SHR   DL,1
	SHR   DL,1
	SHR   DL,1
    CMP   DL, 0AH
    JB    STEP25
    ADD   DL, 07H
STEP25:
    ADD   DL, 30H
    MOV   AH, 02H
    INT   21H

    MOV   DL, BH
    AND   DL, 0FH
    CMP   DL, 0AH
    JB    STEP26
    ADD   DL, 07H
STEP26:
    ADD   DL, 30H
    INT   21H

	MOV	  DL,BL
    SHR   DL,1
	SHR   DL,1
	SHR   DL,1
	SHR   DL,1
    CMP   DL, 0AH
    JB    STEP27
    ADD   DL, 07H
STEP27:
    ADD   DL, 30H
    MOV   AH, 02H
    INT   21H

    MOV   DL, BL
    AND   DL, 0FH
    CMP   DL, 0AH
    JB    STEP28
    ADD   DL, 07H
STEP28:
    ADD   DL, 30H
    INT   21H

	MOV DL,48h
    MOV AH,02h
    INT 21h
	MOV AH,02h
    MOV DL,0dh
    INT 21h
    MOV AH,02h
    MOV DL,0ah
    INT 21h
	
	RET
	
MULTI ENDP
PX PROC
LP1: MOV BX,1					;降序排序
     MOV CX,TABLE_LEN
     DEC CX
     MOV SI,OFFSET TABLE
LP2: MOV AX,[SI]
     CMP AX,[SI+2]
     JAE CONTINUE
     XCHG AX,[SI+2]
     MOV [SI],AX
     MOV BX,0
CONTINUE: ADD SI,2
          LOOP LP2
          CMP BX,1
          JZ EXIT
          JMP SHORT LP1
EXIT:
	RET
PX ENDP
CODE1 ENDS
      END MAIN

程序运行结果:



2.一个用于字符串操作的综合程序

第一部分:

;程序功能:在指定位置插入字符串(假定字符串是 15061153 zhangchongzhi),并且打印插入前后的对别
STACK       SEGMENT    	PARA STACK
STACK_AREA  DW         	100H DUP(?)
STACK_BTM   EQU        	$ - STACK_AREA
STACK       ENDS

DATA        SEGMENT

INS_WORD 	DB 			'15061153 zhangchongzhi'       ;插入的字符串
INS_POS		DB 			'what'						   ;插入位置
INS_INFO 	DB 			'After inserting ,the result:',0DH,0AH,'$'
INS_LEN 	EQU 		INS_POS - INS_WORD
POS_LEN 	EQU 		INS_INFO - INS_POS
BUFF_INS 	DB 			'I just want to know what happened yesterday.',0DH,0AH,'$'  ;总的字符串
INS_END 	DW 			$



DATA        ENDS

CODE        SEGMENT
            ASSUME     	CS:CODE, DS:DATA, SS:STACK
MAIN        PROC       	FAR
			MOV        	AX,STACK
            MOV        	SS,AX
            MOV        	SP,STACK_BTM
            MOV        	AX,DATA
            MOV        	DS,AX
            MOV			ES,AX

            

            MOV			DX,OFFSET BUFF_INS
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET INS_INFO
            MOV			AH,9
            INT			21H

            CALL		INSERT

            MOV			DX,OFFSET BUFF_INS
            MOV			AH,9
            INT			21H


EXIT:       MOV        	AX,4C00H
            INT        	21H
MAIN        ENDP

INSERT 		PROC
			PUSH 		DI
			PUSH 		BX
			PUSH 		SI
			PUSH		CX
			PUSH 		AX
			
			MOV 		DI,OFFSET BUFF_INS
			MOV 		BX,OFFSET INS_END

LP1_I:		CMP 		DI,BX
			JZ 			INSERT_END

			MOV 		SI,OFFSET INS_POS

			MOV  		CX,POS_LEN
			PUSH 		DI

LP2_I:		MOV 		AL,BYTE PTR [SI]
			CMP 		BYTE PTR [DI],AL
			JNZ 		CONTINUE1

			INC 		SI
			INC 		DI

			LOOP 		LP2_I

			PUSH 		DI

			MOV 		CX,OFFSET INS_END
			SUB 		CX,DI
			MOV 		SI,OFFSET INS_END

			MOV 		AX,INS_LEN
			MOV 		DI,SI
			ADD 		DI,AX
			DEC 		DI

			STD
			REP 		MOVSB

			POP 		DI
			MOV 		SI,OFFSET INS_WORD
			MOV 		CX,INS_LEN
			CLD
			REP 		MOVSB

CONTINUE1: 	POP 		DI
CONTINUE2:	INC			DI
			JMP 		LP1_I

INSERT_END: POP			AX
			POP 		CX
			POP			SI
			POP			BX
			POP 		DI

			RET
INSERT 		ENDP


CODE        ENDS
            END        	MAIN

程序运行结果:



第二部分:

;程序功能:1.小写到大写转换
;          2.字符串复制
;          3.字符串按照字典序排序(默认为三个长度相同的字符串)
;		   4.字符串替换
;		   5.IO检测
STACK       SEGMENT    	PARA STACK
STACK_AREA  DW         	100H DUP(?)
STACK_BTM   EQU        	$ - STACK_AREA
STACK       ENDS

DATA        SEGMENT
BUFF_DST	DB			'TO LOWER:',0DH,0AH,'$'
BUFF_SRC    DB 			'TO UPPER',0DH,0AH,'$'
COPY_INFO 	DB			'AFTER COPYING:',0DH,0AH,'$'
COPY_LEN 	EQU			BUFF_SRC - BUFF_DST
COPY_END	DW			$


BUFF_DEL 	DB 			'FOR DELETING',0DH,0AH,'$'
DEL_INFO 	DB 			'AFRER DELETING:',0DH,0AH,'$'
DEL_WORD 	DB 			'DELETE'
DEL_END 	DW 			$
DEL_LEN 	EQU 		DEL_END - DEL_WORD


WORD_OLD	DB			'ZHANGCHONGZHI'
WORD_NEW	DB			'CHONGZHIZHANG'
BUFF_INFO 	DB 			'AFTER REPLACING:',0DH,0AH,'$'
LEN 		DW 			WORD_NEW - WORD_OLD
BUFF		DB			'FOR REPLACING:',0DH,0AH
			DB			'ZHANGCHONGZHI line1: HOW ARE YOU!',0DH,0AH
			DB			'ZHANGCHONGZHI line2: WHAT HAPPENED.',0DH,0AH
			DB			'ZHANGCHONGZHI line3: 15061153.',0DH,0AH
			DB 			'ZHANGCHONGZHI IS A GOOD BOY.',0DH,0AH
			DB			0DH,0AH
			DB			'$'
BUFF_LEN	EQU			$ - BUFF
BUFF_END	DW			$


BUFF_UP		DB 			'TO UPPER:',0DH,0AH,'$'
UP_END 		DW 			$
UP_INFO 	DB			'AFTER UPPERING:',0DH,0AH,'$'
UP_LEN 		EQU 		UP_END - BUFF_UP


WORD_TITLE 	DB  		'FOR SORTING:.',0DH,0AH,'$'
WORD_INFO 	DB 			'AFTER SORTING:',0DH,0AH,'$'
WORD_TMP 	DB 			'TEMP',0DH,0AH,'$'
WORD1		DB			'ACDC',0DH,0AH,'$'
WORD2		DB			'PEAR',0DH,0AH,'$'
WORD3 		DB 			'GOOD',0DH,0AH,'$'
C_LINE		DB			0DH,0AH,'$'
WORD_LEN 	DW 			WORD2 - WORD1

CMP_TITLE 	DB 			'FOR COMPARING:',0DH,0AH,'$'
CMP_INFO	DB 			'AFTER COMPARING:',0DH,0AH,'$'
CWORD1 		DB 			'TEER',0DH,0AH,'$'
CWORD2 		DB 			'TEAR',0DH,0AH,'$'
EQU_INFO 	DB 			'WORD1 IS EQUAL TO WORD2.',0DH,0AH,'$'
W1_INFO 	DB 			'WORD1 IS GREATER THAN WORD2.',0DH,0AH,'$'
W2_INFO 	DB 			'WORD1 IS SMALLER THAN WORD2.',0DH,0AH,'$'
CWORD_LEN 	DW 			CWORD2 - CWORD1

IO_INFO 	DB 			0DH,0AH
			DB 			'FOR IO TESTING',0DH,0AH
			DB 			'INPUT A STRING:',0DH,0AH,'$'
STR 		DB 			?			

DATA        ENDS

CODE        SEGMENT
            ASSUME     	CS:CODE, DS:DATA, SS:STACK
MAIN        PROC       	FAR
			MOV        	AX,STACK
            MOV        	SS,AX
            MOV        	SP,STACK_BTM
            MOV        	AX,DATA
            MOV        	DS,AX
            MOV			ES,AX

            MOV			DX,OFFSET BUFF_UP
            MOV			AH,9
            INT			21H

            CALL		UPPER

            MOV			DX,OFFSET UP_INFO
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET BUFF_UP
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET BUFF_DST
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET BUFF_SRC
            MOV			AH,9
            INT			21H

            CALL		COPY

            MOV			DX,OFFSET COPY_INFO
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET BUFF_DST
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET BUFF_SRC
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET BUFF
            MOV			AH,9
            INT			21H

            CALL 		INQ

            MOV			DX,OFFSET BUFF_INFO
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET BUFF
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET WORD_TITLE
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET WORD1
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET WORD2
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET WORD3
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET C_LINE
            MOV			AH,9
            INT			21H

            CALL 		SORT

            MOV			DX,OFFSET WORD_INFO
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET WORD1
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET WORD2
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET WORD3
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET CMP_TITLE
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET CWORD1
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET CWORD2
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET CMP_INFO
            MOV			AH,9
            INT			21H

            CALL 		COMP

            MOV			DX,OFFSET BUFF_DEL
            MOV			AH,9
            INT			21H

            MOV			DX,OFFSET DEL_INFO
            MOV			AH,9
            INT			21H

            CALL		DEL

            MOV			DX,OFFSET BUFF_DEL
            MOV			AH,9
            INT			21H
            

            MOV			DX,OFFSET IO_INFO
            MOV			AH,9
            INT			21H

            CALL 		IO


            

EXIT:       MOV        	AX,4C00H
            INT        	21H
MAIN        ENDP

DEL 		PROC
			PUSH 		DI
			PUSH 		BX
			PUSH 		SI
			PUSH		CX
			PUSH 		AX
			
			MOV 		DI,OFFSET BUFF_DEL
			MOV 		BX,OFFSET DEL_INFO

LP1_D:		CMP 		DI,BX
			JZ 			DELETE_END

			MOV 		SI,OFFSET DEL_WORD

			MOV  		CX,DEL_LEN
			PUSH 		DI

LP2_D:		MOV 		AL,BYTE PTR [SI]
			CMP 		BYTE PTR [DI],AL
			JNZ 		CONTINUE1

			INC 		SI
			INC 		DI

			LOOP 		LP2_D

			MOV 		SI,DI
			MOV 		CX,OFFSET DEL_INFO
			SUB 		CX,DI


			POP 		DI

			PUSH 		DI

			CLD
			REP 		MOVSB

CONTINUE1: 	POP 		DI
CONTINUE2:	INC			DI
			JMP 		LP1_D

DELETE_END: POP			AX
			POP 		CX
			POP			SI
			POP			BX
			POP 		DI

			RET
DEL 		ENDP

UPPER		PROC
			PUSH		SI
			PUSH		DI
			PUSH		CX
			PUSH		AX

			PUSH		ES
			PUSH		DS
			POP			ES
			MOV			SI,OFFSET BUFF_UP
			MOV			DI,SI
			MOV			CX,UP_LEN
			CLD

LP1_U:		LODSB
			CMP			AL,'a'
			JB			CONTINUE
			CMP			AL,'z'
			JA			CONTINUE
			SUB			AL,20H
CONTINUE:	STOSB
			LOOP		LP1_U
			POP			ES

			POP			AX
			POP			CX
			POP			DI
			POP			SI
			RET
UPPER		ENDP

COPY		PROC
			PUSH		SI
			PUSH		DI
			PUSH		CX

			PUSH		ES
			PUSH		DS
			POP			ES
			MOV			SI,OFFSET BUFF_SRC
			MOV			DI,OFFSET BUFF_DST
			MOV			CX,COPY_LEN
			CLD
			REP			MOVSB
			POP			ES

			POP			CX
			POP			DI
			POP			SI
			RET
COPY		ENDP

INQ 		PROC
			PUSH 		DI
			PUSH 		AX
			PUSH 		BX
			PUSH 		SI

			MOV 		DI,OFFSET BUFF
			MOV 		BX,OFFSET BUFF_END

LP1:		CMP 		DI,BX
			JZ 			INQ_END

			MOV 		SI,OFFSET WORD_OLD

			MOV  		CX,LEN
			PUSH 		DI

LP2:		MOV 		AL,BYTE PTR [SI]
			CMP 		BYTE PTR [DI],AL
			JNZ 		BECONTINUE

			INC 		SI
			INC 		DI

			LOOP 		LP2

			MOV 		SI,OFFSET WORD_NEW
			POP 		DI
			CALL 		REPL
			JMP 		INCONTINUE

BECONTINUE: POP 		DI
INCONTINUE:	INC			DI
			JMP 		LP1

INQ_END: 	POP 		SI
			POP 		BX
			POP 		AX
			POP 		DI
			RET
INQ 		ENDP

REPL 		PROC
			PUSH 		CX
			
			MOV 		CX,LEN
			CLD
			REP 		MOVSB

			POP 		CX
			RET
REPL 		ENDP

SORT 		PROC
			PUSH 		CX
			PUSH 		SI
			PUSH 		DI
            
            MOV 		CX,3
LP_OUT:		PUSH 		CX
			MOV 		SI,OFFSET WORD1
			MOV 		DI,OFFSET WORD2
			MOV  		CX,WORD_LEN
			CLD
			REPZ 		CMPSB
			
			JA 			W1GW2

LP1_S:		MOV 		SI,OFFSET WORD2
			MOV 		DI,OFFSET WORD3
			MOV  		CX,WORD_LEN
			CLD
			REPZ 		CMPSB

			JA 			W2GW3

			JMP 		SCONTINUE

W1GW2:		MOV 		SI,OFFSET WORD1
			MOV 		DI,OFFSET WORD_TMP
			CALL 		COPY_S

			MOV 		SI,OFFSET WORD2
			MOV 		DI,OFFSET WORD1
			CALL 		COPY_S

			MOV 		SI,OFFSET WORD_TMP
			MOV 		DI,OFFSET WORD2
			CALL 		COPY_S

			JMP 		LP1_S

W2GW3:		MOV 		SI,OFFSET WORD2
			MOV 		DI,OFFSET WORD_TMP
			CALL 		COPY_S

			MOV 		SI,OFFSET WORD3
			MOV 		DI,OFFSET WORD2
			CALL 		COPY_S

			MOV 		SI,OFFSET WORD_TMP
			MOV 		DI,OFFSET WORD3
			CALL 		COPY_S

SCONTINUE:	POP 		CX
			LOOP 		LP_OUT

			POP 		DI
			POP 		SI
			POP 		CX
			RET
SORT 		ENDP

COPY_S 		PROC
			PUSH 		CX

			MOV 		CX,WORD_LEN
			CLD
			REP 		MOVSB

			POP 		CX
			RET
COPY_S 		ENDP

COMP 		PROC
			
			MOV 		SI,OFFSET CWORD1
			MOV 		DI,OFFSET CWORD2
			MOV 		CX,CWORD_LEN
			CLD
			REPZ 		CMPSB

			JZ 			EQUAL
			JA 			W1
			JB			W2

EQUAL: 		MOV			DX,OFFSET EQU_INFO
            MOV			AH,9
            INT			21H

            JMP 		COMP_END

W1: 		MOV			DX,OFFSET W1_INFO
            MOV			AH,9
            INT			21H

            JMP 		COMP_END

W2: 		MOV			DX,OFFSET W2_INFO
            MOV			AH,9
            INT			21H

            JMP 		COMP_END

COMP_END: 	RET

COMP 		ENDP

IO 			PROC
			PUSH 		SI
			PUSH 		AX
			PUSH 		DX

			MOV 		SI,OFFSET STR

LP: 	    MOV 		AH,1
            INT  		21H
            CMP 		AL,0DH
            JZ 			NEXT

            MOV 		BYTE PTR [SI],AL
            INC 		SI

            JMP 		LP

NEXT: 		MOV 		DL,'$'
			MOV 		BYTE PTR [SI],DL
			MOV 		DX,OFFSET STR
			MOV 		AH,9
			INT 		21H

			POP			DX
			POP 		AX
			POP			SI
			RET
IO 			ENDP

CODE        ENDS
            END        	MAIN

程序运行结果:


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页