zoukankan      html  css  js  c++  java
  • 如何用汇编写出一个心形图像

    1.今天学王爽的汇编,才知道BIOS非常强大,于是突发奇想,用int 10h和DOS的 int 21h写了心形图像出来玩

    2.上代码 

      1 assume cs:code
      2 data segment
      3     db 'Hello World','$'
      4 data ends
      5 
      6 code segment
      7 start:
      8     ;绘制心形图案开始
      9     
     10     mov ah,2    ;执行2号子程序,设置光标位置
     11     mov bh,0    ;第0页(共8页)
     12     mov dh,6     ;dh存放行号
     13     mov dl,40    ;dl存放列号
     14     int 10h
     15     call far ptr s1
     16     
     17     mov ah,2    
     18     mov bh,0    
     19     mov dh,5     
     20     mov dl,39
     21     int 10h
     22     call far ptr s1
     23     
     24     mov ah,2    
     25     mov bh,0    
     26     mov dh,5     
     27     mov dl,41
     28     int 10h
     29     call far ptr s1
     30     
     31     mov ah,2    
     32     mov bh,0    
     33     mov dh,4     
     34     mov dl,38
     35     int 10h
     36     call far ptr s1
     37     
     38     mov ah,2    
     39     mov bh,0    
     40     mov dh,4     
     41     mov dl,42
     42     int 10h
     43     call far ptr s1
     44     
     45     mov ah,2    
     46     mov bh,0    
     47     mov dh,3     
     48     mov dl,37
     49     int 10h
     50     call far ptr s1
     51     
     52     mov ah,2    
     53     mov bh,0    
     54     mov dh,3     
     55     mov dl,43
     56     int 10h
     57     call far ptr s1
     58         
     59     mov ah,2    
     60     mov bh,0    
     61     mov dh,3     
     62     mov dl,32
     63     int 10h
     64     call far ptr s1
     65         
     66     mov ah,2    
     67     mov bh,0    
     68     mov dh,3     
     69     mov dl,48
     70     int 10h
     71     call far ptr s1
     72         
     73     mov ah,2    
     74     mov bh,0    
     75     mov dh,4     
     76     mov dl,31
     77     int 10h
     78     call far ptr s1
     79         
     80     mov ah,2    
     81     mov bh,0    
     82     mov dh,4     
     83     mov dl,49
     84     int 10h
     85     call far ptr s1
     86         
     87     mov ah,2    
     88     mov bh,0    
     89     mov dh,5     
     90     mov dl,30
     91     int 10h
     92     call far ptr s1
     93         
     94     mov ah,2    
     95     mov bh,0    
     96     mov dh,5     
     97     mov dl,50
     98     int 10h
     99     call far ptr s1
    100         
    101     mov ah,2    
    102     mov bh,0    
    103     mov dh,6     
    104     mov dl,29
    105     int 10h
    106     call far ptr s1
    107         
    108     mov ah,2    
    109     mov bh,0    
    110     mov dh,6     
    111     mov dl,51
    112     int 10h
    113     call far ptr s1
    114         
    115     mov ah,2    
    116     mov bh,0    
    117     mov dh,7     
    118     mov dl,28
    119     int 10h
    120     call far ptr s1
    121         
    122     mov ah,2    
    123     mov bh,0    
    124     mov dh,7     
    125     mov dl,52
    126     int 10h
    127     call far ptr s1
    128         
    129     mov ah,2    
    130     mov bh,0    
    131     mov dh,8     
    132     mov dl,27
    133     int 10h
    134     call far ptr s1
    135         
    136     mov ah,2    
    137     mov bh,0    
    138     mov dh,8     
    139     mov dl,53
    140     int 10h
    141     call far ptr s1
    142         
    143     mov ah,2    
    144     mov bh,0    
    145     mov dh,9     
    146     mov dl,26
    147     int 10h
    148     call far ptr s1
    149         
    150     mov ah,2    
    151     mov bh,0    
    152     mov dh,9     
    153     mov dl,54
    154     int 10h
    155     call far ptr s1
    156         
    157     mov ah,2    
    158     mov bh,0    
    159     mov dh,10     
    160     mov dl,26
    161     int 10h
    162     call far ptr s1
    163         
    164     mov ah,2    
    165     mov bh,0    
    166     mov dh,10     
    167     mov dl,54
    168     int 10h
    169     call far ptr s1
    170         
    171     mov ah,2    
    172     mov bh,0    
    173     mov dh,11     
    174     mov dl,27
    175     int 10h
    176     call far ptr s1
    177         
    178     mov ah,2    
    179     mov bh,0    
    180     mov dh,11     
    181     mov dl,53
    182     int 10h
    183     call far ptr s1
    184         
    185     mov ah,2    
    186     mov bh,0    
    187     mov dh,12     
    188     mov dl,28
    189     int 10h
    190     call far ptr s1
    191         
    192     mov ah,2    
    193     mov bh,0    
    194     mov dh,12     
    195     mov dl,52
    196     int 10h
    197     call far ptr s1
    198         
    199     mov ah,2    
    200     mov bh,0    
    201     mov dh,13     
    202     mov dl,29
    203     int 10h
    204     call far ptr s1
    205         
    206     mov ah,2    
    207     mov bh,0    
    208     mov dh,13     
    209     mov dl,51
    210     int 10h
    211     call far ptr s1
    212         
    213     mov ah,2    
    214     mov bh,0    
    215     mov dh,14     
    216     mov dl,30
    217     int 10h
    218     call far ptr s1
    219         
    220     mov ah,2    
    221     mov bh,0    
    222     mov dh,14     
    223     mov dl,50
    224     int 10h
    225     call far ptr s1
    226         
    227     mov ah,2    
    228     mov bh,0    
    229     mov dh,15     
    230     mov dl,31
    231     int 10h
    232     call far ptr s1
    233         
    234     mov ah,2    
    235     mov bh,0    
    236     mov dh,15     
    237     mov dl,49
    238     int 10h
    239     call far ptr s1
    240         
    241     mov ah,2    
    242     mov bh,0    
    243     mov dh,16     
    244     mov dl,32
    245     int 10h
    246     call far ptr s1
    247         
    248     mov ah,2    
    249     mov bh,0    
    250     mov dh,16     
    251     mov dl,48
    252     int 10h
    253     call far ptr s1
    254         
    255     mov ah,2    
    256     mov bh,0    
    257     mov dh,17     
    258     mov dl,33
    259     int 10h
    260     call far ptr s1
    261         
    262     mov ah,2    
    263     mov bh,0    
    264     mov dh,17     
    265     mov dl,47
    266     int 10h
    267     call far ptr s1
    268         
    269     mov ah,2    
    270     mov bh,0    
    271     mov dh,18     
    272     mov dl,34
    273     int 10h
    274     call far ptr s1
    275         
    276     mov ah,2    
    277     mov bh,0    
    278     mov dh,18     
    279     mov dl,46
    280     int 10h
    281     call far ptr s1
    282         
    283     mov ah,2    
    284     mov bh,0    
    285     mov dh,19     
    286     mov dl,35
    287     int 10h
    288     call far ptr s1
    289         
    290     mov ah,2    
    291     mov bh,0    
    292     mov dh,19     
    293     mov dl,45
    294     int 10h
    295     call far ptr s1
    296         
    297     mov ah,2    
    298     mov bh,0    
    299     mov dh,20     
    300     mov dl,36
    301     int 10h
    302     call far ptr s1
    303         
    304     mov ah,2    
    305     mov bh,0    
    306     mov dh,20     
    307     mov dl,44
    308     int 10h
    309     call far ptr s1
    310         
    311     mov ah,2    
    312     mov bh,0    
    313     mov dh,21     
    314     mov dl,37
    315     int 10h
    316     call far ptr s1
    317         
    318     mov ah,2    
    319     mov bh,0    
    320     mov dh,21     
    321     mov dl,43
    322     int 10h
    323     call far ptr s1
    324         
    325     mov ah,2    
    326     mov bh,0    
    327     mov dh,22     
    328     mov dl,38
    329     int 10h
    330     call far ptr s1
    331         
    332     mov ah,2    
    333     mov bh,0    
    334     mov dh,22     
    335     mov dl,42
    336     int 10h
    337     call far ptr s1
    338         
    339     mov ah,2    
    340     mov bh,0    
    341     mov dh,23     
    342     mov dl,39
    343     int 10h
    344     call far ptr s1
    345         
    346     mov ah,2    
    347     mov bh,0    
    348     mov dh,23    
    349     mov dl,41
    350     int 10h
    351     call far ptr s1
    352         
    353     mov ah,2    
    354     mov bh,0    
    355     mov dh,24     
    356     mov dl,40
    357     int 10h
    358     call far ptr s1
    359     
    360     mov ah,2    
    361     mov bh,0    
    362     mov dh,2     
    363     mov dl,33
    364     int 10h
    365     call far ptr s2
    366     
    367     mov ah,2    
    368     mov bh,0    
    369     mov dh,2    
    370     mov dl,44
    371     int 10h
    372     call far ptr s2
    373     ;绘制心形图案结束
    374     
    375     ;hello world 字符串所在行和列
    376     mov ah,2    
    377     mov bh,0    
    378     mov dh,8     
    379     mov dl,35
    380     int 10h
    381     
    382     mov ax,data
    383     mov ds,ax
    384     mov dx,0
    385     mov ah,9
    386     int 21h
    387     
    388     ;无限循环,防止程序结束.
    389     s0:
    390         jmp short s0
    391     
    392     mov ax,4c00h
    393     int 21h
    394     
    395     ;s1,s2用来心形图案的绘制
    396     s1:
    397         mov ah,9    ;在光标位置显示字符
    398         mov al,' '    ;字符
    399         mov bl,4ch    ;颜色属性
    400         mov bh,0    ;第0页
    401         mov cx,1    ;字符重复个数
    402         int 10h
    403         retf
    404     
    405     s2:
    406         mov ah,9    
    407         mov al,' '    
    408         mov bl,4ch    
    409         mov bh,0    
    410         mov cx,4    
    411         int 10h
    412         retf
    413         
    414 code ends
    415 end start
    View Code

      代码中都是重复代码,所以就不展开了,如果各位大佬有比这个更好的代码,请让我借鉴一下.

      我的代码只能运行在xp系统,win7没有试.

    3.原理的话很简单.

      (1).一共用到了2个中断程序其中的3个子程序.

        int 10h中  ah=2 设置光标位置

        int 10h中  ah=9 在光标位置显示字符串

        int 21h中  ah=9 在光标位置显示字符串,字符串以'$

      (2).颜色设置

        7  6  5  4  3  2  1  0

        BL  R  G  B  I  R  G  B

       闪烁   [     背景色     ]   高亮   [     前景色    ]

       比如:  红底绿字  01000010B

            黑底白字  00000111B

  • 相关阅读:
    目录:数据挖掘
    目录:工具的安装与激活
    目录:Django框架开发Web系统的功能实现过程
    Python3.5在jupyter中使用graphviz画决策树(包括graphviz-2.38.msi的安装)
    2020年全国高校计算机能力挑战赛Python程序设计初赛
    离群异常值与重复数据检测
    数据描述性统计度量方法
    数据挖掘的方法
    Nginx+uWSGI+Django部署方案的详细实现过程
    VMware的联网配置及虚拟机IP配置
  • 原文地址:https://www.cnblogs.com/Triomphe/p/8688356.html
Copyright © 2011-2022 走看看