assume cs:code,ss:stack
data segment
db 10 dup (0)
data ends
stack segment
db 128 dup (0)
stack ends
code segment
start: mov ax,12666
mov bx,data
mov ds,bx
mov si,0
mov bx,stack
mov ss,bx
mov sp,128
call dtoc
mov dh,8
mov dl,3
mov cl,2
call show_str
mov ax,4c00h
int 21h
;----------------显示运算----------------------------
show_str: mov ax,0b800h
mov es,ax
mov si,0
mov al,160
mul dh
mov di,ax
add dl,dl
mov bl,dl
mov bh,0
mov al,cl
s: mov cl,[si]
mov ch,0
jcxz ok
mov cl,[si]
mov es:[bx+di],cl
mov es:[bx+di+1],al
inc si
add di,2
jmp short s
ok: ret
;-----------------字符串运算-------------------------
dtoc:
push ax ;子程序调用的寄存器入栈
push bx ;子程序调用的寄存器入栈
push cx ;子程序调用的寄存器入栈
push dx ;子程序调用的寄存器入栈
push ds ;子程序调用的寄存器入栈
mov cx,10 ;此cx代表除数
mov dx,0
call divdw
mov dx,cx
add dx,30h
push dx ;注意这里的第一个dx进栈了
mov cx,ax
jcxz ok1
call dtoc
ok1: pop dx ;注意这里的第二个dx出栈了,这2个dx是一样吗 ,sp指向不同了吧
mov ds:[si],dx
inc si
mov byte ptr ds:[si],0
pop ds ;子程序调用的寄存器出栈
pop dx ;子程序调用的寄存器出栈
pop cx ;子程序调用的寄存器出栈
pop bx ;子程序调用的寄存器出栈
pop ax ;子程序调用的寄存器出栈
ret
;-----------------除法运算---------------------------
divdw:
mov bx,ax
mov ax,dx
mov dx,0
div cx
push ax ;商入栈
mov ax,bx
div cx
mov cx,dx
pop dx ;商出栈
ret
code ends
end start |