鱼C论坛

 找回密码
 立即注册
查看: 4039|回复: 8

[争议讨论] 比较这两段代码,看看哪个更正确

[复制链接]
发表于 2011-7-30 21:05:07 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 weixianlang 于 2011-7-31 09:07 编辑

    编程,向内存0:200~0:23F依次传送数据0~63(3FH),程序中只能使用9条指令,9条指令中包括“mov ax,4c00h”和“int 21h”。
   比较这两段代码,看看哪个更正确
第一种:
  1. assume cs:codesg
  2. codesg segment
  3. mov ax,0020h
  4. mov ds,ax
  5. mov bl,0
  6. mov cx,40h
  7. s: mov [bx],bl
  8. inc bl
  9. loop s

  10. mov ax,4c00h
  11. int 21h

  12. codesg ends
  13. end
复制代码


第二种:
  1. assume cs:code
  2. code segment

  3. start:mov ax,0020h
  4. mov ds,ax
  5. mov bx,0
  6. mov cx,63
  7. s: mov [bx],bl
  8. inc bx
  9. loop s

  10. mov ax,4c00h
  11. int 21h

  12. code ends
  13. end start
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-7-31 08:39:39 | 显示全部楼层
英雄所见略同
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-7-31 12:01:46 | 显示全部楼层
本帖最后由 china0008 于 2011-8-2 09:03 编辑

版主老师您好!
       我用loop循环20h次,虽然改变了指定空间的内存内容,但是我却用了12行代码,感觉很复杂。我思考了很久也找不出怎么把这几行代码进行优化,希望老师多多指点!再一次谢谢老师的教导。以下是我写的代码:

  1. assume cs:code
  2. code segment
  3.           start: mov ax,0020h
  4.           mov ds, ax
  5.           mov bl,0
  6.           mov cx,20h

  7. s:      mov al,bl
  8.           inc bl
  9.           mov ah,bl
  10.           mov ds:[bx-1],ax
  11.           inc bl
  12.           loop s
  13.   
  14.          mov ax,4c00h
  15.          int 21h
  16. code ends
  17. end start
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-7-31 14:41:06 | 显示全部楼层
死亡请帖 发表于 2011-7-31 14:23
我来给你改下:
assume cs:code
code segment

改得真好,方法新,还用cx给ds了地址。
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-10-3 09:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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