bilogoboss

Assembly Language Program To Read A String And Display

Now we will write another Assembly program which reads ten (10) characters from console.

Assembly Language character and string operations summary. This web page examines string and character instructions in assembly language. Specific examples of instructions from various processors are used to illustrate the general nature of assembly language.

Let’s identify variables needed for this program.
First variable will be holding the Message “ENTER 10 CHARACTERS : ” to be printed for the User, So in all One variable.
The identified variable is MESSAGE.

First Line – DATA SEGMENT

How to prompt user for input in assembly language

DATA SEGMENT is the starting point of the Data Segment in a Program and DATA is the name given to this segment and SEGMENT is the keyword for defining Segments, Where we can declare our variables.

Next Line – MESSAGE DB “ENTER 10 CHARACTERS : $”

MESSAGE DB “ENTER 10 CHARACTERS : $” this line is a declaration of Charater Array initialized with “ENTER 10 CHARACTERS : $” and $ is used as (n) NULL character in C program. (A Character is of a BYTE Hence we have to use only DB (Define Byte) ) Detailed explanation is given below.

Next Line – DATA ENDS

DATA ENDS is the End point of the Data Segment in a Program. We can write just ENDS But to differentiate the end of which segment it is of which we have to write the same name given to the Data Segment.

Now, Selection of data type is DB data type because Character needs BYTE which means DB is sufficient.

In Assembly programming, the variable are all defined by bytes only.

DB – Define Byte (Size – 1 Byte)

DW – Define Word (Size – 2 Byte)

DD – Define Double word (Size – 4 Bytes)

DQ – Define Quad word (Size – 8 Bytes)

DT – Define Ten Bytes (Size – 10 Bytes)

NUMBER SYSTEM in Assembly Programming is Decimal, Octal, Hexadecimal, Binary.

In the Program, We are entering the values for the variables and Do arithmetical Operations like Addition, Subtraction, Multiplication and Division So the Computer should understand which kind of Number is entered. Hence there is a different letters for different Number Systems. O or o stands for Octal, H or h stands for Hexadecimal, B or b stands for Binary, D or dstands for Decimal. By default type of numbering system is Decimal. If you do not specify any letter then the number is understood to be Decimal (By default).

Explanation :

In this Assembly Language Programming, A single program is divided into four Segments which are 1. Data Segment, 2. Code Segment, 3. Stack Segment, and 4. Extra Segment. Now, from these one is compulsory i.e. Code Segment. if at all you don’t need variable(s) for your program. if you need variable(s) for your program you will need two Segments i.e. Code Segment and Data Segment.

Next Line – CODE SEGMENT

CODE SEGMENT is the starting point of the Code Segment in a Program and CODE is the name given to this segment and SEGMENT is the keyword for defining Segments, Where we can write the coding of the program.

Next Line – ASSUME DS:DATA CS:CODE

In this Assembly Language Programming, their are Different Registers present for Different Purpose So we have to assume DATA is the name given to Data Segment register and CODE is the name given to Code Segment register (SS,ES are used in the same way as CS,DS )

Next Line – START:

START is the label used to show the starting point of the code which is written in the Code Segment. : is used to define a label as in C programming.

Next Line – MOV AX,DATA
MOV DS,AX

After Assuming DATA and CODE Segment, Still it is compulsory to initialize Data Segment to DS register. MOV is a keyword to move the second element into the first element. But we cannot move DATA Directly to DS due to MOV commands restriction, Hence we move DATA to AX and then from AX to DS. AX is the first and most important register in the ALU unit. This part is also called INITIALIZATION OF DATA SEGMENT and It is important so that the Data elements or variables in the DATA Segment are made accessable. Other Segments are not needed to be initialized, Only assuming is enhalf.

Next Line – LEA DX,MESSAGE
MOV AH,9
INT 21H

The above three line code is used to print String or Message present in the character Array till $ symbol which tells the compiler to stop.

Now, lets understand line by line

LEA DX,MESSAGE in this LEA stands for LOAD EFFECTIVE ADDRESS and it loads the effective address of second element into the first element. This same code can be interchangably written as MOV DX, OFFSET MESSAGE where OFFSET means effective address and MOV means move second element into the first element.

MOV AH,9
INT 21H

The above two line code is used to PRINT the String or Message of the address present in DX register.

Standard Input and Standard Output related Interupts are found in INT 21H which is also called as DOS interrupt. It works with the value of AH register, If the Value is 9 or 9h, That means PRINT the String or Message of the address present in DX register.

Next Line – MOV CX,10

MOV CX,10 is used to move or assign value 10 (decimal value) to CX. The program which we are wishing to write is to input ten characters from console which will be entered by the user, Hence to do so we need a loop construct. In assembly programming language we have a LOOP instruction. This works with two other helpers which are Label and Counter. The Loop start with LABEL and ends with LOOP instruction with the same LABEL name with it. the execution of the Loop depends on the value in CX register ( CX is also Called COUNTER).

Next Line – INPUT:

INPUT: is a LABEL and all the words ending in colon (:).

Next Line – MOV AH,1
INT 21H
MOV X,AL

The above three line code is used to Read a Character from Console and save the value entered in variable X in its ASCII form.

Standard Input and Standard Output related Interupts are found in INT 21H which is also called as DOS interrupt. It works with the value of AH register, If the Value is 1 or 1h, That means READ a Character from Console, Echo it on screen and save the value entered in AL register.

MOV X,AL means move value in AL register into variable X.

Next Line – LOOP INPUT

This end of loop. In assembly programming language we have a LOOP instruction. This works with two other helpers which are Label and Counter. The Loop start with LABEL and ends with LOOP instruction with the same LABEL name with it. the execution of the Loop depends on the value in CX register ( CX is also Called COUNTER).

Next Line – MOV AH,4CH
INT 21H

The above two line code is used to exit to dos or exit to operating system. Standard Input and Standard Output related Interupts are found in INT 21H which is also called as DOS interrupt. It works with the value of AH register, If the Value is 4ch, That means Return to Operating System or DOS which is the End of the program.

MOV AH,4CH This same code can be interchangably written as MOV AX,4C00H where AX register is initialized with 4C00H which means 4C gets saved in AH register and 00 gets saved in AL register. different books follow different forms.

Next Line – CODE ENDS

CODE ENDS is the End point of the Code Segment in a Program. We can write just ENDS But to differentiate the end of which segment it is of which we have to write the same name given to the Code Segment.

Last Line – END START

END START is the end of the label used to show the ending point of the code which is written in the Code Segment.

Note :- In this Assembly Language Programming, We have Com format and EXE format. We are Learning in EXE format only which simple then COM format to understand and Write. We can write the program in lower or upper case, But i prepare Upper Case.

Screen Shots :-Mods available for skyrim ps4.

Output:-

Note :- To see the variable and its value you have to click vars button in the emulator.

Note:- To understand program for sequence in detail Please SEARCH numerically example: ASSEMBLY01, ASSEMBLY02, etc.

In this article, you’ll be learning how to write a Assembly Language Program to print Strings in multiple lines (8086). For this example code, we’ll have three different strings saved on the Registers and will be printed in different lines.

Title: 8086 Assembly Program to print String “Hello World, Good Morning, Have Good Day” in 3 different lines

Description: If you have seen your first Hello World ALP, this assembly program prints STRING from .DATA, but in three different lines. So, here we’ll be saving 3 different Strings to .DATA, and then print them one by one. From our first Hello World ALP hope you have understood the use of mnemonics to display the string and the interrupt request.

Same instructions are used here, but repeatedly. This programs for 8086 Assembly Program to print different Strings in different lines.

8086 ALP to print string “HELLO WORLD, GOOD MORNING, HAVE GOOD DAY” in 3 three different lines:

Assembly Language Program to print Strings in multiple lines (8086)

.MODEL SMALL

.STACK

.DATA

STRING1 DB ‘HELLO WORLD $’ ; declaring string

STRING2 DB 10, 13, ‘GOOD MORNING $’ ; declaring string

STRING3 DB 10, 13, ‘HAVE GOOD DAY $’ ; declaring string

.CODE

MAIN PROC ; main procedure

MOV AX, @DATA ; initialize the data segment

MOV DS, AX

LEA DX, STRING1 ; loading the effective address

MOV AH, 09H ; for string display

INT 21H ; dos interrupt function

LEA DX, STRING2 ; loading the effective address

Assembly Language Program To Read A String And Display

MOV AH, 09H ; for string display

INT 21H ; dos interrupt function

LEA DX, STRING3 ; loading the effective address

MOV AH, 09H ; for string display

INT 21H ; dos interrupt function

Display String In Assembly Language

MOV AX, 4C00H ; end request

INT 21H

MAIN ENDP ; end procedure

How To Read From Keyboard In Assembly

END MAIN ; end program

String

How To Read A String In Assembly Language

More Assembly Language Programs