"80x86 Assembly language Learning" "DOS function call" Basic IO function (ii)

Source: Internet
Author: User

Example 2: Write a program that takes a string first, and then displays the number of characters, the number of letters, and the length of the string.

The DOS system used in this example is called as follows:

1. Display string (number 9th function call)

Function: Displays a string on the standard output. Typically, the standard output is the screen

Entry parameter: ds:dx= requires the first address of the output string, with the string ' $ ' as the end flag

Export parameters: None

Note: When displaying the output check whether to press CTRL + C or Ctrl+break key, otherwise the program exits.

2. Input string (0AH function Call)

Function: Reads a string from the input in the table, usually the standard input is the keyboard.

Entry parameter: ds:dx= buffer first address,

Export parameters: The received string is in the buffer

Note: (1) The first word in the buffer is the maximum buffer capacity, which can be considered as an entry parameter; the second byte of the buffer holds the actual read-in

The number of characters (excluding carriage returns), which can be considered part of the export parameter, and the third byte begins to hold the accepted string.

(2) The string ends with a carriage return, which is the last character of the string.

(3) If the number of characters entered exceeds the maximum value that the buffer can hold, then the characters entered are discarded and ringing until a carriage return is encountered.

(4) Press CTRL + C or Ctrl+break key to exit the program

3, display output (number 2nd function call)

Function: Write a character like a standard output device, typically, the standard output is the screen

Entry parameter: dl= the ASCII code to output the displayed characters

Export parameters: None

Note: Press CTRL + C or the Ctrl+break key, or the program exits

The code is as follows:

Mlength = 128; Position constant, buffer maximum length dseg SEGMENT BUFF db mlength; the first byte holds the maximum value of the buffer db? The second byte holds the length of the actual string db Mlength DUP (0); True string MESSG0 db ' please input:$ ' MESSG1 db ' length = $ ' M ESSG2 db ' X = $ ' MESSG3 db ' Y = $ ' dseg ENDS cseg SEGMENT assume cs:cseg,ds:dseg Start:mov ax,dseg MOV DS, A
		X; set DS register MOV dx,offset MESSG0; display prompt message call dispmess; mov dx,offset BUFF; call number 10th to get the output string mov ah,10 INT 21H to call NEWLINE; Show line feed and carriage return mov bh,0;	            Empties the numeric character counter mov bl,0; Clears the character counter mov cl,buff+1; Gets the length of the input string mov ch,0 jcxz COK
		; Determines whether the string is empty, with the carriage return as the end of MOV Si,offset buff+2; Gets the first address of the holding string Again:mov Al,[si]; Gets the character INC SI; pointer plus a CMP al, ' 0 ' JB NEXT CMP al, ' 9 '; determine if the number JA NodeC INC BH; digital Count additive JM P short NEXT nodec:or al,20h; If the letter is converted to a lowercase letter CMP AL, ' a' JB next CMP AL, ' z ' JA next INC BL; letter count cumulative Next:loop AGAIN;	         Cok:mov dx,offset MESSG1; display prompt message call dispmess MOV al,buff+1; Gets the length of the string XOR Ah,ah call Dispal
		; The call NEWLINE is displayed in decimal number form;
		mov dx,offset MESSG2; display number of numbers call dispmess MOV al,bh XOR ah,ah call Dispal call NEWLINE;
		MOV Dx,offset MESSG3; Displays the number of letters call dispmess MOV AL, BL XOR AH, ah call Dispal call NEWLINE; mov ax,4c00h INT 21H; Displays 8-bit binary dispal PROC mov cx,3 in decimal, 8-bit binary number maximum represented as 3 decimal number mov dl,10; divisor is ten disp1:div D L Ax/dl=al (quotient) AH (remainder) XCHG ah,al; Exchange Al,ah, so that Al saves the remainder ADD al, ' 0 '; Convert to ASCII PUSH ax; save Ax to the stack, where the main use is AL, the subsequent display process
		Will use Al XCHG Ah,al; is Al to continue to maintain the business MOV ah,0; empty AH loop DISP1; continue the cycle test; MOV cx,3 disp2:pop DX call Echoch LOOP DISP2 ret dispal ENDP echoch PROC MOV ah,2 INT 21H RET Echoch ENDP; Shown with DX refers to the hint information dispmess PROC MOV ah,9 INT 21H RET DIspmess ENDP; show line break and carriage return NEWLINE PROC push AX push DX mov dl,0dh mov ah,2 INT 21H mov dl,0ah mov AH, 2 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.