数码转换实验
实验要求
(1)数制转换
assume cs:code
data segment
est db " Error:Input invalid",0ah,0dh,
data ends
stack segment
stk db 64 dup (0)
stack ends
code segment
start: mov ax,stack
mov ss,ax
mov sp,offset stk
mov ax,data
mov ds,ax
rf: mov cx,5
mov ax,0
mov dx,0
mov si,0
mov di,0
rr: mov ah,01h
int 21h
cmp al,0dh
je rend
cmp al,
je qt
cmp al,
je qt
cmp al,
jl err
cmp al,
jg err
jmp cnt
err: call perr
cnt: sub al,
mov bh,0
mov bl,al
mov ax,di
push bx
mov bx,10
mul bx
pop bx
add ax,bx
adc dx,0
mov si,dx
mov di,ax
loop rr
rend: call newline
mov bx,si
call itb
mov bx,di
call itb
call newline
jmp rf
qt: mov ax,4c00h
int 21h
itb: mov cx,16
rs: mov ax,bx
and ax,01h
mov dl,al
add dl,
push dx
shr bx,1
loop rs
mov cx,16
r: pop dx
mov ah,02h
int 21h
loop r
ret
newline:
mov ah,02h
mov dl,0dh
int 21h
mov dl,0ah
int 21h
ret
perr:
mov dx,offset est
mov ah,09h
int 21h
jmp rf
ret
code ends
end start
(2)数字字符计数
assume cs:code
stack segment
stk db 16 dup (0)
stack ends
code segment
start: mov ax,stack
mov ss,ax
mov sp,0
mov bx,0
rc: mov ah,01h
int 21h
cmp al,0dh
je brk
cmp al,
jl n
cmp al,
jg n
inc bx
n: jmp rc
brk: call show_num
mov ax,4c00h
int 21h
show_num:
mov si,0
rs: mov ax,bx
mov cl,10
div cl ;ah:al div cl ah存放余数 al存放商
add ah,
mov dl,ah
push dx ;由低位到高位压入栈中
mov ah,0 ;ah清零
inc si
cmp ax,0
je rt
jmp rs ;被除数不为0则继续
rt: mov cx,si ;位数
s: pop dx
mov ah,02h
int 21h
loop s
ret
code ends
end start
实验结果
(1)数制转换
(2)数字字符计数