jcxz跳转后,紧随其后的代码不会执行,要特别注意出栈入栈是否匹配
; e10_3.asm
assume cs:code,ss:stack,ds:data
data segment
db 16 dup (0)
data ends
stack segment
db 64 dup (0)
stack ends
code segment
start:
mov ax,stack
mov ss,ax
mov sp,64
mov ax,12666
mov bx,data
mov ds,bx
mov si,0 ; set ds:[si]
call dtoc
mov dh,8
mov dl,3
mov cl,2
call show_str
mov ax,4c00h
int 21h
dtoc:
push ax
push bx
push cx
push dx
push ds
push si
push di ; to record the digits to output
mov di,0
mov bx,10 ; set divisor
s_dtoc:
mov dx,0 ; set (dx),(ax)
div bx ; [(dx) * 10000h + (ax)] / 10
; result (dx) = remainder, (ax) = quotient
add dx, 30h
push dx ; save the remainder to stack
inc di
push cx
mov cx,ax
jcxz ok_dtoc ; to see if quotient (ax) = 0
pop cx ; this wouldn't be excuted when (ax) = 0
inc cx ; (cx) = (cx) - 1 after loop s
loop s_dtoc
ok_dtoc:
pop cx
mov cx,di
s1_dtoc:
pop dx
mov ds:[si], dl ; (dx) < 10 + 30H
inc si
loop s1_dtoc
pop di
pop si
pop ds
pop dx
pop cx
pop bx
pop ax
ret
show_str:
push cx
push dx
push ds
push si
push ax
push es
push bp
push di
mov ax,0b800h
mov es,ax
mov al,160
mul dh
mov bp,ax
mov al,2
mul dl
mov di,ax
s: push cx
mov ch,0
mov cl,ds:[si]
jcxz ok
pop cx
mov al,ds:[si]
mov es:[bp+di],al
mov es:[bp+di+1],cl
add di,2
inc si
inc cx
loop s
ok:
pop cx
pop di
pop bp
pop es
pop ax
pop si
pop ds
pop dx
pop cx
ret
code ends
end start