十进制与十进制互换.doc
文本预览下载声明
十进制与十六进制互换
说明:程序运行,选择功能。
按1键:十进制转换成十六进制,键入值:0-255;
按2键:十六进制转换成十进制,键入值:0-ff;
按q键:退出。
代码部分:
stack segment stack stack
dw 100h dup(?)
top label word
stack ends
data segment
select db ?
decimal db 5 dup(?)
buffer db 100 dup(?)
keybuffer db 100
db ?
db 100 dup(?)
string1 db press 1: deciamal to Hexadecimal,0dh,0ah,
press 2: Hexadecimal to deciamal ,0dh,0ah,
press q: out ,0dh,0ah,$
string2 db please input deciamal data(0-255) :$
string3 db please input Hexadecimal data(0-ff) :$
string4 db change to Hexadecimal: $
string5 db change to deciamal: $
data ends
code segment
assume cs:code,ds:data,es:data,ss:stack
start: ;键盘输入十六进制数(最大:ff),输出十进制数(255)
mov ax,data
mov ds,ax
mov es,ax
mov ax,stack
mov ss,ax
lea sp,top
mov cx,5
mov dx,0h
lea si,decimal
lps:
mov [si],dx
inc si
loop lps
lea dx,string1 ;显示选择功能提示
mov ah,09h
int 21h
mov ah,01h ;保存选择项
int 21h
mov select,al
cmp select,71h
je over
call dispcr
cmp select,31h ;根据选择项显示提示
je ke
lea dx,string3
jmp kr
ke:
lea dx,string2
kr:
mov ah,09h
int 21h
mov ah,0ah
lea dx,keybuffer
int 21h
lea si,keybuffer+1
lea di,buffer
mov cx,[si]
cmp select,31h
je kre
mov bx,10h
jmp lp
kre:
mov bx,10
lp: ;取值到存储单元
inc si
dec cx
mov al,[si]
sub al,30h
cmp select,31h
je de
cmp al,0ah
jb de
sub al,27h
de:
add [di],al
mov al,0dh
cmp [si],al
je over
cmp [si+1],al
je mp ;是回车
mov al,[di] ;不是回车 乘16
mul bx
mov [di],al
loop lp
mp:
call dispcr
cmp select,31h
je uc
lea dx,string5
jmp uct
uc:
lea dx,string4
uct:
mov ah,09h
int 21h
mov cx,di
lea si,buffer
sub cx,si
inc cx
xor ax,ax
mov al,[si]
call dispaxd
call dispcr ;
call dispcr ;
jmp start ;
over:
mov ah,4ch
int 21h
dispcr proc near
push ax
push dx
mov ah,02h
显示全部