鱼C论坛

 找回密码
 立即注册
查看: 3133|回复: 7

[汇编作业] 实验6 实践课程中的程序

[复制链接]
发表于 2020-4-4 13:53:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
还不能发图,就发点比较重要的:
7.6大小写:
  1. assume cs:codesg,ds:datasg
  2. datasg segment
  3. db 'BaSiC'
  4. db 'MinIX';这两个在内存中挨着放:“BaSiCMinIX......”
  5. datasg ends

  6. codesg segment
  7. start:       
  8.         mov ax,datasg
  9.         mov ds,ax
  10.         mov bx,0
  11.         mov cx,5
  12. s1:
  13.         mov al,[bx]
  14.         and al,11011111b;将串中所有字符第6位置0以转化为大写
  15.         mov [bx],al
  16.         inc bx
  17.         loop s1;正因为两个字符串挨着放所以不将bx置0
  18.         mov cx,5
  19. s2:
  20.         mov al,[bx]
  21.         or al,00100000b;将串中所有字符第6位置1以转化为小写
  22.         mov [bx],al
  23.         inc bx
  24.         loop s2

  25.         mov ax,4c00H
  26.         int 21h
  27. codesg ends
  28. end start
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-4 14:09:34 | 显示全部楼层
还可以写成:
  1. assume cs:codesg,ds:datasg
  2. datasg segment
  3. db 'BaSiC'
  4. db 'MinIX'
  5. datasg ends

  6. codesg segment
  7. start:       
  8.         mov ax,datasg
  9.         mov ds,ax
  10.         mov bx,0
  11.         mov cx,5
  12. s:
  13.         mov al,0[bx]
  14.         and al,11011111b
  15.         mov [bx],al

  16.         mov al,5[bx]
  17.         or al,00100000b
  18.         mov 5[bx],al
  19.         inc bx
  20.         loop s

  21.         mov ax,4c00H
  22.         int 21h
  23. codesg ends
  24. end start
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-4 14:14:06 | 显示全部楼层
问题7.2
  1. assume cs:codesg,ds:datasg
  2. datasg segment
  3. db 'welcome to masm!'
  4. db '................';两个都有16个bytes
  5. datasg ends

  6. codesg segment
  7. start:       
  8.         mov ax,datasg
  9.         mov ds,ax
  10.         mov si,0
  11.         mov di,16
  12.         mov cx,8
  13. s:
  14.         mov ax,[si]
  15.         mov [di],ax
  16.         add si,2
  17.         add di,2
  18.         loop s

  19.         mov ax,4c00H
  20.         int 21h
  21. codesg ends
  22. end start
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-4 14:21:23 | 显示全部楼层
问题7.3改进7.2使代码行数更少
  1. assume cs:codesg,ds:datasg
  2. datasg segment
  3. db 'welcome to masm!'
  4. db '................'
  5. datasg ends

  6. codesg segment
  7. start:       
  8.         mov ax,datasg
  9.         mov ds,ax
  10.         mov si,0
  11.         mov cx,8
  12. s:
  13.         mov ax,[si]
  14.         mov 16[si],ax;刚犯了个蠢,[si+di] 的写法是错的
  15.         add si,2
  16.         loop s

  17.         mov ax,4c00H
  18.         int 21h
  19. codesg ends
  20. end start
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-4 14:34:54 | 显示全部楼层
问题7.6
  1. assume cs:codesg,ds:datasg
  2. datasg segment
  3. db '1. file         '
  4. db '2. edit         '
  5. db '3. search       '  
  6. db '4. view         '
  7. db '5. options      '
  8. db '6. help         '
  9. datasg ends

  10. codesg segment
  11. start:       
  12.         mov ax,datasg
  13.         mov ds,ax
  14.         mov bx,0
  15.         mov cx,6
  16. s:
  17.         mov al,[bx+3];这里如果al写成ax就会把第5个字符置0也就是"."
  18.         and al,11011111b
  19.         mov 3[bx],al
  20.         add bx,16
  21.         loop s

  22.         mov ax,4c00H
  23.         int 21h
  24. codesg ends
  25. end start
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-4 14:53:04 | 显示全部楼层
问题7.7和7.8
由于看过视频,上来就写出嵌套的正确形式
  1. assume cs:codesg,ds:datasg
  2. datasg segment
  3. db 'ibm             '
  4. db 'dec             '
  5. db 'dos             '  
  6. db 'vax             '

  7. datasg ends

  8. codesg segment
  9. start:       
  10.         mov ax,datasg
  11.         mov ds,ax
  12.         mov bx,0
  13.         mov cx,4
  14. s:
  15.         push cx
  16.         mov si,0
  17.         mov cx,3;由于push过cx了,结尾再pop cx回来,内部cx无论怎么改变都不影响外部循环
  18.         s0:
  19.                 mov al,[bx+si]
  20.                 and al,11011111b
  21.                 mov [bx+si],al
  22.                 inc si
  23.                 loop s0
  24.         add bx,16
  25.         pop cx
  26.         loop s

  27.         mov ax,4c00H
  28.         int 21h
  29. codesg ends
  30. end start
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-4 14:56:07 | 显示全部楼层
流风逸雪 发表于 2020-4-4 14:53
问题7.7和7.8
由于看过视频,上来就写出嵌套的正确形式

开头忘记申明栈地址了,以后注意一下吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-4 15:19:54 | 显示全部楼层
问题7.9:
  1. assume cs:codesg,ss:stacksg,ds:datasg;总之这里声明的东西下面都要写上
  2. stacksg segment
  3. dw 0,0,0,0,0,0,0,0;这里没写会报错
  4. stacksg ends

  5. datasg segment
  6. db '1. display      '
  7. db '2. brows        '
  8. db '3. replace      '  
  9. db '4. modify       '

  10. datasg ends

  11. codesg segment
  12. start:       
  13.         mov ax,stacksg
  14.         mov ss,ax
  15.         mov sp,16
  16.         mov ax,datasg
  17.         mov ds,ax

  18.         mov bx,0
  19.         mov cx,4
  20. s:
  21.         push cx
  22.         mov si,0
  23.         mov cx,4
  24.         s0:
  25.                 mov al,[bx+3+si]
  26.                 and al,11011111b
  27.                 mov [bx+3+si],al
  28.                 inc si
  29.                 loop s0
  30.         add bx,16
  31.         pop cx
  32.         loop s

  33.         mov ax,4c00H
  34.         int 21h
  35. codesg ends
  36. end start
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-9 11:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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