当前位置: 代码迷 >> 汇编语言 >> 编译语言程序
  详细解决方案

编译语言程序

热度:184   发布时间:2016-05-02 04:35:47.0
汇编语言程序
《1》、实现绕圈的笑脸:assume cs:code code segment        dec dh        dec dl        inc dh        inc dl        ;预存指令 start: mov ax,cs        mov ds,ax              mov si,0        lea di,s1     ;使ds:si指向预存指令,ds:di指向目的地址        mov dx,0h     ;光标起始坐标0,0      s:mov ah,2        mov bh,0        int 10h       ;调用int 10h第2号中断,置光标 ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>               mov ah,0ah     ;int 10h第0a号中断        mov al,2       ;显示笑脸        mov bh,0        ;第0页        mov cx,1       ;重复次数1        int 10h        call delay     ;延迟显示 ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>        mov ah,0ah      ;用int 10h  0a号中断清除笑脸        mov al,0        mov bh,0        int 10h ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>             cmp dh,24       ;行号是否为24        jb L             ;小于则转 L        mov ax,[si]     ;等于则改s1处为自减        mov [di],ax          L2:cmp dl,79       ;列号是否为79        jb L1           ;小于则转 L1        mov ax,[si+2]    ;等于,改si+2处为自减        mov [di+2],ax        jmp s1                  L:cmp dh,0         ;行号是否为0        ja L2             ;大于0转L2        mov ax,[si+4]     ;为0 ,改s1处为自加        mov [di],ax        jmp L2     L1:cmp dl,0         ;列号是否为0        ja s1            ;大于转 s1        mov ax,[si+6]    ;等于改 s1+2处 自加        mov [di+2],ax     s1:inc dh        inc dl         jmp s          mov ax,4c00h        int 21h ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>         delay:push ax        push dx        mov dx,2000h        mov ax,0    s3: sub ax,1        sbb dx,0        cmp ax,0        jne s3        cmp dx,0        jne s3        pop dx        pop ax        ret  ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>         code ends  end start 改进一下的【加中断可控制了】:assume cs:code  code segment         dec dh         dec dl         inc dh         inc dl        ;预存指令  start: mov ax,cs         mov ds,ax               mov si,0         lea di,s1     ;使ds:si指向预存指令,ds:di指向目的地址         mov dx,0h     ;光标起始坐标0,0       s:mov ah,2         mov bh,0         int 10h       ;调用int 10h第2号中断,置光标  ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                mov ah,0ah     ;int 10h第0a号中断         mov al,2       ;显示笑脸         mov bh,0        ;第0页         mov cx,1       ;重复次数1         int 10h         call delay     ;延迟显示         in al,60H         cmp al,10H         jz over  ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>         mov ah,0ah      ;用int 10h  0a号中断清除笑脸         mov al,0         mov bh,0         int 10h  ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>               cmp dh,24       ;行号是否为24         jb L             ;小于则转 L         mov ax,[si]     ;等于则改s1处为自减         mov [di],ax           L2:cmp dl,79       ;列号是否为79         jb L1           ;小于则转 L1         mov ax,[si+2]    ;等于,改si+2处为自减         mov [di+2],ax         jmp s1                   L:cmp dh,0         ;行号是否为0         ja L2             ;大于0转L2         mov ax,[si+4]     ;为0 ,改s1处为自加         mov [di],ax         jmp L2      L1:cmp dl,0         ;列号是否为0         ja s1            ;大于转 s1         mov ax,[si+6]    ;等于改 s1+2处 自加         mov [di+2],ax      s1:inc dh         inc dl          jmp s     over:  mov ax,4c00h         int 21h  ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>          delay:push ax         push dx         mov dx,500h         mov ax,0     s3: sub ax,1         sbb dx,0         cmp ax,0         jne s3         cmp dx,0         jne s3         pop dx         pop ax         ret   ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>          code ends   end start《2》、像素颜色;子程序display入口参数 ;cx列号 ;dx行号 ;al像素颜色 ;子程序delay延时 stack segment stack      db  100h dup(?) stack ends code segment  assume cs:code,ds:code,ss:stack  start:        xor ax,ax         ;设置显示模式(640*480 16色图形)        mov ah,0        mov al,12h        int 10h        mov ah,0bh            ;置调色板背景色        mov bh,0        mov bl,0        int 10h        mov cx,0        mov dx,0        mov al,0     s2:call display        call delay        inc al        cmp al,10h        je exit        add cx,10        jmp s2  exit: mov ah,01        int 21h                              ;esc退出观看效果                                      cmp al,1bh        jne exit        mov ax,0003h        int 10h        mov ax,4c00h        int 21h  display:push ax          push bx          push si          mov bx,cx          mov si,cx          add si,10          s: mov ah,0ch        int 10h        inc cx        cmp cx,si        jne s        mov cx,bx        inc dx        cmp dx,10        jne s        mov dx,0        pop si        pop bx        pop ax        ret  delay:push ax        push dx        mov dx,2000h        mov ax,0      s1:sub ax,1         sbb dx,0         cmp ax,0         jne s1         cmp dx,0         jne s1         pop dx         pop ax        ret  code ends  end start 《3》进制转换:(1)16转10进制:TITLE CONVERT HEXADECIMAL TO BCDDATA SEGMENTPROMPT DB 'Hello  Boss!  INPUT   sixten bits number ,please  :$'HEXBUF DB 3,0,3  DUP(0)DISP   DB  0AH,0DHBCDBUF DB  6  DUP(0),'$'DATA   ENDSSTACK1  SEGMENT PARA STACK         DW 20H  DUP(0)STACK1   ENDSCOSEG    SEGMENT         ASSUME  CS:COSEG,DS:DATA,SS:STACK1HEXBCD: MOV  AX,DATA        MOV  DS,AX        LEA  DX,PROMPT        MOV  AH,09H        INT  21H        LEA  DX,HEXBUF         MOV  AH,0AH        INT  21H        LEA   SI,HEXBUF+2        MOV   BX,0        MOV   CH,HEXBUF+1HEX1:   MOV   AL,[SI]        CMP   AL,'9'        JBE   NUMB        SUB   AL,07HNUMB:   AND   AL,0FH        MOV   CL,04        SAL   BX,CL        OR    BL,AL        INC   SI        DEC   CH        JNE   HEX1        MOV   WORD PTR   BCDBUF+0,0        MOV   WORD PTR   BCDBUF+2,0        MOV   WORD PTR   BCDBUF+4,0               TEST   BX,8000H         JNS   PLUS         MOV   BCDBUF,'-'NEG      BX  PLUS:    MOV CH,0FHLOP0:    CLC         SHL   BX,1         CALL  ADDIT         CALL  MULTI          DEC   CH        JNE   LOP0        SHL   BX,1        CALL  ADDIT        LEA  DI,BCDBUF+1        MOV  CX,3LOP1:   OR  BYTE PTR  [DI],30H         INC  DI         LOOP  LOP1         LEA  DX,DISP          MOV  AH,09H          INT  21H                  MOV  AH,4CH          INT   21HADDIT     PROC          LEA  DI,BCDBUF+3           MOV CL,3ADD1:     MOV AL,[DI]           ADC AL,0           AAA           MOV   [DI],AL           DEC   DI           DEC   CL           JNE   ADD1           RETADDIT      ENDPMULTI      PROC           LEA   DI,BCDBUF+3           MOV  CL,3           CLC  MUL1:      MOV   AL,[DI]           ADC  AL,AL           AAA           MOV   [DI],AL           DEC    DI           DEC    CL           JNE  MUL1            RETMULTI       ENDPCOSEG       ENDS            END HEXBCD   (2)十转十六进制:TITLE ADDITION DATA SEGMENT A1   DB "Input a number please: ","$" A2   DB 0DH,0AH,"The result is: ","$" DATA ENDS STACK1 SEGMENT PARA STACK        DW 20H DUP(?) STACK1 ENDS COSEG SEGMENT       ASSUME CS:COSEG,DS:DATA,SS:STACK1 START: MOV AX,DATA        MOV DS,AX       MOV DX,OFFSET A1        MOV AH,9        INT 21H       MOV AH,01H        INT 21H                      AND AL,0FH       SUB AH,AH       ADD BX,AX       MOV AH,01H        INT 21H               CMP AL,0DH       JE ERR1       MOV DX,BX       MOV CL,3       SAL BX,CL       ADD BX,DX       ADD BX,DX       AND AL,0FH       SUB AH,AH       ADD BX,AX       ERR1:  MOV DX,OFFSET A2        MOV AH,9        INT 21H        SUB AX,AX        MOV CH,4ERR2:   MOV CL,4        ROL BX,CL        MOV AL,BL        AND AL,0FH        ADD AL,30H        CMP AL,3AH        JB ERR3        ADD AL,07HERR3:   MOV DL,AL        MOV AH,2        INT 21H        DEC CH        JNZ ERR2                       MOV AH,4CH         INT 21H COSEG   ENDS         END START

?

  相关解决方案