做过的练习,改了一下。
程序代码:
assume cs:code,ds:data
data segment
mem db 1,2,0,0,0,0,0,0,0,3,0,0,4,0,5,6,0,0,0,0,0,7
count db 0
data ends
code segment
start:
mov ax,data
mov ds,ax
mov bx,offset mem
mov cx,lengthof mem
push bx
push cx
;
mov ah,2
d1:
mov dl,[bx]
add dl,30h
int 21h
mov dl,20h
int 21h
inc bx
loop d1
mov dl,13
int 21h
mov dl,10
int 21h
pop cx
pop bx
s1:
push cx
mov al,[bx]
cmp al,0
jz move
jmp jx
move:
inc count
mov si,bx
s2:
mov al,[si+1]
mov [si],al
inc si
loop s2
dec bx
jx:
pop cx
inc bx
loop s1
;
mov cx,bx
mov bx,offset mem
mov ah,2
d2:
mov dl,[bx]
add dl,30h
int 21h
mov dl,20h
int 21h
inc bx
loop d2
;
mov ah,2
mov dl,13
int 21h
mov dl,10
int 21h
;
mov al,count
cmp al,9
ja d3
mov dl,al
add dl,30h
int 21h
jmp done
d3:
mov ah,0
mov bl,10
div bl
push ax
mov ah,2
mov dl,al
add dl,30h
int 21h
pop ax
mov dl,ah
mov ah,2
add dl,30h
int 21h
done:
mov ah,4ch
int 21h
code ends
end start
运行结果:
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
[
本帖最后由 ansic 于 2011-6-13 11:02 编辑 ]