鱼C论坛

 找回密码
 立即注册
查看: 2733|回复: 1

[技术交流] 花了我这么长时间终于搞定了,实验10第三个,贴出来晒晒,不能白写了

[复制链接]
发表于 2012-1-11 22:28:56 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 415968430 于 2012-1-11 22:32 编辑

亲测mov ax,12666显示绿色的12666
  1. assume cs:code

  2. data segment
  3. db 10 dup (0)
  4. data ends

  5. stack segment
  6. db 20h dup (0)
  7. stack ends

  8. code segment
  9. start:
  10. mov ax,12666
  11. mov dx,0
  12. mov bx,data
  13. mov ds,bx
  14. mov bx,stack
  15. mov ss,bx
  16. mov sp,20h
  17. mov si,0
  18. s1:mov cx,10
  19. call dtoc;计算ax中每一位的数
  20. jcxz s3
  21. add cx,30h
  22. mov ds:[si],cl
  23. inc si
  24. jmp s1
  25. s3:call arund;将ds中的数掉头.si为要掉头的byte个数减1





  26. s0:mov dh,8
  27. mov dl,3
  28. mov cl,2
  29. call show_str;显示ds中的数

  30. mov ax,4c00h
  31. int 21h


  32. arund:
  33. mov bx,0
  34. mov dh,0
  35. e:mov cx,si
  36. mov dl,ds:[bx]
  37. push dx
  38. inc bx
  39. sub cx,bx
  40. jcxz e0
  41. jmp e
  42. e0:mov cx,si
  43. mov bx,0
  44. e1:pop ax
  45. mov ds:[bx],al
  46. inc bx
  47. loop e1
  48. ret



  49. dtoc:
  50. push ax
  51. mov ax,dx
  52. mov dx,0
  53. div cx
  54. mov bx,ax;商放进bx中保存,余数在dx中正好为低16做除法时代高位
  55. pop ax
  56. div cx
  57. mov cx,dx
  58. mov dx,bx
  59. ret

  60. show_str:
  61. dec dh
  62. mov al,160
  63. mul dh
  64. mov bx,ax
  65. dec dl
  66. mov al,2
  67. mul dl
  68. add bx,ax
  69. mov ax,0b800h
  70. mov es,ax;段地址
  71. mov di,bx;做偏移
  72. mov bx,0
  73. mov ah,cl
  74. mov ch,0
  75. s:mov cl,ds:[bx]
  76. jcxz ok
  77. mov es:[di],cl
  78. mov es:[di+1],ah
  79. inc bx
  80. inc di
  81. inc di
  82. jmp s
  83. ok:ret

  84. code ends
  85. end start
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2012-1-11 22:31:13 | 显示全部楼层
其中那个arund是把ds掉头用的
源代码多了个dec si:
  1. assume cs:code

  2. data segment
  3. db '1','2','3','4','5','6'
  4. db 10 dup (0)
  5. data ends

  6. stack segment
  7. db 30h dup (0)
  8. stack ends

  9. code segment
  10. start:
  11. mov ax,data
  12. mov ds,ax
  13. mov ax,stack
  14. mov ss,ax
  15. mov sp,30h
  16. mov si,6 ;6个数,si为形参
  17. dec si
  18. mov bx,0
  19. mov dh,0
  20. e:mov cx,si
  21. mov dl,ds:[bx]
  22. push dx
  23. inc bx
  24. sub cx,bx
  25. jcxz e0

  26. jmp e
  27. e0:mov cx,si
  28. mov bx,0
  29. e1:pop ax
  30. mov ds:[bx],al
  31. inc bx
  32. loop e1


  33. mov ax,4c00h
  34. int 21h
  35. code ends
  36. end start
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-7-7 09:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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