北工大汇编——子程序设计

题目要求

完成一个字母或数制之间的转化程序,主程序分别具有 5种可选择的子功能,按相应的宇符可分别进入相应的子功能并在屏幕上显示结果,按“q”键退出。子功能分别为: 1) 实现小写字母向大写字母的转换;2)实现大写字母向小写字母的转换;3)实现二进制数向十六进制数的转换;4)实现十六进制数向二进制数的转换:5)实现十六进制数向十进制数的转换。

北工大汇编——子程序设计_第1张图片

完整代码

DATAS SEGMENT
    ;此处输入数据段代码
    msg DB 'please input 1-5 q:quit$'  
DATAS ENDS

STACKS SEGMENT
    ;此处输入堆栈段代码
STACKS ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
    MOV AX,DATAS
    MOV DS,AX
    ;此处输入代码段代码
    LOP:
	    MOV AH, 1 
	    INT 21H
	
	    CMP AL, 'q'
	    JZ EXIT
	
	    CMP AL, '1' 
	    JB Err
	    CMP AL, '5'
	    JA Err
	
	    SUB AL, 30H
	    MOV BX, AX
	    
	    CMP AL,1
		JE FUNC1
		CMP AL,2
		JE FUNC2
		CMP AL,3
		JE FUNC3
		CMP AL,4
		JE FUNC4
		CMP AL,5
		JE FUNC5 
    JMP LOP
    
    
    
    FUNC1:
    	MOV DL, 0DH;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
	    
    	MOV AH, 1 
    	INT 21H
    	
    	CMP AL, 'a'
    	JB LOP
    	CMP AL, 'z'
    	JA LOP
    	
    	sub AL, 32
    	
    	MOV DL,AL
		MOV AH,02H
		INT 21H
		
		MOV DL, 0DH ;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
    JMP LOP
    
    
    
    FUNC2:
    	MOV DL, 0DH;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
	    
    	MOV AH, 1 
    	INT 21H
    	
    	CMP AL, 'A'
    	JB LOP
    	CMP AL, 'Z'
    	JA LOP
    	
    	add AL, 32
    	
    	MOV DL,AL
		MOV AH,02H
		INT 21H
		
		MOV DL, 0DH ;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
    JMP LOP
    
    
    
    FUNC3:
    	MOV DL, 0DH;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
	    
	    MOV DL, 0
	    MOV CL, 4
	    
	    FUNC3INPUT:
	    	MOV AH, 1 
	    	INT 21H
	    	
	    	CMP AL, '0'
	    	JB LOP
	    	CMP AL, '1'
	    	JA LOP
	    	
	    	JE FUNC3LOP1
	
	    	ROL DL,1
			OR DL,0
			
			JMP FUNC3LOP2
			
		FUNC3LOP1:
			ROL DL,1
			OR DL,1
			
		FUNC3LOP2:
			DEC CL
			CMP CL, 0
			JE FUNC3DISPLAY
			JMP FUNC3INPUT
			
		FUNC3DISPLAY:
			MOV CL, DL
			MOV DL, 0DH;回车换行
		    MOV AH, 02
		    INT 21H
		    MOV DL, 0AH
		    MOV AH, 02
		    INT 21H
		    
		    MOV DL, CL
		
			CMP DL, 0
			JB LOP
			CMP DL, 9
			JA FUNC3LOP3
			
			ADD DL, '0'
			
			JMP FUNC3LOP4
		
		FUNC3LOP3:
			ADD DL, 37H
			
		FUNC3LOP4:
			MOV AH,02H
			INT 21H
		
		MOV DL, 0DH;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
    JMP LOP
    
    
    
    
    FUNC4:
    	MOV DL, 0DH;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
	    
	    FUNC4INPUT:
	    	MOV AH, 1
	    	INT 21H
	    	
	    	CMP AL, '0'
	    	JB LOP
	    	CMP AL, '9'
	    	JA FUNC4CMP
	    	
	    	SUB AL, '0'
	    	MOV CH,8
			MOV BL,AL
	    	JMP FUNC4PRINT
	    	
	    FUNC4CMP:
	    	CMP AL, 'a'
	    	JB LOP
	    	CMP AL, 'f'
	    	JA LOP
	    	
	    	SUB AL, 'a'
	    	ADD AL, 10
	    	MOV CH,8
			MOV BL,AL
	    	JMP FUNC4PRINT
	    	
	    FUNC4PRINT:
	    	ROL BL, 1
	    	MOV DL, BL
	    	AND DL,1
			ADD DL, '0'
			
			MOV AH,02H
			INT 21H
			
		 	DEC CH
			JZ LOPPRINT
			JMP FUNC4PRINT
		
	LOPPRINT:
		MOV DL, 0DH;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
    JMP LOP
    
    
    
    
    FUNC5:
    	MOV DL, 0DH;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
	    
	    FUNC5INPUT:
	    	MOV AH, 1
	    	INT 21H
	    	
	    	CMP AL, '0'
	    	JB LOP
	    	CMP AL, '9'
	    	JA FUNC5CMP
	    	
	    	SUB AL, '0'
	    	MOV CH,8
			MOV BL,AL
	    	JMP FUNC5PRINT
	    	
	    FUNC5CMP:
	    	CMP AL, 'a'
	    	JB LOP
	    	CMP AL, 'f'
	    	JA LOP
	    	
	    	SUB AL, 'a'
	    	ADD AL, 10
	    	MOV CH,8
			MOV BL,AL
	    	JMP FUNC5PRINT
	    	
	    FUNC5PRINT:
			MOV AH, 0
			MOV BL, 10
			DIV BL
			
			MOV DH, AH
			CMP AL, 0
			JE NOTEN
			
			MOV DL,AL      
			ADD DL, '0'
			
			MOV AH,02H
			INT 21H
			
		NOTEN:	                        
			MOV DL,DH
			ADD DL,'0'
			MOV AH,02H
			INT 21H
			
		MOV DL, 0DH;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
    JMP LOP
	
	ERR:
	    MOV DL, 0DH ;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
	    
	    MOV DX, OFFSET msg
	    MOV AH, 09
	    INT 21H
	    
	    MOV DL, 0DH ;回车换行
	    MOV AH, 02
	    INT 21H
	    MOV DL, 0AH
	    MOV AH, 02
	    INT 21H
	    
	    JMP LOP
	
	EXIT:
	    MOV AH,4CH
	    INT 21H
CODES ENDS
    END START





你可能感兴趣的:(汇编,汇编,算法)