Find strings (and modify, sort, insert, delete, etc.) - assembly language

A group of strings are data,name,time,file,code,path,user,exit,quit,text. Please write a program to input a string of 4 characters from the keyboard. If there is a string, change it to disk and display the result on the display.

DATAS SEGMENT
    STRING0 DB 'data',0AH,0DH     
    STRING1 DB 'name',0AH,0DH     
    STRING2 DB 'time',0AH,0DH     
    STRING3 DB 'file',0AH,0DH     
    STRING4 DB 'code',0AH,0DH    
    STRING5 DB 'path',0AH,0DH     
    STRING6 DB 'user',0AH,0DH     
    STRING7 DB 'exit',0AH,0DH     
    STRING8 DB 'quit',0AH,0DH    
    STRING9 DB 'text','$'  
    BUF DB 5         
    DB ?         
    DB 5 DUP(?) ;Enter segment code here  
DATAS ENDS

EXTRA SEGMENT   
    STRING DB 7 DUP(?) ;Enter stack segment code here
EXTRA ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:EXTRA
START:
    MOV AX,DATAS
    MOV DS,AX
	MOV AX,EXTRA     
	MOV ES,AX     
	LEA DX,BUF     
	MOV AH,0AH     
	INT 21H     
	LEA SI,BUF+2     
	LEA DI,STRING
	
	MOV CX,4     
	REP MOVSB     
	LEA SI,STRING0     
	LEA DI,STRING     
	CLD     
	
	MOV CX,4     
	REPE CMPSB     
	CMP CX,0     
	JE TIHUAN     
	LEA SI,STRING1     
	LEA DI,STRING     
	CLD     
	MOV CX,4     
	REPE CMPSB     
	CMP CX,0     
	JE TIHUAN     
	LEA SI,STRING2     
	LEA DI,STRING 
    CLD     
    MOV CX,4     
    REPE CMPSB     
    CMP CX,0     
    JE TIHUAN     
    LEA SI,STRING3     
    LEA DI,STRING     
    CLD     
    MOV CX,4     
    REPE CMPSB     
    CMP CX,0     
    JE TIHUAN     
    LEA SI,STRING4     
    LEA DI,STRING     
    CLD     
    MOV CX,4     
    REPE CMPSB     
    CMP CX,0     
    JE TIHUAN     
    LEA SI,STRING5     
    LEA DI,STRING     
    CLD     
    MOV CX,4     
    REPE CMPSB     
    CMP CX,0     
    JE TIHUAN     
    LEA SI,STRING6     
    LEA DI,STRING     
    CLD     
    MOV CX,4     
    REPE CMPSB     
    CMP CX,0     
    JE TIHUAN     
    LEA SI,STRING7     
    LEA DI,STRING     
    CLD     
    MOV CX,4     
    REPE CMPSB     
    CMP CX,0     
    JE TIHUAN     
    LEA SI,STRING8     
    LEA DI,STRING     
    CLD     
    MOV CX,4 
    REPE CMPSB     
    CMP CX,0     
    JE TIHUAN     
    LEA SI,STRING9     
    LEA DI,STRING     
    CLD     
    MOV CX,4     
    REPE CMPSB     
    CMP CX,0     
    JE TIHUAN     
    JMP SHUCHU 
TIHUAN:     
    SUB SI,4     
    MOV AL,'d'     
    MOV [SI],AL    
     MOV AL,'i'     
     MOV [SI+1],AL     
     MOV AL,'s'     
     MOV [SI+2],AL     
     MOV AL,'k'     
     MOV [SI+3],AL 
SHUCHU:     
     LEA DX,STRING0     
     MOV AH,09H     
     INT 21H     
     MOV AH,4CH     
     INT 21H 
     CODES ENDS 
    END START ;Code snippet code here
    MOV AH,4CH
    INT 21H
CODES ENDS
    END START

For example, the result of entering user:

Results when entering abcd:

There is a set of strings ram, yes, red, the get, for, and key, not, may. Please write a program to sort them by ASCII size and display them on the display.

DATAS SEGMENT
     STR0 DB 'ram',0AH,0DH     
     STR1 DB 'yes',0AH,0DH     
     STR2 DB 'red',0AH,0DH     
     STR3 DB 'the',0AH,0DH     
     STR4 DB 'get',0AH,0DH     
     STR5 DB 'for',0AH,0DH     
     STR6 DB 'and',0AH,0DH     
     STR7 DB 'key',0AH,0DH     
     STR8 DB 'not',0AH,0DH     
     STR9 DB 'may$' 
     ;Enter segment code here  
DATAS ENDS

STACKS SEGMENT
    SAVE DB 100 DUP(?) ;Enter stack segment code here
STACKS ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
    MOV AX,DATAS
    MOV DS,AX
    MOV ES,AX
    XOR AX,AX
    MOV CX,9
    LEA DI,STR0
    LEA SI,STR1
AGAIN:
	 PUSH CX     
	 PUSH SI     
	 PUSH DI 
    
BIJIAO:
	MOV AL,[DI]
	CMP AL,[SI]
	JE BIJIAO1
	CMP AL,[SI]
	JB JIXU
	JMP JIAOHUAN
BIJIAO1:
	MOV AL,[DI+1]
	CMP AL,[SI+1]
	JE BIJIAO2
	CMP AL,[SI]
	JB JIXU
	JMP JIAOHUAN
BIJIAO2:
	MOV AL,[DI+2]
	CMP AL,[SI+2]
	JA JIAOHUAN
	JMP JIXU
JIXU:
	 ADD SI,5     
	 ADD DI,5
	 LOOP BIJIAO
	 POP DI     
	 POP SI     
	 POP CX 
	 LOOP AGAIN
	 JMP OUTPUT
JIAOHUAN:
	MOV AL,[SI]     
	MOV BL,[DI]     
	MOV [SI],BL     
	MOV [DI],AL     
	MOV AL,[SI+1]     
	MOV BL,[DI+1]     
	MOV [SI+1],BL     
	MOV [DI+1],AL     
	MOV AL,[SI+2]     
	MOV BL,[DI+2]     
	MOV [SI+2],BL     
	MOV [DI+2],AL     
	JMP JIXU
OUTPUT:
	LEA DX,STR0
	MOV AH,09H
	INT 21H 
    
    ;Code snippet code here
    MOV AH,4CH
    INT 21H
CODES ENDS
    END START

Example of result chart:

There is a set of strings as data,name,time,file,code,path,user,exit,quit,text. Please write a program to input 4-character strings from the keyboard, if any, delete them and display them on the display.

DATAS SEGMENT
    STR0 DB 'data',0AH,0DH     
    STR1 DB 'name',0AH,0DH     
    STR2 DB 'time',0AH,0DH     
    STR3 DB 'file',0AH,0DH     
    STR4 DB 'code',0AH,0DH     
    STR5 DB 'path',0AH,0DH     
    STR6 DB 'user',0AH,0DH     
    STR7 DB 'exit',0AH,0DH     
    STR8 DB 'quit',0AH,0DH     
    STR9 DB 'text',0AH,0DH,'$'     
    LEN EQU $-STR0     
    BUF DB 6   
    JISHU DB 00H   
    DB ? 
    DB 5 DUP(?)  ;Enter segment code here  
DATAS ENDS

STACKS SEGMENT
    STRING DB 7 DUP(?);Enter stack segment code here
STACKS ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,ES:STACKS
START:
    MOV AX,DATAS
    MOV DS,AX
	MOV AX,STACKS    
	MOV ES,AX     
SHURU:
	LEA DX,BUF
	MOV AH,0AH
	INT 21H
	LEA DI,STRING
	LEA SI,BUF[2]
	MOV CX,4
	REP MOVSB
	
	
	LEA DI,STRING
	LEA SI,STR0
	CLD
	MOV CX,4
	;JMP JIAOHUAN
	REPE CMPSB
	CMP CX,0
	JE YIDONG
	INC JISHU
	LEA DI,STRING
	LEA SI,STR1
	CLD
	MOV CX,4
	REPE CMPSB
	CMP CX,0
	JE YIDONG
	INC JISHU
    LEA DI,STRING
	LEA SI,STR2
	CLD
	MOV CX,4
	REPE CMPSB
	CMP CX,0
	JE YIDONG
	INC JISHU
    LEA DI,STRING
	LEA SI,STR3
	CLD
	MOV CX,4
	REPE CMPSB
	CMP CX,0
	JE YIDONG
	INC JISHU
	LEA DI,STRING
    LEA SI,STR4
	CLD
	MOV CX,4
	REPE CMPSB
	CMP CX,0
	JE YIDONG
	INC JISHU
	LEA DI,STRING
    LEA SI,STR5
	CLD
	MOV CX,4
	REPE CMPSB
	CMP CX,0
	JE YIDONG
	INC JISHU
	LEA DI,STRING
	LEA SI,STR6
	CLD
	MOV CX,4
	REPE CMPSB
	CMP CX,0
	JE YIDONG
	INC JISHU
	LEA DI,STRING
	LEA SI,STR7
	CLD
	MOV CX,4
	REPE CMPSB
	CMP CX,0
	JE YIDONG
	INC JISHU
	LEA DI,STRING
	LEA SI,STR8
	CLD
	MOV CX,4
	REPE CMPSB
	CMP CX,0
	JE YIDONG
	INC JISHU
	LEA DI,STRING
	LEA SI,STR9
	CLD
	MOV CX,4
	REPE CMPSB
	CMP CX,0
	JE YIDONG
	INC JISHU
	JMP SHUCHU
YIDONG:
	MOV AL,JISHU
	XOR AH,AH
	MOV BL,04H
	MUL BL
	MOV BL,AL
	MOV BX,SI
	MOV AX,LEN
	SUB AL,BL
	MOV CL,AL
	DEC SI
	DEC SI
	DEC SI
	DEC SI
JIAOHUAN:
	MOV AX,[SI+6]
	MOV [SI],AX
	INC SI
	DEC CX
	CMP CX,0
	JNE JIAOHUAN
SHUCHU:
	LEA DX,STR0	
	MOV AH,09H
	INT 21H
    ;Code snippet code here
    MOV AH,4CH
    INT 21H
CODES ENDS
    END START

For example, enter the result after user:

There is a set of strings as data,name,time,file,code,path,user,exit,quit,text. Please write a program to sort the above strings (in ascending order) and insert the disk to make them still in order, and display them on the display.

Refer to the above examples and combine them.

 

 

Keywords: ascii

Added by Sturm on Tue, 10 Dec 2019 04:39:23 +0200