EXPERIMENT 2
EXPERIMENT 2
Objective
• In this lab students will learn registers
• Practice how to Input, Output and Display Characters as well as strings.
Time Required : 3 hrs
Programming Language : Assembly Language
Software Required : EMU 8086
Hardware Required : NIL
Registers
Registers are high-speed storage locations directly inside the CPU, designed to be accessed
at much higher speed than conventional memory.
Types of registers
• General purpose Registers
• Segment Registers
• Status Flags Register
• Instruction Pointer
CX (Count Register)
• Contains the count for certain instructions e,g shift count, rotate the number of bytes
and a counter with loop instruction.
• Can be accessed as 32 bit (ECX), 16 bit (CX) or 8 bit (CH or CL) register 32 bit
General Purpose use in ADD, MUL, DIV, MOV Special Purpose use in LOOP etc.
Example:
Mov ah,1h ;keyboard input subprogram
INT 21h ;call the sub program to take character input from the user and store in al
Note:-
• Carriage Return ASCII (0DH) is the control character to bring the cursor to the start of
a line.
;display
Return
mov dl,
0dh mov
ah, 2h
int 21h ; display Carriage Return
• Line-feed ASCII (oAh) is the control character that brings the cursor down to the next
line on the screen. ;display Line-feed mov dl, 0ah mov ah, 2h
int 21h ; display Line Feed
String Output
• A string is a list of characters treated as a unit.
• In 8086 assembly language, single or double quotes may be used to denote a string
constant.
• For Defining String Variables following 3 definitions are equivalent ways of defining a
string "abc":
var1 db "abc" ; string constant
var2 db ‘a’, ‘b’, ‘c’ ; character
constants var3 db 97, 98, 99 ;
ASCII codes
• The first version simply encloses the string in quotes. (preferred method)
• The second version defines a string by specifying a list of the character constants that make
up the string.
• The third version defines a string by specifying a list of the ASCII codes that make up the
string
• In order to display string using MS-DOS subprogram (number 9h), the string must be
terminated with the ‘$’ character.
• In order to display a string we must know where the string begins and ends.
• The beginning of string is given by obtaining its address using the offset operator.
• The end of a string may be found by either knowing in advance the length of the string
or by storing a special character at the end of the string.
EXERCISES
Exercise 2.1
Write a program that input a character from user is in lowercase, the program will convert
it to uppercase and will display it on console after conversion.
Hint: - The ASCII codes for lowercase letters (a-z) are 97-122. In order to convert a
lowercase letter to uppercase letter, just subtract 32 from its ASCII code.
Exercise 2.2
Write a program that input a character from user. The program will display it ten times on
screen in newline.
Exercise 2.3
Write a program that will display uppercase letters (A-Z), using loop on new line.