Compare the strings in the data segment with the additional segment and the four interrupt instructions common in the Assembly

Source: Internet
Author: User

1. Input two strings of the same length from the keyboard, respectively, to the data and additional segments, using the string comparison instruction to compare two strings in the data segment and the additional segment, and if the two strings, output y, otherwise output n.

This program debugging for a long time, between two problems encountered, one is the use of additional segments, need to DS stack to the ES adjustment processing, that is

1 PUSH    DS2mov     ax,es        3mov     ds,ax4; 5 POP      DS    
View Code

The second is that the string comparison instruction CMPSW the word comparison, while the CMPSB byte comparison, need to distinguish. (In fact, I do not understand the character of the string, even if the word comparison why the error, a master know?) )

Here is the program:

1 DATA SEGMENT2VA DB -,0, -DUP (0),'$'3V1 DB'Y'4V2 DB'N'5ENTER DB 0AH, 0DH,'$'6 DATA ENDS7 DATA2 SEGMENT8VB DB -,0, -DUP (0),'$'9 DATA2 ENDSTen CODE SEGMENT One assume Cs:code,ds:data,es:data2 A Start:mov ax,data; loading DS - MOV Ds,ax - MOV ax,data2; loading es the MOV Es,ax -      - MOV dx,offset va; input string va - MOV ah,0ah + INT 21H -      + PUSH DX, carriage return, line break A MOV DX, OFFSET ENTER at MOV AH, 09H - INT 21H - POP DX -  - PUSH DS - MOV ax,es; handling of additional segments in MOV Ds,ax - MOV dx,offset vb; Input string vb to MOV ah,0ah + INT 21H - POP DS the  * PUSH DX, carriage return, line break $ MOV DX, OFFSET ENTERPanax Notoginseng MOV AH, 09H - INT 21H the POP DX +      A LEA Si,va; transmitting the source string address to SI the PUSH DS + MOV ax,es - MOV Ds,ax $ LEA Di,vb; sending the destination string address to DI $ POP DS -      - to clear the direction flag so that the forward theMOV CX, -; repeat counter - Repe CMPSB, equal repeat, CX 0 or unequal to runWuyi JE J1; equal jump theMOV AH,2 - MOV dl,v2 Wu INT 21H - JMP J2 AboutJ1:mov AH,2 $ MOV dl,v1 - INT 21H - J2:mov ah,4ch - INT 21H A CODE ENDS +END START
View Code

2. The following four types of interrupts are common:

1) keyboard input character interrupt

Mov ah,1

Int 21h; The result is an ASCII code for the al← input character

2) screen displays one character interrupt

Mov ah,2

Mov DL, ASCII code to display characters

Int 21h; (note: Here Al will become the ASCII code of the character to be output)

3) screen display string (number 9th function call)

Format: MOV DX, offset address of the string
MOV AH, 09H
int21h

When using the number 9th feature call, you should be aware of the following issues:

① the string to be displayed must first be placed in the Memory data area (DS segment) with the ' $ ' sign as the end flag.

② the segment base and offset address of the first address of the string should be stored separately in the DS and DX registers.

4) keyboard input string (0AH function Call)

Format: MOV DX, defined offset address of buffer
MOV AH, 0AH
INT 21H

① defines an input buffer before execution, and the first byte in the buffer is defined as the maximum number of characters allowed to enter, including the carriage return 0DH. The second byte is reserved and the actual number of characters entered (without carriage return) is saved after the execution of the program. The ASCII code that receives the characters from the keyboard begins at the third byte. If the actual number of characters entered is less than the maximum number of characters defined, the buffer will automatically clear 0 of other units. If the actual number of characters entered is greater than the number of characters defined, then the input character is discarded, until the input enter.

② the segment base and offset addresses of the first address of the buffer should be stored separately in the DS and DX registers.

Example:

The

compares the strings in the data and additional segments, respectively, and the four interrupt directives that are common in the Assembly

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.