汇编语言——数值显示(子程序)
程序员文章站
2024-02-02 15:50:40
...
程序如下:
assume cs:code
data segment
db 10 dup (0)
data ends
code segment
start:
mov ax,12666
mov bx,data
mov ds,bx
mov si,0
call dtoc
mov dh,8
mov dl,3
mov cl,2
call show_str
mov ax,4c00h
int 21h
dtoc:
push dx
push cx
push ax
push si
push bx
mov bx,0;存放数值位数
s1:
mov cx,10d
mov dx,0
div cx
mov cx,ax
jcxz s2
add dx,30h;余数加30h得相应的ASCII码
push dx;逐个保存
inc bx;统计数值位数
jmp short s1
s2:
add dx,30h
push dx
inc bx ;最后一位cx未统计到(ax=cx=0,在s2再转换一次
mov cx,bx;总共bx为进栈
mov si,0
s3:
pop ax ;将入栈数值逐个输出
mov [si],al ;根据要求 存放到di:[si]地址处
inc si
loop s3
okey:
pop bx
pop si
pop ax
pop cx
pop dx
ret
show_str:
push bx
push cx
push si
mov al,0a0h
dec dh
mul dh
mov bx,ax
mov al,2
mul dl
sub ax,2
add bx,ax
mov ax,0b800h
mov es,ax
mov di,0
mov al,cl
mov ch,0
s:
mov cl,ds:[si]
jcxz ok
mov es:[bx+di],cl
mov es:[bx+di+1],al
inc si
add di,2
jmp short s
ok:
pop si
pop cx
pop bx
ret
code ends
end start
上一篇: 2.1 ECMAScript基础
下一篇: 汇编语言||关于单片机数据的寻址方式总结