Professional Documents
Culture Documents
Case
Case
L1 DB ?
M1 DB
P11 DB 0FFH DUP ($) to concate characters of two strings given by user and Other variables
will be holding the Messages ENTER ANY STRING :- $, ENTERED STRING IS :- $ and CONVERTED STRING
IS : $ to be printed for the User, So in all Four variables.The identified variables are P11, MSG1, MSG2 and MSG3.
First Line DATA SEGMENT
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 MSG1 DB 10,13,ENTER ANY STRING :- $
MSG2 DB 10,13,ENTERED STRING IS :- $
MSG3 DB 10,13,CONVERTED STRING IS : $
P1 LABEL BYTE
M1 DB 0FFH
L1 DB ?
P11 DB 0FFH DUP ($)
P1 LABEL BYTE
M1 DB 0FFH
L1 DB ?
Variable Length of Users Choice (i.e. User can enter String of Variable Length) initialized with $ which works as
New Line Character $ is used as (\n) NULL character in C program. P1 is the Start of the Label Byte Data
Type. M1 is used for assigning Maximum Length of the Array. L1 is used to Get the LENGTH of the entered String
by User. P11 is the name refered for the Array in the proram. (A Number Character is of a BYTE size Hence we
have to used only DB Define Byte ) as we dont know the lenght of the Characters in the String. Therefore we take it
approx size 256. Here 0FFH DUP ($) stands for N i.e. Size of Array or Array Size. DUP stands for Duplicate i.e. it
will duplicate the value in All the Array with the value present in Bracket (i.e. $). MSG1 DB 10,13,ENTER ANY
STRING :- $this line is a declaration of Charater Array initialized with ENTER ANY STRING :- $ 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 ). Similarly MSG2 DB 10,13,ENTERED STRING IS :- $ and MSG3 DB 10,13, CONCATENATED STRING
IS :- $.
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 the numbers which we are adding will be integers so DB is sufficient.
LEA DX,MSG
INT 21H
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 dont 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
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 DISPLAY MSG1
DISPLAY MSG1 is Calling of a Macro DISPLAY with Argument MSG1. This will display String Msg1 on Screen.
Next Line LEA DX,P1
MOV AH,0AH
INT 21H
The above three line code is used to Scan the String entered by user Onscreen to the variable length character
Array present in P1 Label Byte and String refered by P11 as Array.
Now, lets understand line by line
LEA DX,P1 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 P1where
OFFSET means effective address and MOV means move second element into the first element.
MOV AH,0AH
INT 21H
The above two line code is used to SCAN the String entered by user Onscreen to the variable length character Array
to the address present in DX.
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 0AH, That means SCAN the String entered by user Onscreen to
the variable length character Array to the address present in DX.
Next Line DISPLAY MSG2
DISPLAY MSG1 is Calling of a Macro DISPLAY with Argument MSG2. This will display String Msg2 on Screen.
Next Line DISPLAY P11
DISPLAY P11 is Calling of a Macro DISPLAY with Argument P11. This will display String P11 on Screen.
Next Line DISPLAY MSG3
DISPLAY MSG3 is Calling of a Macro DISPLAY with Argument MSG3. This will display String Msg3 on Screen.
Next Line LEA SI,P11
MOV CL,L1
MOV CH,0
The above Three line code is used to initialize P11 to SI register, Move L1 (i.e. Actual Length of String Entered) to
CL register and MOV CH,0 is used to move or assign value Zero (decimal value) to CH Register.
Next Line CHECK:
CHECK: is a LABEL and all the words ending in colon (:) are Labels.
SUB [SI],20H
JMP DONE
LWR:
ADD [SI],20H
UPR: is a LABEL and all the words ending in colon (:) are Labels. SUB [SI],20H means subtracting 20H
from Address of SI Register, here we are reducing the ASCII value by 20H to convert Upper case to Lower
case. JMP DONE JMP is Unconditional Jump. This will Jump to Label DONE.
LWR: is a LABEL and all the words ending in colon (:) are Labels. ADD [SI],20H means adding 20H to Address of
SI Register, here we are increasing the ASCII value by 20H to convert Lower case to Upper case.
Next Line DONE: INC SI
DONE: is a LABEL and all the words ending in colon (:) are Labels.INC SI will increment the value present in SI
register by One.
Next Line LOOP CHECK
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).