data segment;数据段
string1 db 'please input a string:',13,10,'$';提示字符串
data ends
code segment;代码段
assume cs:code,ds:data
main proc far;段间调用
start:
mov ax,data
mov ds,ax
lea dx,string1;取有效地址
mov ah,09h;显示字符串
int 21h
mov cx,0;将0赋给cx
call crlf;调用子程序
call shuru
call crlf2
main endp
shuru proc near;段内调用
input:
mov ah,01h;键盘输入并回显
int 21h;随机读文件
cmp al,0dh;用户输入回车时代表输入结束
jz crlf3;条件转移指令,跳转到crlf3
push ax;将接受的字符入栈
inc cx;cx加1,计算字符数
jmp input;无条件转移指令,跳转到input
crlf3:
mov dl,0dh;回车
mov ah,02h;显示功能
int 21h;21号功能:随机读文件
mov dl,0ah;换行
mov ah,2
int 21h
jmp output
output:
pop dx;出栈,实现逆序输出
mov ah,02h;DOS系统功能调用,一个字符一个字符输出
int 21h
loop output;循环指令,循环次数由cx指
汇编语言实现字符串逆序输出
最新推荐文章于 2024-04-13 18:53:45 发布