|
发表于 2012-6-30 21:37:17
|
显示全部楼层
assume cs:code,ds:data,ss:stack
data segment
db 16 dup(0)
data ends
stack segment
db 16 dup(0)
stack ends
code segment
start: mov ax,data ax=data
mov ds,ax ds=data
mov ax,stack ax=stack
mov ss,ax ss=stack
mov sp,16 sp=16
mov ax,12666 ax=12666
mov si,0 si=0
call dtoc 跳到标号处
返回后,ax=0,bx=6,cx=0,dx=36h,si=5
data:0=31h data:1~4=36h,data:5~15=0
mov dh,8
mov dl,3
mov si,0
mov bl,2 bx=2
call show_str 跳到标号处
返回后各内存值:
bd04:0=31h,bd04:1~8=36h
(这个就是你执行后的结果了)
mov ax,4c00h
int 21h
dtoc: mov dx,0 dx=0......
mov bx,10 bx=10.....
div bx ax=1266,dx=6,ax=126,dx=6,....ax=0,dx=1
mov cx,ax cx=1266,cx=126,cx=12,cx=1,cx=0
add dx,30h dx=36h,dx=36h,dx=36h,dx=36h,dx=31h
push dx pop 36,pop 366,pop 36h,pop36h,pop31h
inc si si=1,si=2,si=3,si=4,si=5
jcxz dtoc_ok 第5次cx=0,跳
jmp short dtoc 此处跳转4次
dtoc_ok: mov cx,si cx=5
mov si,0 si=0
dtoc_s: pop bx bx=31h 第二次:bx=36h ..........bx=36h
mov ds:[si],bl data:0=31h data:1=36h .........一直到data:4=36h
inc si si=1 si=2 ..........
loop dtoc_s 跳4次 si最后=5
mov ds:[si],byte ptr 0 data:5和data:6的值无改变,为0
ret 返回
show_str: mov al,160 al=160=a0h
mul dh ax=1280
dec ax ax=1279
mov dx,ax dx=1279
mov al,2 al=2
mul dl ax=6
dec ax ax=5
add ax,dx ax=1284
add ax,0b800h ax=bd04h
mov es,ax es=bd04h
mov bp,0 bp=0
mov ch,0 ch=0
show_s: mov cl,ds:[si] cl=data:0=31h 第二次:cl=data:1=36h ....cl=data:4=36h cl=data:5=0
jcxz show_ok cx=31h cx=36h ....cl=36h cx=0 跳
mov es:[bp],cl bd04:0=31h, bd04:2=36h ....bd04:8=36h
即第7行第2个
从第0行第0个开始数
mov es:[bp+1],bl bd04:1=36h bd04:3=36h ....bd04:7=36h
inc si si=1 si=2 ....si=5
add bp,2 bp=2 bp=4 ....bp=10
jmp short show_s 跳 跳 ....不跳
show_ok: ret 返回
code ends
end start
|
|