Compilation of basic Cases

Source: Internet
Author: User
Tags alphabetic character first string numeric lowercase

The

Calculates the number of a+b within two bits.

;---------------------------assume CS:CC, ds:qw;---------------------------QW SEGMENT; data segment;D B One byte, dw two bytes, dd four bytes M1 DB ' Please input n1: $ ' M2 db in a, ' please input N2: $ ' M3 db, ' SUM = $ ' M4 db, ' Pres
    s any key to continue ... $ ' N1 DB?
    N2 DB?
S DB?
    QW ENDS;---------------------------CC SEGMENT; code snippet START:; introduce QW segment mov ax, QW mov DS, ax; show M1

    LEA DX, M1 mov ah, 9;D x= string address, $ end string INT 21H; interrupt number; segment flag in_n1:; input MOV Ah, 1 INT 21H  ; Judging whether between 0-9 cmp al, ' 0 ' JB in_n1; smaller than 0 transfer cmp al, ' 9 ' JA in_n1; greater than 9 transfer and AL, 0FH; with MOV   N1, AL; output LEA DX, M2 MOV Ah, 9 int 21H In_n2:mov AH, 1 int 21H CMP AL, ' 0 ' JB In_n2 CMP AL, ' 9 ' JA in_n2 and al, 0FH mov N2, al; Operation N1+n2 ADD AL, N1 MOV S, Al D  ISP:; output hint string LEA DX, M3 mov AH, 9 INT 21H; carry Operation MOVAl, S MOV AH, 0 MOV bl, ten DIV bl; result al depositary, AH Save remainder, PUSH AX; Press into stack, temporarily save ADD AL, ' 0 '; Low eight bit with Operation MOV
    DL, AL;D l output character mov ah, 2 INT 21H POP AX ADD AH, ' 0 '; High eight bit with Operation Mov DL, ah;D l output character mov ah, 2 int 21H Exit:lea DX, M4 mov ah, 9 int 21H mov ah, 7;
 Ah feature output does not echo int 21H MOV AH, 4CH; end this program int 21H; return dos;---------------------------CC ENDS End START

The

Calculates the length of the string, the number of digits, and the number of letters. If you are interested, you can change the number of uppercase letters to calculate the number of lowercase.

; STEP1: Accepts a string using the 0AH function call;; STEP2: Statistics of the number of characters, the number of English letters;; STEP3: Displays them in decimal numbers; data definition mlength = 128; buffer length dseg SEGMENT; data segment BUFF DB mlength; 0AH function call          The required buffer DB?
  The actual number of characters typed DB mlength DUP (?)  MESS0 db "Please input:$" MESS1 db "Length = $" MESS2 db "number = $" MESS3 db "word = $" dseg ENDS cseg
        SEGMENT; code snippet assume cs:cseg, ds:dseg Start:mov ax,dseg; Send data window first address dseg into DS register mov ds,ax; set DS mov dx,offset MESS0 call dispmess; show hint mov DX , OFFSET BUFF mov ah,10; accept a string INT 21H call NEWLINE; carriage return line mov B
        h,0; clear digit character counter mov bl,0; clear alphabetic character counter mov cl,buff+1; take string length mov ch,0 If cx=0, Jcxz cok: Jump to the label Cok Jcxz cok; If the string length equals 0, do not count MOV Si,offset buff+2;
        AGAIN to the first string:MOV Al,[si]; take a character INC SI; Adjust the data pointer, point to the next data CMP AL, ' 0 '; Determine if it is a numeric character JB N EXT; less than ' 0 ', not a statistical character, CMP AL, ' 9 '; greater than ' 9 ', not a numeric character, JA NodeC; turn the alphabetic character to judge INC B H; '
        0 ' ~ ' 9 ', numeric character count plus 1 JMP short next; turn to take one character, Next->again (LOOP) nodec:or al,20h; uppercase to lowercase classic statement            CMP al, ' a '; determine if it is an alphabetic character JB next CMP al, ' Z ' JA next INC BL
        ; alphabetic character count plus 1 Next:loop AGAIN; next Cok:mov dx,offset MESS1 call dispmess; display hints MOV al,buff+1; Take the string length XOR Ah,ah;
        AH takes 0 call Dispal; Displays the string length (becomes decimal) call NEWLINE; Enter line MOV Dx,offset MESS2 Call dispmess; display hint MOV al,bh XOR ah,ah call Dispal; display number characters (decimal display) CA LL NEWLINE; return line MOV dx,offset MESS3 CALL dispmess MOV al,bl XOR ah,ah call Dispal; display alphabetic characters call NEWLINE mov ax,4c00h; program normal end INT 21H Dispal PROC near; subroutine, binary number displays MOV cx,3 in decimal form; 8-bit binary number conversion into 3-bit decimal number MOV dl,10 disp1:div DL; Al Quotient, AH remainder XCHG ah,al; make al= remainder, ah= quotient ADD AL, ' 0 '; ASCII PUSH AX; push in stack XCHG ah,a
        L mov ah,0 loop DISP1; continue mov cx,3; cycle counter resets Disp2:pop DX; Call Echoch; show a character LOOP DISP2; continue RET dispal ENDP dispmess PROC near; subroutine, display message MO    V ah,9 int 21H RET dispmess ENDP Echoch PROC near; subroutine, display a character MOV ah,2 INT 21H RET Echoch ENDP NEWLINE PROC near; sub-program, forming carriage return and line feeds push AX push DX M
OV DL,0DH; The ASCII code of the carriage return is 0DH MOV ah,2; display carriage return INT 21H         mov dl,0ah; The ASCII code of the newline character is 0AH MOV ah,2; display newline character INT 21H POP DX POP AX RET NEWLINE ENDP cseg ENDS END START

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.