|
主题 : : 实验一总算完成了有很多不足知处望高手多提意件 [待解决] |
回复[ 2次 ]
点击[ 441次 ] | |
荣誉值:0
信誉值:0
注册日期:2009-10-07 14:18 |
assume cs:code
data segment
db 10 dup(0)
data ends
code segment
start:mov ax,12666
mov bx,data
mov ds,bx
mov ss,bx
mov bx,0
mov sp,bx
mov si,0
call dtoc
mov dh,8
mov dl,3
mov cl,2
call show_str
mov ax,4c00h
int 21h
show_str: dec dh
dec dl
mov ax,0
mov al,dh
mov bx,0
mov bl,10
mul bl
mov bx,ax
mov ax,0b800h
add ax,bx
mov es,ax
mov ax,0
mov al,dl
add al,dl
mov bx,ax
mov di,0
mov ch,cl
ok: mov cl,[si]
push cx
mov ch,0
jcxz return
pop cx
mov es:[bx+di],cx
add di,2
inc si
jmp short ok
return: pop cx
ret
dtoc: mov cx,0ah
call divdw ;传入ax,cx的值进行除法运算
push cx ;传送div的返回值cx
inc di
mov cx,dx
jcxz goon
jmp short dtoc
goon: mov cx,0ah ;没有判断是一种不负责任的行为
call divdw
push cx
inc di
mov cx,ax
jcxz re_num
jmp short goon
re_num: mov si,0
mov cx,di
s: pop ax
mov bx,030h
add ax,bx
mov ds:[si],al
inc si
loop s
mov si,0
ret
divdw: push ax ;记得要保存现场
mov ax,dx
div cl
mov bx,ax ;用bx过度然后用把商存入dx然后还原现场压入dx取出bx传入dx使dh为0,dx为div
结果的余数
mov ah,0
mov dx,ax ;一点总结子程序用到了dx,cx,ax,bx,dh,dl,ah,其实记得还原栈中的数据
pop ax
push dx ;结果问题子程序传入的是ax,dx,cx其中cx为除数,ax,dx为被除数,ret之后dx高
,ax低 cx为余数,bx变形了
mov dx,bx
mov dl,dh
mov dh,0
div cx
mov cx,dx
pop dx
ret
code ends
end start | | |