⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tran.asm

📁 本程序实现对二进制 十进制 十六进制的互相转换 1、 对进制进行判断 2、 数据的输入 3、 对数据做进制转换及输出 文件: tran.asm 源代码 设计思想.doc 简单介绍
💻 ASM
字号:
datarea segment
mesg1 db 'Please input a number with head of b or d or h to select style:',13,10 
    db 'b:bin to hex&dec',13,10 
    db 'h:hex to bin&dec',13,10 
    db 'd:dec to bin&hex',13,10
    db 'ESC to Exit',13,10,'$' 
msg_error db 13,10,'You have input a invalid number!Please select again(Remember:with b or d or h in the beginning):',13,10,'$' 
;mesg7 db 'Please input a bin number:',13,10,'$' 
;mesg8 db 'Please input a dec number:',13,10,'$' 
;mesg9 db 'please input a hex number:',13,10,'$' 
msg_wait   db 'Press anykey to continue...',13,10,'$'
msg_out_bin db 13,10,'bin number:','$' 
msg_out_dec db 13,10,'dec number:','$' 
msg_out_hex db 13,10,'hex number:','$' 
datarea ends 
prognam segment 
main proc far 
assume cs:prognam,ds:datarea 
start: 
push ds 
xor ax,ax 
push ax 
mov ax,datarea 
mov ds,ax 
  Func_Choose: 									;re-choose to use which function
	lea dx,mesg1 
	mov ah,09h 
	int 21h 
  Choice_Enter:
	mov ah,8 			 						;judge 
	int 21h 
	cmp al,'b' 
	je L1 
	cmp al,'h' 
	je L2 
	cmp al,'d' 
	je L3 
	cmp al,1Bh						;ESC
	je EXIT
	
	lea dx,msg_error 
	mov ah,9 
	int 21h 
	jmp Choice_Enter 

	L1: 
	call bin2others 
	call crlf 
	jmp Func_Choose 
	L2: 
	call hex2others 
	call crlf 
	jmp Func_Choose 
	L3: 
	call dec2others 
	call crlf 
	jmp Func_Choose 

 EXIT:
    MOV     AX,4C00H
	INT     21H
	ret 
main endp 

bin2others proc near 
	xor ax,ax 
	mov bx,ax 
	
	;lea dx,mesg7 					;inform todo
	;mov ah,9 
	;int 21h 
	
	mov si,4 
  newchar1: 
	mov ah,1 
	int 21h 
	sub al,30h 
	jl Disp_B2H 
	cmp al,02h
	jl add_to1 
	jmp Disp_B2H 
	
  add_to1:                    	   ;save bin to bx 
	mov cl,1 
	shl bx,cl 
	mov ah,0 
	add bx,ax 
	jmp newchar1 
  Disp_B2H: 
    push bx							;save for next use
	lea dx,msg_out_hex 					;display hex 
	mov ah,9 
	int 21h 	
  rotate1_1: 
	mov cl,4 
	rol bx,cl 
	mov al,bl 
	and al,0fh 
	add al,30h 
	cmp al,3ah 
	jl print1 
	add al,7h 
  print1: 
	mov dl,al 
	mov ah,2 
	int 21h 
	dec si 
	jnz rotate1_1 	
  Disp_B2D:
    pop bx
	lea dx,msg_out_dec 
	mov ah,9 
	int 21h              			;display dec 
	mov cx,10000d 
	call dec_div4 
	mov cx,1000 
	call dec_div4 
	mov cx,100 
	call dec_div4 
	mov cx,10 
	call dec_div4 
	mov cx,1 
	call dec_div4 

	ret 

bin2others endp 

hex2others proc near 
	mov bx,0 
	;lea dx,mesg9 
	;mov ah,9 
	;int 21h 
	mov si,16 
  newchar2: 
	mov ah,1 
	int 21h 
	sub al,30h 
	jl Disp_H2B
	cmp al,10h ;<16?
	jl add_to2 
	
	sub al,27h 
	cmp al,0ah 
	jl  Disp_H2B 
	cmp al,10h 
	jge Disp_H2B 
  add_to2: 
	mov cl,4 
	shl bx,cl 
	mov ah,0 
	add bx,ax 				;save hex to bx
	jmp newchar2 
  Disp_H2B:
    push bx
	lea dx,msg_out_bin 			;display bin
	mov ah,9 
	int 21h 
  print2: 
	rol bx,1 
	mov al,bl 
	and al,1h 
	add al,30h 
	mov dl,al 
	mov ah,2 
	int 21h 
	dec si 
	jnz print2 
  Disp_H2D:
    pop bx
	lea dx,msg_out_dec 
	mov ah,9 
	int 21h                ;display dec 
	mov cx,10000d 
	call dec_div5 
	mov cx,1000d 
	call dec_div5 
	mov cx,100d 
	call dec_div5 
	mov cx,10d 
	call dec_div5 
	mov cx,1d 
	call dec_div5 
	ret 
hex2others endp 

dec2others proc near 
	;lea dx,mesg8 
	;mov ah,9 
	;int 21h 

	mov bx,0 
	mov si,16 
 newchar3: 
	mov ah,1 
	int 21h 
	
	sub al,30h 
	jl Disp_D2B 
	cmp al,9d 
	jg Disp_D2B
	cbw 
	
	xchg ax,bx 
	mov cx ,10d 
	mul cx 
	xchg ax,bx 
	add bx,ax 
	jmp newchar3 
  Disp_D2B:
	push bx
	lea dx,msg_out_bin 				;display bin
	mov ah,9 
	int 21h 
  print3:
	rol bx,1 
	mov al,bl 
	and al,1h 
	add al,30h 
	mov dl,al 
	mov ah,2 
	int 21h 
	dec si 
	jnz print3 
  Disp_D2H:	
    pop bx
	mov si,4 					;display hex
	lea dx,msg_out_hex 
	mov ah,9 
	int 21h 
  rotatet6: 
	mov cl,4 
	rol bx,cl 
	mov al,bl 
	and al,0fh 
	add al,30h 
	cmp al,3ah 
	jl printt6 
	add al,7h 
  printt6: 
	mov dl,al 
	mov ah,2 
	int 21h 
	dec si
	jnz rotatet6 
	ret 
dec2others endp 

dec_div4 proc near 
mov ax,bx 
mov dx,0 
div cx 
mov bx,dx 
mov dl,al 
add dl,30h 
mov ah,2 
int 21h 
ret 
dec_div4 endp 

dec_div5 proc near 
mov ax,bx 
mov dx,0 
div cx 
mov bx,dx 
mov dl,al 
add dl,30h 
mov ah,2 
int 21h 
ret 
dec_div5 endp 

crlf proc near 
mov dl,13 
mov ah,2 
int 21h 
mov dl,10 
mov ah,2 
int 21h 

lea dx,msg_wait 	;wait for entering anykey
mov ah,9 
int 21h
mov ah,8
int 21h

ret 
crlf endp 
prognam ends 
end start

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -