汇编语言实现字符串逆序输出

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指

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值