17课作业 dtoc dword型
本帖最后由 sdnyzjzx 于 2010-12-27 21:57 编辑抛砖引玉,敬请指正!
assume cs:code
data segment
dw 100 dup (0)
jdd 1024,1234567,238763,887766,345543,99990088
data ends
stack segment
dw 100 dup (0)
stack ends
code segment
start:mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,200
mov bx,offset j ;要显示数据的偏移位置
mov si,0 ;保存数据转化为字符后偏移位置
mov di,0
mov cx,6 ;要转化数据的个数
_main:
push cx
push bx
mov cx,0ah
mov ax,
mov dx,
call dtoc
mov bx,8*160 ;第8行开始显示
add bx,di
call show_str
pop bx
pop cx
add bx,4
loop _main
mov ax,4c00h
int 21h
dtoc:
_s0: call divdw
cmp dx,0 ;商的高位是否为0
jnz _s1
cmp ax,0 ;商的低位是否为0
jnz _s1
add cx,30h
mov ,cx
ret ;数据转化完成,返回
_s1: ;写入转化完成的数据为字符
add cx,30h
mov ,cx
inc si
mov cx,0ah
jmp _s0
show_str:
mov ax,0b800h
mov es,ax
xianshi:
mov al,
mov byte ptr es:,al ;要显示的字符
mov byte ptr es:,2 ;要显示字符的颜色
cmp si,0
jz ok
dec si
add bx,2
jmp xianshi
ok: add di,20 ;显示字符宽度
ret
divdw: push si ;dword型数值除法运算
push di
mov si,ax ;save ax(L)t
mov ax,dx
mov dx,0
div cx ;(H/N)
mov di,dx ;save rem(H/N)
push di
mov dx,0 ;int(H/N)
mov di,2
mul di
mov bx,32768 ;int(H/N)*65536
mul bx
pop di
push ax ;save int(H/N)*65536
push dx
mov ax,di ;Load rem(H/N)
mov di,2
mul di
mul bx
add ax,si ;rem(H/N)*65536+L
div cx
mov si,ax
mov cx,dx
pop dx
pop ax
pop di
add ax,si
pop si
ret
code ends
end start
Good Job~!
页:
[1]