问题描述
- 王爽汇编语言实验10.3 div这一步怎么了
-
将数据12666以十进制的形式在屏幕的8行3列,用绿色显示出来。我的程序是
assume cs:code,ds:data
data segment
db 10 dup(0)
data endscode segment
start:
mov ax,12666
mov bx,data
mov ds,bx
mov si,0
call dtocmov dh,8 mov dl,3 mov cl,2 call show_str
dtoc:
push ax
push bx
push cx
push si
push di
mov ch,0
mov si,0
mov di,0001htransform:
mov bl,10d
div bl
mov cl,ah ;余数写入cl
jcxz readin ;判定余数是否为0
add cl,30h ;得到该数的ascii码
mov [di],clinc di
inc si ;记录长度
mov ah,0
jmp short transform
readin:
mov cx,si
mov si,0
mov al,[di]
mov [si],al
inc si
dec di
loop readin ;因为是逆序,所以用栈调整为顺序
mov byte ptr [si],0 ;结尾标志pop di pop si pop cx pop bx pop ax ret
show_str:
push ax
push cx
push si
push di
;获取对应显存地址mov ax,160
mul dhmov bx,ax ;bx=160*dh
mov ax,2
mul dl
add bx,ax ;bx=160*dh+2*dl
mov al,cl
mov cl,0
show:
mov cl,[si]jcxz ok ;判定字符串是否结束
;写入显存mov es:[bx+di],cl
mov es:[bx+di].1,al
add di,2
inc si
jmp short show
ok:
pop cx
pop ax
pop si
pop di
retcode ends
end start