0% found this document useful (0 votes)
3 views

EXPERIMENT 2

Uploaded by

Sunbal Ghayas
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

EXPERIMENT 2

Uploaded by

Sunbal Ghayas
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

EXPERIMENT 2 –REGISTER, INPUT/ OUTPUT CHARACTERS

& DISPLAY STRINGS

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

General Purpose Register: Can be divided into Data and Index

• Data Registers: Are used for arithmetic and data movement


AX (Accumulator register)
BX (Base Register)
CX (Counter
Register) DX (Data
Register)

• Index Register: Contains the offsets of data and instructions.


BP (Base pointer Register)
SP (Stack pointer Register)
SI (Source Index Register)
DI (Destination Index Register)

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.

Introduction to Input / Output


• In 8086 assembly language, we use a software interrupt mechanism for I/O.
• An interrupt signals the processor to suspend its current activity (i.e. running your
program) and to pass control to an interrupt service program (i.e. part of the operating
system).
• A software interrupt is one generated by a program (as opposed to one generated by
hardware).
• The 8086 INT instruction generates a software interrupt.
• For I/O and some other operations, the number used is 21h.
• A Specific number is placed in the register AH to specify which I/O operation (e.g.
read a character, display a character) you wish to carry out.
• When the I/O operation is finished, the interrupt service program terminates and
program will be resumed at the instruction following int.
Character Input from User
To get the input from keyboard a subprogram at 1h will be called. First 1h will be placed
in ah and then an interrupt 21h generated to call the subprogram. Finally the character will
be placed in al register.

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.

You might also like