鱼C论坛

 找回密码
 立即注册
查看: 3392|回复: 2

小白求助

[复制链接]
发表于 2018-12-16 17:29:48 | 显示全部楼层 |阅读模式

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

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

x
第一个题目:计算从1到20的累加和,以十进制的方式显示在屏幕上
第二个题目:在80*25的屏幕上,以多种颜色显示多种字符
求大佬这两道题怎么写?
还有DOSBox 0.74怎么在屏幕上显示程序运行结果?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-16 22:45:36 | 显示全部楼层
  1. assume cs:code, ds:data

  2. data segment
  3. buf        db 512 dup(?)
  4. stack        db 512 dup(?)
  5. stack_top:
  6. data ends

  7. code segment
  8. ; void PutChar(uint8_t x, uint8_t y, char ch, uint8_t attr);
  9. PutChar:
  10.         push        bp
  11.         mov        bp, sp
  12.         push        di
  13.         push        es
  14.        
  15.         mov        ax, 0b800h
  16.         mov        es, ax
  17.         mov        dl, [bp + 6]        ; y
  18.         mov        al, 160
  19.         mul        dl
  20.         mov        di, ax
  21.         mov        dl, [bp + 4]        ; x
  22.         mov        al, 2
  23.         mul        dl
  24.         add        di, ax
  25.        
  26.         mov        al, [bp + 8]        ; ch
  27.         mov        ah, [bp + 10]        ; attr
  28.         mov        es:[di], ax
  29.        
  30.         mov        bh, 0        ; 显示页码
  31.         mov        dh, [bp + 6]        ; y
  32.         mov        dl, [bp + 4]        ; x
  33.         add        dl, 1
  34.         mov        ah, 2        ; 设置光标位置
  35.         int        10h
  36.        
  37.         pop        es
  38.         pop        di
  39.         mov        sp, bp
  40.         pop        bp
  41.         ret

  42. ; void PutString(uint8_t x, uint8_t y, char *str, uint8_t attr);
  43. PutString:
  44.         push        bp
  45.         mov        bp, sp
  46.         push        bx
  47.         push        si
  48.         push        di
  49.        
  50.         mov        si, [bp + 4]        ; x
  51.         mov        di, [bp + 6]        ; y
  52.         mov        bx, [bp + 8]        ; str
  53. @@:
  54.         cmp        byte ptr [bx], 0
  55.         je        @F
  56.         push        [bp + 10]        ; attr
  57.         xor        ah, ah
  58.         mov        al, [bx]
  59.         push        ax                ; ch
  60.         push        di                ; y
  61.         push        si                ; x
  62.         call        PutChar
  63.         add        sp, 8
  64.         inc        si
  65.         inc        bx
  66.         jmp        @B
  67. @@:
  68.         pop        di
  69.         pop        si
  70.         pop        bx
  71.         mov        sp, bp
  72.         pop        bp
  73.         ret

  74. ; void NumberToString(uint16_t number, char *buffer);
  75. NumberToString:
  76.         push        bp
  77.         mov        bp, sp
  78.         push        bx
  79.         push        si
  80.         push        di
  81.        
  82.         mov        di, [bp + 6]        ; buffer
  83.         mov        ax, [bp + 4]        ; number
  84.         xor        dx, dx
  85.         ;mov        cx, 16
  86.         mov        cx, 10                ; 现在是要十进制
  87. @@:
  88.         div        cx
  89.         mov        dh, dl
  90.         add        dl, '0'
  91.         cmp        dh, 10
  92.         jb        @1
  93.         mov        dl, dh
  94.         sub        dl, 10
  95.         add        dl, 'A'
  96. @1:
  97.         mov        [di], dl
  98.         inc        di
  99.         xor        dx, dx
  100.         cmp        ax, 0
  101.         jne        @B
  102.         mov        byte ptr [di], 0        ; '\0'
  103.        
  104.         ; 下面翻转字符串
  105.         dec        di
  106.         mov        si, [bp + 6]        ; buffer
  107. @@:
  108.         cmp        si, di
  109.         jge        @F
  110.         mov        ah, [si]
  111.         mov        al, [di]
  112.         mov        [si], al
  113.         mov        [di], ah
  114.         inc        si
  115.         dec        di
  116.         jmp        @B
  117. @@:
  118.         pop        di
  119.         pop        si
  120.         pop        bx
  121.         mov        sp, bp
  122.         pop        bp
  123.         ret
  124. start:
  125.         mov        ax, data
  126.         mov        ds, ax
  127.         mov        ss, ax
  128.         mov        sp, stack_top
  129.        
  130.         mov        cx, 1
  131.         xor        ax, ax
  132. L:
  133.         add        ax, cx
  134.         inc        cx
  135.         cmp        cx, 20
  136.         jbe        L
  137.        
  138.         mov        bx, offset buf
  139.         push        bx                ; buffer
  140.         push        ax                ; number
  141.         call        NumberToString
  142.         add        sp, 4
  143.        
  144.         mov        ax, 07h
  145.         push        ax                ; attr
  146.         mov        ax, offset buf
  147.         push        ax                ; str
  148.         xor        ax, ax
  149.         push        ax                ; y
  150.         push        ax                ; x
  151.         call        PutString
  152.         add        sp, 8
  153.        
  154.         mov        ax, 4c00h
  155.         int        21h
  156. code ends
  157. end start
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-16 22:52:58 | 显示全部楼层
  1. assume cs:code, ds:data

  2. data segment
  3. msg0        db 'C', 0
  4. msg1        db 'C++', 0
  5. msg2        db 'Java', 0
  6. msg3        db 'Python', 0

  7. stack        db 512 dup(?)
  8. stack_top:
  9. data ends

  10. code segment
  11. ; void PutChar(uint8_t x, uint8_t y, char ch, uint8_t attr);
  12. PutChar:
  13.         push        bp
  14.         mov        bp, sp
  15.         push        di
  16.         push        es
  17.        
  18.         mov        ax, 0b800h
  19.         mov        es, ax
  20.         mov        dl, [bp + 6]        ; y
  21.         mov        al, 160
  22.         mul        dl
  23.         mov        di, ax
  24.         mov        dl, [bp + 4]        ; x
  25.         mov        al, 2
  26.         mul        dl
  27.         add        di, ax
  28.        
  29.         mov        al, [bp + 8]        ; ch
  30.         mov        ah, [bp + 10]        ; attr
  31.         mov        es:[di], ax
  32.        
  33.         mov        bh, 0        ; 显示页码
  34.         mov        dh, [bp + 6]        ; y
  35.         mov        dl, [bp + 4]        ; x
  36.         add        dl, 1
  37.         mov        ah, 2        ; 设置光标位置
  38.         int        10h
  39.        
  40.         pop        es
  41.         pop        di
  42.         mov        sp, bp
  43.         pop        bp
  44.         ret

  45. ; void PutString(uint8_t x, uint8_t y, char *str, uint8_t attr);
  46. PutString:
  47.         push        bp
  48.         mov        bp, sp
  49.         push        bx
  50.         push        si
  51.         push        di
  52.        
  53.         mov        si, [bp + 4]        ; x
  54.         mov        di, [bp + 6]        ; y
  55.         mov        bx, [bp + 8]        ; str
  56. @@:
  57.         cmp        byte ptr [bx], 0
  58.         je        @F
  59.         push        [bp + 10]        ; attr
  60.         xor        ah, ah
  61.         mov        al, [bx]
  62.         push        ax                ; ch
  63.         push        di                ; y
  64.         push        si                ; x
  65.         call        PutChar
  66.         add        sp, 8
  67.         inc        si
  68.         inc        bx
  69.         jmp        @B
  70. @@:
  71.         pop        di
  72.         pop        si
  73.         pop        bx
  74.         mov        sp, bp
  75.         pop        bp
  76.         ret

  77. start:
  78.         mov        ax, data
  79.         mov        ds, ax
  80.         mov        ss, ax
  81.         mov        sp, stack_top
  82.        
  83.         mov        ax, 09h
  84.         push        ax                ; attr
  85.         mov        ax, offset msg0
  86.         push        ax                ; str
  87.         mov        ax, 0
  88.         push        ax                ; y
  89.         xor        ax, ax
  90.         push        ax                ; x
  91.         call        PutString
  92.         add        sp, 8
  93.        
  94.         mov        ax, 0Ah
  95.         push        ax                ; attr
  96.         mov        ax, offset msg1
  97.         push        ax                ; str
  98.         mov        ax, 1
  99.         push        ax                ; y
  100.         xor        ax, ax
  101.         push        ax                ; x
  102.         call        PutString
  103.         add        sp, 8
  104.        
  105.         mov        ax, 0Ch
  106.         push        ax                ; attr
  107.         mov        ax, offset msg2
  108.         push        ax                ; str
  109.         mov        ax, 2
  110.         push        ax                ; y
  111.         xor        ax, ax
  112.         push        ax                ; x
  113.         call        PutString
  114.         add        sp, 8
  115.        
  116.         mov        ax, 0Eh
  117.         push        ax                ; attr
  118.         mov        ax, offset msg3
  119.         push        ax                ; str
  120.         mov        ax, 3
  121.         push        ax                ; y
  122.         xor        ax, ax
  123.         push        ax                ; x
  124.         call        PutString
  125.         add        sp, 8
  126.        
  127.         mov        ax, 4c00h
  128.         int        21h
  129. code ends
  130. end start
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-10 08:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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