多语言展示
当前在线:1600今日阅读:23今日分享:25

汇编语言程序设计:[11]动画心

汇编语言(Assembly Language)是面向机器的程序设计语言。在汇编语言中,用助记符(Memoni)代替机器指令的操作码,用地址符号(Symbol)或标号(Label)代替指令或操作数的地址,如此就增强了程序的可读性并且降低了编写难度,象这样符号化的程序设计语言就是汇编语言,因此亦称为符号语言。使用汇编语言编写的程序,机器不能直接识别,还要由汇编程序或者叫汇编语言编译器转换成机器指令。汇编程序将符号化的操作代码组装成处理器可以识别的机器指令,这个组装的过程称为组合或者汇编。因此,有时候人们也把汇编语言称为组合语言。
工具/原料

Assembly Language   Masm汇编编译器

方法/步骤
1

打开masm汇编编译程序,新建一个masm源文件脚本。DATAS SEGMENT    ;此处输入数据段代码  DATAS ENDSSTACKS SEGMENT    ;此处输入堆栈段代码STACKS ENDSCODES SEGMENT    ASSUME CS:CODES,DS:DATAS,SS:STACKSSTART:    MOV AX,DATAS    MOV DS,AX    ;此处输入代码段代码    MOV AH,4CH    INT 21HCODES ENDS    END START

2

在正文中输入我们的程序代码,并将文件命名为xin.asmdata segmentfull db 0buff1 db '  xiaobo welcome you !'           db 0dh,0ah,'*****Designed by 1wangxiaobo@163.com!',0dh,0ah,'Please press any key*****$'buff2 db '       My heart beats with yours!'      db '             ***** Please q to quit *****$'data endscode segmentmain proc far     assume cs:code,ds:datastart:     push ds     sub ax,ax     push ax     mov ax,data     mov ds,ax     mov ah,00     mov al,04     int 10h     mov ah,0bh     mov bh,00     mov bl,1     int 10h     mov ah,0bh     mov bh,1     mov bl,2     int 10h     mov dx,offset buff1               ;显示提示信息     mov ah,09     int 21h     mov ah,08     int 21h     call clear                        ;clssss:     call text                         ;display the text     mov di,2     mov al,1                          ;draw the big box     mov cx,70     mov dx,20     mov bx,160     call box     mov cx,71      mov dx,21     mov bx,158again:     mov al,1     mov di,0     call box     call delay     mov al,0     mov di,0     call box     inc cx     inc dx     sub bx,2     cmp cx,94     jnz again     mov di,0                          ;draw the 2nd box     mov cx,95     mov dx,45     mov al,1     mov bx,110     call box     mov cx,96     mov dx,46     mov bx,108again_00:     mov al,1     mov di,0     call box     call delay     call delay     mov al,0     mov di,0     call box     inc cx     inc dx     sub bx,2     cmp cx,114     jnz again_00     mov cx,115                        ;draw the 3rd box     mov dx,65     mov al,1     mov bx,70     call box     mov cx,116     mov dx,66     mov bx,68again_01:     mov al,1     mov di,0     call box     call delay     call delay     mov al,0     mov di,0     call box     inc cx     inc dx     sub bx,2     cmp cx,129     jnz again_01     mov di,2     mov al,1                          ;draw the small box     mov cx,130     mov dx,80     mov bx,40     call box     mov di,2     mov al,3                          ;对角线     mov si,0     mov cx,71     mov dx,21     mov bx,59     call xie_line     mov cx,171     mov dx,121     mov bx,59     call xie_line     mov si,1     mov cx,71     mov dx,179     mov bx,59     call xie_line     mov cx,171     mov dx,79     mov bx,59     call xie_line     mov cx,150                       ;十字线     mov dx,20     mov si,0     mov bx,60     call draw_line     mov cx,150     mov dx,120     mov bx,60     call draw_line     mov cx,70     mov dx,100     mov si,1     mov bx,60     call draw_line     mov cx,170     mov dx,100     mov bx,60     call draw_line     mov si,1     mov cx,70     mov dx,60     mov bx,60     call mid_line     mov cx,170     mov dx,110     mov bx,60     call mid_line     mov si,2     mov cx,110     mov dx,20     mov bx,30     call mid_line     mov cx,160     mov dx,120     mov bx,30     call mid_line     mov si,3     mov cx,70     mov dx,140     mov bx,60     call mid_line     mov cx,170     mov dx,90     mov bx,60     call mid_line     mov si,4     mov cx,110     mov dx,180     mov bx,30     call mid_line     mov cx,160     mov dx,80     mov bx,30call mid_linemov di,0mov al,1                           ;draw the big box againmov cx,70mov dx,20mov bx,160call boxmov di,0mov al,1                           ;draw the small box againmov cx,130mov dx,80mov bx,40call boxmov di,0mov cx,95mov dx,45mov al,1mov bx,110call boxmov cx,115mov dx,65mov al,1mov bx,70call boxmov di,1                          ;fillcall fillcall fill_2call fill_3mov cx,149                         ;boldmov dx,120mov al,2mov bx,60mov si,0call draw_linemov cx,151mov dx,120mov al,2mov bx,60mov si,0call draw_lineheart_:                            ;draw the heartcall cls_boxcall heartmov ah,08int 21hcmp al,'q'jz okcmp al,20hjz heart_call clearjmp sssok:retmain endpfill proc near                    ;the procedure of fillmov full,0mov al,5mov cx,160mov dx,121mov si,0mov bx,60fill_Y:push cxpush dxpush bxcall draw_linepop bxpop dxpop cxsub bx,2inc cxadd dx,2inc fullcmp full,30jne fill_yretfill endpfill_2 proc nearmov full,0mov al,5mov cx,140mov dx,121mov si,0mov bx,60fill_Y1:push cxpush dxpush bxcall draw_linepop bxpop dxpop cxsub bx,2dec cxadd dx,2inc fullcmp full,30jne fill_y1retfill_2 endpfill_3 proc nearmov al,1mov full,0mov si,0mov cx,140mov dx,121mov bx,60re_fill:push bxpush cxpush dxcall draw_linepop dxpop cxpop bxinc cxinc fullcmp full,9jne re_fillmov full,0mov cx,159mov dx,121mov bx,60re_fill2:push bxpush cxpush dxcall draw_linepop dxpop cxpop bxdec cxinc fullcmp full,9jne re_fill2retfill_3 endpdraw_Line proc near               ;the procedure of draw a linepush bxcmp si,0jz V_line1add bx,cxH_line:mov ah,0chint 10hcmp di,0jz aa0cmp di,1jz aa1call delayaa1:call delayaa0:inc cxcmp cx,bxjne H_linejmp exit_lineV_line1:add bx,dxV_line:mov ah,0chcmp di,0jz bb0cmp di,1jz bb1call delaybb1:call delaybb0:int 10hinc dxcmp dx,bxjne V_lineexit_line:pop bxretdraw_Line endpxie_line proc near                ;the procedure of draw a xie_lineadd bx,cxcmp si,1jz xieline_1xieline_0:mov ah,0chint 10hinc dxinc cxcmp cx,bxjne xieline_0jmp exit_xiexieline_1:mov ah,0chint 10hdec dxinc cxcmp cx,bxjne xieline_1exit_xie:retxie_line endpMid_line proc near                 ;draw a xie_lineadd bx,cxcmp si,2jz midline_2cmp si,3jz midline_3cmp si,4jz midline_4midline_1: mov ah,0chint 10hinc dxadd cx,2cmp cx,bxjne midline_1jmp exit_linesmidline_2:mov ah,0chint 10hadd dx,2inc cxcmp cx,bxjne midline_2jmp exit_linesmidline_3:mov ah,0chint 10hdec dxadd cx,2cmp cx,bxjne midline_3jmp exit_linesmidline_4:mov ah,0chint 10hsub dx,2inc cxcmp cx,bxjne midline_4exit_lines:retmid_line endpbox proc near                      ;draw a boxpush cxpush dxpush cxpush dxpush cxpush dxpush cxpush dxmov si,1call draw_line                    ;toppop dxpop cxadd cx,bxmov si,0call draw_line                     ;rightpop dxpop cxmov si,0call draw_line                    ;leftpop dxpop cxmov si,1add dx,bxcall draw_line                    ;bottompop dxpop cxretbox endpspace proc near                    ;display a spacemov ah,02mov dl,' 'int 21hretspace endpreturn proc near                  ;回车mov ah,2mov dl,0ahint 21hmov dl,0dhint 21hretreturn endptext proc near                    ;显示文本信息mov bh,0mov dh,0mov dl,0mov ah,2int 10hmov dx,offset buff2mov ah,09int 21htext endpheart proc nearmov cx,136                         ;draw_heartmov dx,93mov si,0mov bx,5mov al,2call draw_linemov cx,137                        ;draw_heartmov dx,91mov si,0mov bx,9call draw_linemov cx,138                        ;draw_heartmov dx,90mov si,0mov bx,12call draw_linemov cx,139                        ;draw_heartmov dx,89mov si,0mov bx,14call draw_linemov cx,140                        ;draw_heartmov dx,88mov si,0mov bx,16call draw_linemov cx,141                        ;draw_heartmov dx,88mov si,0mov bx,17call draw_linemov cx,142                        ;draw_heartmov dx,87mov si,0mov bx,19call draw_linemov cx,143                        ;draw_heartmov dx,87mov si,0mov bx,20call draw_linemov cx,144                        ;draw_heartmov dx,87mov si,0mov bx,21call draw_linemov cx,145                        ;draw_heartmov dx,88mov si,0mov bx,21call draw_linemov cx,146                         ;draw_heartmov dx,88mov si,0mov bx,22call draw_linemov cx,147                        ;draw_heartmov dx,89mov si,0mov bx,22call draw_linemov cx,148                        ;draw_heartmov dx,90mov si,0mov bx,22call draw_linemov cx,149                        ;draw_heartmov dx,91mov si,0mov bx,22call draw_linemov cx,150                        ;1draw_heartmov dx,91mov si,0mov bx,22call draw_linemov cx,151                        ;draw_heartmov dx,90mov si,0mov bx,22call draw_linemov cx,152                        ;draw_heartmov dx,89mov si,0mov bx,22call draw_linemov cx,153                        ;draw_heartmov dx,88mov si,0mov bx,22call draw_linemov cx,154                        ;draw_heartmov dx,88mov si,0mov bx,21call draw_linemov cx,155                        ;draw_heartmov dx,87mov si,0mov bx,21call draw_linemov cx,156                        ;draw_heartmov dx,87mov si,0mov bx,20call draw_linemov cx,157                        ;draw_heartmov dx,87mov si,0mov bx,19call draw_linemov cx,158                        ;draw_heartmov dx,88mov si,0mov bx,17call draw_linemov cx,159                        ;draw_heartmov dx,88mov si,0mov bx,16call draw_linemov cx,160                        ;draw_heartmov dx,89mov si,0mov bx,14call draw_linemov cx,161                        ;draw_heartmov dx,90mov si,0mov bx,12call draw_linemov cx,162                        ;draw_heartmov dx,91mov si,0mov bx,9call draw_linemov cx,163                        ;draw_heartmov dx,93mov si,0mov bx,5call draw_lineretheart endpdelay proc near                   ;the procedure of delaypush cxpush dxmov dx,25dl2:mov cx,2801dl3:loop dl3dec dxjnz dl2pop dxpop cxretdelay endpclear proc near                   ;clearmov al,0mov bx,0mov cx,0mov dx,0line:mov ah,0chint 10hinc cxcmp cx,320jne linemov cx,0inc dxcmp dx,200jne lineretclear endpcls_box proc nearmov al,0mov bx,0mov cx,131mov dx,81s_line:mov ah,0chint 10hinc cxcmp cx,170jne s_linemov cx,131inc dxcmp dx,120jne s_lineretcls_box endpcode ends     end start

3

运行我们编辑的文件动画先显示一些提示信息,然后按任意键进入,只见一个方框向中间由大变小,并留下痕迹,然后出现一个心,按空格重复出现心,按其他键将重复,按Q键退出程序,。

推荐信息