8086系列(14):子程序参数传送----通过寄存器传送参数

题目

十进制到十六进制数转换程序。程序要求从键盘取得一个十进制数,然后把该数以十六进制形式在屏幕上显示出来。

思路

主程序部分十分简单,调用一个子程序DECIBIN实现从键盘取得十进制数并把它转成二进制数;另一个子程序BINHEX把此二进制数以十六进制数显示出来。另外用CRLF子程序取得回车和换行的效果,BX寄存器用来在过程间传递要转换的数。

代码

;;;;;;;;通过寄存器传递参数;;;;;;;;;;;
datasg segment

datasg ends
;---------------------------
codesg segment
    assume cs:codesg,ds:datasg,es:datasg

;----------主函数------------
main proc far
start:
    push ds
    sub ax,ax
    push ax
    mov ax,datasg
    mov ds,ax
    mov es,ax
;--------------
repeat:              ;死循环
    call decibin
    call crlf
    call binihex
    call crlf
    jmp repeat
main endp
;----------主函数-------------

;-----------decibin----------
decibin proc near
    mov bx,0           ;清理bx
newchar:
    mov ah,1
    int 21h
    sub al,30H       
    jl exit           ;<0 则退出
    cmp al,9d    ;>9也退出
    jg exit
    cbw               ;byte in AL to work in AX
;Multiply number in BX by 10 decimal
    xchg ax,bx        
    mov cx,10d        ;ax*bx
    mul cx 
    xchg ax,bx 
    add bx,ax         ;bx = ax*10 + bx
    jmp newchar
exit:
    ret
decibin endp
;-----------decibin----------

;-----------binihex----------
binihex proc near
    mov ch,4
rotate:
    mov cl,4
    rol bx,cl
    mov al,bl
    and al,0fh
    add al,30H
    cmp al,3ah
    jl printit
    add al,7h
printit:
    mov dl,al
    mov ah,2
    int 21h
    dec ch
    jnz rotate
    ret
binihex endp
;-----------binihex----------

;---------- crlf-------------
crlf proc near
    mov dl,0dh
    mov ah,2
    int 21h
    mov dl,0ah
    mov ah,2
    int 21h
    ret
crlf endp
;---------- crlf-------------

codesg ends
end start

调试

反汇编

在这里插入图片描述
在未进入decibin子程序时查看堆栈段的内容,075A是ds的偏移地址,0000是push ax(0)

在这里插入图片描述
进入子程序后查看堆栈段,Push了(IP)

在这里插入图片描述
在这里插入图片描述
查看decibin子程序

在这里插入图片描述
子程序decibin结束后,bx=123

在这里插入图片描述

紧接着调用子程序CRLF

在这里插入图片描述
再者调用binihex

在这里插入图片描述
最终查看结果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值