找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 714|回复: 0
打印 上一主题 下一主题
收起左侧

微机原理与接口技术汇编程序-删除字符串开头和结尾的空格

[复制链接]
跳转到指定楼层
楼主
该程序实现了将一个字符串开头和结尾的任意多个空格去除然后显示字符串内容。
可以根据需要输入不同的字符串,程序将自动识别并删除开头和结尾的空格。
适合本科阶段学习微机原理与接口技术的同学练习参考。


  1. ;Remove spaces at the beginning and end of a string

  2. DATA SEGMENT
  3.     string DB ' a string for testing. ',0
  4.     length DW $-string    ;length of the string
  5. DATA ENDS

  6. CODE SEGMENT
  7.     ASSUME CS:CODE, DS:DATA
  8. START:
  9.     MOV AX, DATA
  10.     MOV DS, AX
  11.    
  12.     LEA SI, string
  13.    
  14. BEGIN:    ;Set beginning pointer of the new string
  15.     CMP [SI], ' '    ;Find spaces, skip them
  16.     JNE NEXT
  17.     INC SI
  18.     JMP BEGIN

  19. NEXT:   ;Shift DI to the end of the initial string
  20.     LEA DI, string
  21.     MOV AX, length    ;Load length of the string to AX
  22.     ADD DI, AX      
  23.     SUB DI, 2       ;Move DI to the end of the string
  24.    
  25. THIRD:   ;Shift DI to the end of the new string
  26.     CMP [DI], ' '
  27.     JNE LAST
  28.     DEC DI
  29.     JMP THIRD
  30.    
  31. LAST:   ;display the new string on screen
  32.     INC DI
  33.     MOV byte ptr[DI], '0'   ;string ends with 0
  34.     INC DI
  35.     MOV byte ptr[DI], '


  36.    
  37.     MOV AH, 09H
  38.     MOV DX, SI      ;Set offset adress
  39.     INT 21H
  40.    
  41. CODE ENDS
  42. END START
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表