鱼C论坛

 找回密码
 立即注册
查看: 3585|回复: 5

实验10.3代码

[复制链接]
发表于 2011-3-5 16:05:40 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 ckzmo 于 2011-3-6 13:11 编辑

题目就是吧12666显示在8行3列绿字
终于调试出来了
  1. assume cs:code
  2. data segment
  3. db 10 dup(0)
  4. data ends

  5. code segment
  6. start:mov ax,12666
  7.       mov bx,data
  8.           mov ds,bx
  9.           mov si,0
  10.           call dtoc
  11.           
  12.            mov dh,8
  13.            mov dl,3
  14.            mov cl,2
  15.            call show_str
  16.           
  17.            mov ax,4c00h
  18.            int 21h       
  19.           
  20. dtoc:push bx
  21.               
  22.   s:    mov dx,0
  23.          mov cx,10d
  24.          div cx
  25.          mov cx,ax
  26.          jcxz t
  27.          add dx,30h
  28.          mov ds:[si],dx
  29.          push dx
  30.          inc si
  31.          mov bx,si
  32.          jmp short s
  33.                 
  34.    t:   add bx,1
  35.         mov cx,bx
  36.         mov si,0
  37.         add dx,30h
  38.          
  39. s1  : mov ds:[si],dx
  40.         pop dx
  41.         inc si  
  42.         loop s1
  43.        
  44.         mov si,0
  45.         ret
  46.        
  47. show_str:mov al,0a0h
  48.                 dec dh
  49.                 mul dh
  50.                 mov bx,ax
  51.                
  52.                 mov al,2
  53.                 mul dl
  54.                 sub ax,2
  55.                 add bx,ax
  56.          
  57.                  mov dx,0b800h
  58.                  mov es,dx
  59.                         
  60.                  mov di,0
  61.                  mov al,cl
  62.          
  63.   s2:mov cl,ds:[si]
  64.        mov ch,0
  65.        jcxz x
  66.        mov es:[bx+di],cl                 
  67.        mov es:[bx+di+1],al
  68.        inc si
  69.        add di,2
  70.        jmp short s2
  71.        
  72.         x:ret
  73.        
  74. code ends
  75. end start
复制代码
aa.jpg
77.jpg
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-3-5 22:44:18 | 显示全部楼层
首先
mov ax,4c00h
int 21h ;少了个h

不过通过了没正常显示.再看看.
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-3-5 23:00:56 | 显示全部楼层
本帖最后由 china0008 于 2011-3-5 23:52 编辑

源码来了。你自己分析下。
有疑问再提问。
  1. assume cs:code
  2. data segment
  3.   db 10 dup (0)
  4. data ends

  5. code segment
  6. start:
  7.         mov ax,12666
  8.         mov bx,data
  9.         mov ds,bx
  10.         mov si,0
  11.         call dtoc
  12.         mov dh,8
  13.         mov dl,3
  14.         mov cl,2
  15.         call show_str
  16.        
  17.         mov ax,4c00h
  18.         int 21h
  19. dtoc:
  20.         push ax
  21.         push bx
  22.         push cx
  23.         push dx
  24.         push si
  25.         mov bx,0
  26. zh: mov cx,10
  27.         mov dx,0
  28.         div cx
  29.         add dx,30h
  30.         push dx
  31.         inc bx
  32.         mov cx,ax
  33.         inc cx       ;针对首位为1的数值对循环次数的影响。其他首位值不受影响。
  34.         loop short zh
  35.     mov cx,bx    ;把显示数值的位数传递给cx
  36.         mov si,0
  37. px: pop ax      
  38.     mov [si],al
  39.         inc si
  40.         loop short px
  41.        
  42.         pop si
  43.         pop dx
  44.         pop cx
  45.         pop bx
  46.         pop ax
  47.         ret
  48.                
  49. show_str:              ;提供 行/列/属性   即可显示
  50.           push cx
  51.           push si
  52.           mov ax,0b800h
  53.           mov es,ax        ;显存0页段地址
  54.           dec dh
  55.           dec dl           ;因为行列都是从0开始数。所以行和列都减1
  56.           mov al,160
  57.           mul dh
  58.           mov bx,ax
  59.           mov al,2
  60.           mul dl
  61.           add bx,ax        ;计算首字地址
  62.           mov di,0         ;显存偏移变量
  63.           mov al,cl
  64.           mov ch,0         ;用al存储显示属性,CX用于显示字符和判断0的出现。
  65.         s:mov cl,ds:[si]
  66.       jcxz ok
  67.           mov es:[bx+di],cl
  68.           mov es:[bx+di+1],al
  69.           inc si
  70.           add di,2      
  71.       jmp short s
  72.    ok:pop si
  73.       pop cx
  74.       ret
  75. code ends
  76. end start
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-3-5 23:57:29 | 显示全部楼层
  1. assume cs:code
  2. data segment
  3.         db 10 dup(0)
  4. data ends

  5. code segment
  6.         start:mov ax,12666
  7.         mov bx,data
  8.         mov ds,bx
  9.         mov si,0
  10.         call dtoc

  11.         mov dh,8
  12.         mov dl,3
  13.         mov cl,2
  14.         call show_str

  15.         mov ax,4c00h
  16.         int 21h        
  17.       
  18. dtoc:
  19.         push bx
  20.         push si
  21.               
  22. s:   
  23.         mov dx,0      ;s循环是把12666分别除以10取的余数放进ds:[si]中
  24.         mov bx, 0aH
  25.         div bx
  26.         add dx, 30H
  27.         push dx
  28.         mov cx, ax
  29.         inc di
  30.         jcxz t
  31.         jmp s
  32.                
  33. t: mov cx, di           ;要循环的次数给CX

  34. s1:  
  35.                                         ;S1循环就是把DS:[SI]中的数加上30H
  36.         pop dx
  37.         mov [si], dl
  38.         inc si
  39.         loop s1
  40.         mov dl, 0
  41.         mov [si], dl
  42.         
  43.         pop si                                         
  44.         pop bx
  45.         
  46.         ret
  47.         
  48. show_str:
  49.         mov al,0a0h
  50.         ;dec dh                                          ;行
  51.         mul dh
  52.         mov bx,ax

  53.         mov al,2                                     ;列
  54.         mul dl
  55.         ;sub ax,2
  56.         add bx,ax


  57.         mov dx,0b800h
  58.         mov es,dx
  59.                
  60.         mov di,0
  61.         mov ah,cl

  62.         s2:mov cl,ds:[si]
  63.         mov ch,0
  64.         jcxz x
  65.         mov al,ds:[si]
  66.         mov es:[bx],ax                 
  67.         ;mov es:[di+1],al
  68.         inc si
  69.         add bx,2
  70.         jmp short s2

  71.         x:ret
  72.         
  73. code ends
  74. end start
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-3-6 00:05:35 | 显示全部楼层
哎呀,12点了.改了一个小时,技术差....有几句偶不明白的地方,给你注释掉了.用栈的方式存储,其他的地方没动.
其实ds:[si],默认关联的.不需要显示表示,直接[si]就可以的吧
上面版主也给了代码了.
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-3-6 13:12:51 | 显示全部楼层
我的答案编辑在1楼了 谢谢版主的帮忙
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-4-20 00:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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