汇编语言_子程序

子程序概念

子程序调用指令CALL
格式为 CALL 子程序名
CALL相当于JMP
子程序名 相当于 标号
子程序执行完返回到CALL下一句的语句执行

在子程序中用RET 返回

子程序伪指令定义

子程序名PROC属性(Far,Near)

子程序名 ENDP
如果主程序是被执行的第一个程序,属性应为Far
在这里插入图片描述

代码举例

用子程序多次输入一个65535以内的十进制数并以十六进制数显示

data segment
x dw 0
mess1 db 0dh,0ah,'input dec=$'
mess2 db 0dh,0ah,'input out hex=$'
hex db '0123456789ABCDEF'
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
;主程序
let0:
mov x,0
lea dx,mess1
mov ah,9
int 21h
call let1
call let2
jmp let0
out1:
mov ah,4ch
int 21h


let1:
mov ah,1
int 21h
com al,27//判断是否为	esc
jz out1:
sub al,30h
jl exit
cmp al,9
jg exit
mov ah,0
xchg ax,x
mov cx,10
mul cx
xchg ax,x
add x,ax
jmp let1
exit:ret


let2: //查表显示16进制
lea dx,mess2
mov ah,9
int 21h
mov bx,x
mov ch,4
mov cl,4


rept1:
rol bx,cl
mov al,bl
and ax,000fh
mov si,ax
mov dl,hex[si]
mov ah,2
int 21h
dec ch
jnz rept1
ret
code ends
end start
原创文章 12 获赞 11 访问量 398

猜你喜欢

转载自blog.csdn.net/FRANK48691/article/details/106164264