assume cs:code
data segment
db 10 dup (0)
data ends
stack segment
db 20h dup (0)
stack ends
code segment
start:
mov ax,12666
mov dx,0
mov bx,data
mov ds,bx
mov bx,stack
mov ss,bx
mov sp,20h
mov si,0
s1:mov cx,10
call dtoc;计算ax中每一位的数
jcxz s3
add cx,30h
mov ds:[si],cl
inc si
jmp s1
s3:call arund;将ds中的数掉头.si为要掉头的byte个数减1
s0:mov dh,8
mov dl,3
mov cl,2
call show_str;显示ds中的数
mov ax,4c00h
int 21h
arund:
mov bx,0
mov dh,0
e:mov cx,si
mov dl,ds:[bx]
push dx
inc bx
sub cx,bx
jcxz e0
jmp e
e0:mov cx,si
mov bx,0
e1:pop ax
mov ds:[bx],al
inc bx
loop e1
ret
dtoc:
push ax
mov ax,dx
mov dx,0
div cx
mov bx,ax;商放进bx中保存,余数在dx中正好为低16做除法时代高位
pop ax
div cx
mov cx,dx
mov dx,bx
ret
show_str:
dec dh
mov al,160
mul dh
mov bx,ax
dec dl
mov al,2
mul dl
add bx,ax
mov ax,0b800h
mov es,ax;段地址
mov di,bx;做偏移
mov bx,0
mov ah,cl
mov ch,0
s:mov cl,ds:[bx]
jcxz ok
mov es:[di],cl
mov es:[di+1],ah
inc bx
inc di
inc di
jmp s
ok:ret
code ends
end start