assume cs:code
data segment
db 15 dup(0)
data ends
code segment
start:
mov ax,12666
mov dx,55
mov bx,data
mov ds,bx
mov si,0
call ddtoc
mov dx,0803h
mov cl,10
call cle
call show_str
mov ax,4c00h
int 21h
ddtoc:
;将ddword型数据转变为表示十进制数的以零结尾字符串,
;dxax=ddword型数据,ds:si指向字符串的首地址
push ax
push cx
push dx
push bx
push sp
push bp
push si
push di ;保存所有 20
mov cx,0
mov bx,10
mov dx,0
dnow:
sub ax,dx
push cx
mov cx,bx
call divdw
mov bp,cx
pop cx
push bp
inc cx
add ax,dx
or ax,ax
jnz dnow
dreturn:
pop ax
or al,30h
mov [si],al
inc si
loop dreturn
mov byte ptr [si],0
pop di
pop si
pop bp
pop sp
pop bx
pop dx
pop cx
pop ax
ret
cle:
push ax
push cx
push dx
push bx
push sp
push bp
push si
push di
push es
mov cx,4000
mov ax,0b800h
mov es,ax
nnow:
mov bx,cx
sub bx,1
mov byte ptr es:[bx],0
loop nnow
pop es
pop di
pop si
pop bp
pop sp
pop bx
pop dx
pop cx
pop ax
ret
dtoc:
;将word型数据转变为表示十进制数的以零结尾字符串,
;ax=word型数据,ds:si指向字符串的首地址
push ax
push cx
push dx
push bx
push sp
push bp
push si
push di ;保存所有非段寄存器 20
mov cx,0
mov bx,10
now:
mov dx,0
div bx
push dx
inc cx
or ax,ax
jnz now
return:
pop ax
or al,30h
mov [si],al
inc si
loop return
mov byte ptr [si],0
pop di
pop si
pop bp
pop sp
pop bx
pop dx
pop cx
pop ax
ret
show_str:
;制定位置 制定颜色 显示用零结尾的字符串 40
;dh=行号(0-24)dl=列号(0-79) cl=颜色 ds:si指向字符串首地址
;7 6 5 4 3 2 1 0
;BL R G B I R G B
;闪烁 背景 高亮 前景
;R红色 G绿色 B蓝色
push ax
push cx
push dx
push bx
push sp
push bp
push si
push di
push es
mov ax,0b800h
mov es,ax
mov al,dh
mov ah,0
mov dh,80*2
mul dh ;al*dh,fang ax
mov dh,0
shl dl,1 ;dl*2,luoji zuoyi 1wei
add ax,dx
mov di,ax
mov ah,cl
mov ch,0
cld ;清除方向标志 60
@b:
lodsb ;al=ds:[si],si+1
or al,al
mov cl,al
jz @f
stosw ;es:[di]=ax,di+2
jmp short @b
@f:
pop es
pop di
pop si
pop bp
pop sp
pop bx
pop dx
pop cx
pop ax
ret
divdw:
;进行无溢出的除法,被除数为dword,除数word,结果dword
;ax=低16 dx=dword高16,cx除数
;返回dx=商高16,ax低16,cx余数
push bp
push ax
push dx
push cx
mov bp,sp
mov dx,0
mov ax,[bp+2]
div cx
push dx
mov dx,ax
push dx
mov bp,sp
mov dx,[bp+2]
mov ax,[bp+8]
div word ptr [bp+4]
mov cx,dx
pop dx
pop bp
pop bp
pop bp
pop bp
pop bp
ret
code ends
end start
data segment
db 15 dup(0)
data ends
code segment
start:
mov ax,12666
mov dx,55
mov bx,data
mov ds,bx
mov si,0
call ddtoc
mov dx,0803h
mov cl,10
call cle
call show_str
mov ax,4c00h
int 21h
ddtoc:
;将ddword型数据转变为表示十进制数的以零结尾字符串,
;dxax=ddword型数据,ds:si指向字符串的首地址
push ax
push cx
push dx
push bx
push sp
push bp
push si
push di ;保存所有 20
mov cx,0
mov bx,10
mov dx,0
dnow:
sub ax,dx
push cx
mov cx,bx
call divdw
mov bp,cx
pop cx
push bp
inc cx
add ax,dx
or ax,ax
jnz dnow
dreturn:
pop ax
or al,30h
mov [si],al
inc si
loop dreturn
mov byte ptr [si],0
pop di
pop si
pop bp
pop sp
pop bx
pop dx
pop cx
pop ax
ret
cle:
push ax
push cx
push dx
push bx
push sp
push bp
push si
push di
push es
mov cx,4000
mov ax,0b800h
mov es,ax
nnow:
mov bx,cx
sub bx,1
mov byte ptr es:[bx],0
loop nnow
pop es
pop di
pop si
pop bp
pop sp
pop bx
pop dx
pop cx
pop ax
ret
dtoc:
;将word型数据转变为表示十进制数的以零结尾字符串,
;ax=word型数据,ds:si指向字符串的首地址
push ax
push cx
push dx
push bx
push sp
push bp
push si
push di ;保存所有非段寄存器 20
mov cx,0
mov bx,10
now:
mov dx,0
div bx
push dx
inc cx
or ax,ax
jnz now
return:
pop ax
or al,30h
mov [si],al
inc si
loop return
mov byte ptr [si],0
pop di
pop si
pop bp
pop sp
pop bx
pop dx
pop cx
pop ax
ret
show_str:
;制定位置 制定颜色 显示用零结尾的字符串 40
;dh=行号(0-24)dl=列号(0-79) cl=颜色 ds:si指向字符串首地址
;7 6 5 4 3 2 1 0
;BL R G B I R G B
;闪烁 背景 高亮 前景
;R红色 G绿色 B蓝色
push ax
push cx
push dx
push bx
push sp
push bp
push si
push di
push es
mov ax,0b800h
mov es,ax
mov al,dh
mov ah,0
mov dh,80*2
mul dh ;al*dh,fang ax
mov dh,0
shl dl,1 ;dl*2,luoji zuoyi 1wei
add ax,dx
mov di,ax
mov ah,cl
mov ch,0
cld ;清除方向标志 60
@b:
lodsb ;al=ds:[si],si+1
or al,al
mov cl,al
jz @f
stosw ;es:[di]=ax,di+2
jmp short @b
@f:
pop es
pop di
pop si
pop bp
pop sp
pop bx
pop dx
pop cx
pop ax
ret
divdw:
;进行无溢出的除法,被除数为dword,除数word,结果dword
;ax=低16 dx=dword高16,cx除数
;返回dx=商高16,ax低16,cx余数
push bp
push ax
push dx
push cx
mov bp,sp
mov dx,0
mov ax,[bp+2]
div cx
push dx
mov dx,ax
push dx
mov bp,sp
mov dx,[bp+2]
mov ax,[bp+8]
div word ptr [bp+4]
mov cx,dx
pop dx
pop bp
pop bp
pop bp
pop bp
pop bp
ret
code ends
end start