You are on page 1of 58

Microprocessor Based System Design-Lab Manual

Computer Laboratory Manual


Microprocessor Based System Design
(CE-207)
Computer Engineering Department
Sir Syed ni!ersity o" Engineering # $ec%nology
ni!ersity &oad' (arac%i 7)*00
%t t p +,, --- .ssuet.edu .p /


Sir Syed University of Engineering and Technology Page
Microprocessor Based System Design-Lab Manual
Content
Lab 0 $opic 1age0
1 Explore debugger using different commands 3
2 To understand the basic concept and functionality of Assembly Language. 10
3 To understand the concept of new line using carriage return line feed and macro. 1!
" To understand the concept of displaying string in assembly language.. 20
# To understand the concepts of loop in assembly language. 23
$ To understand the concept of stac% in assembly language. 2#
& 'ntroduction to ()A * !0!$ Training +it 2&
! To understand the basic operations of ()A !0x!$ trainer %it 2,
, To understand the concept of how to access a memory of trainer !0!$ and
understand some Assembly instructions.
3"
10 To understand the different commands of ()A !0x!$ trainer +it 3$
11 -rite a program to display the digits in decimal from 0.& into &.segment "0
12 To initiali/e dot matrix display "3
13 Exploring ()E !0#1 (icrocontroller Trainer 0oards "$
1" 1rogramming !0#1 '23 1orts as 'nput 1orts #3
1# 1rogramming !0#1 '23 1orts as 'nput 1orts and 3utput 1orts #$
Sir Syed University of Engineering and Technology Page !
Microprocessor Based System Design-Lab Manual
L2B03
4B5EC$67E+
Explore debugger using different commands.
$8E4&9+
1&4:&2MM6;: L2;:2:E
A programming language is an artificial language that can be used to control the beha4ior of a
machine particularly a computer. 1rogramming languages li%e human languages ha4e syntactic
and semantic rules to define meaning.
$91ES 4< 1&4:&2MM6;: L2;:2:E
1rogramming languages can be classified into three basic categories on the basis of understanding
le4el of users as well as the machine to which instructions has been gi4en5
3. 86:8 LE7EL L2;:2:ES
A programming language that enables a programmer to write programs
that are more or less independent of a particular type of computer and are designed to gi4e a
better program efficiency. 6uch languages are considered high.le4el because they are closer to
human languages.
2. L4= LE7EL L2;:2:ES
These are designed to ha4e both5 a relati4ely good programming
efficiency and relati4ely good machine efficiency.
*. M2C86;E L2;:2:E
(achine language is at the lowest le4el because it is the actual binary
code of 1s and 0s that the computer understands. These are designed to gi4e a better machine
efficiency.
&E:6S$E&S CL2SS6<6C2$64; 5 The registers inside the microprocessor are classified
according to the function they perform.
'n general they are classified as
1. )ata registers
2. Address registers
3. 6egment register
". 3ffset registers
#. 6tatus register
Sir Syed University of Engineering and Technology Page "
Microprocessor Based System Design-Lab Manual
S4ME :E;E&2L 1&14SE &E:6S$E&S+
2> (2CCML2$4& &E:6S$E&)
't is the preferred register to use in the arithmetic logic and data transfer instructions
because its use generates the shortest machine code.
'n multiplication and di4ision operations one of the numbers in4ol4ed must be in A7 or
AL.
'nput and output operation also re8uires the use of A7 and AL.

B> (B2SE &E:6S$E&)
't is used to store the data also it ser4es as an address register.
C> (C4;$ &E:6S$E&)
1rogram loop instructions are facilitated by the use of 97 register ser4es as a loop counter.
Also used as a counter in the string operations.
9L is used as count in instructions that shift and rotate bits.
D> (D2$2 &E:6S$E&)
't is used in multiplication and di4ision operations.
't is used in '3 operation li%e )L in character output and )7 in string output functions.
&E:6S$E& S6?E+
-e ha4e three different si/es of registers5
!.bit register5 A: AL 0: 0L 9: 9L ): )L
1$.bit registers5 A7 07 97 )7 61 01 6' )' 66 )6 96 E6 ;6 <6 '1 ;LA<6
32.bit registers5 EA7 E70 E97 E)7 E6' E)' E61 E01 E'1 and E;LA<6.
B2S6C M47 6;S$&C$64;
The basic (3= instruction is used to transfer data between registers between and memory
locations or to ha4e a number directly to a register or memory location.
Synta@+ M47 Destination' Sourc
E>2M1LES+
(3= A: 0L > !.bits register to register
(3= 07 A7 > 1$.bits register to register
(3= byte1 0L > !.bit register to memory
(3= A7 word1 >1$.bit memory to register
Sir Syed University of Engineering and Technology Page #
Microprocessor Based System Design-Lab Manual
S4ME 2&6$8ME$6C 6;S$&C$64;S
2DD5Add the contents of source operand1 to source operand 2 and result store in the
source operand1.
Synta@+ 2DD Source operand3' Source operand2
E>2M1LE + 2DD 2L' BL
SB5 6ubtract the contents of source operand1 to source operand 2 and result store in the
source operand1.
Synta@+ SB Source operand3' Source operand2
E>2M1LE + SB 2L'BL
DEB: 1&4:&2M+
To create a program in assembler two options exist the first one is to use the assembler program
such as TA6( or Turbo Assembler from 0orland and the second one is to use the debugger . on
this first section we will use this last one since it is found in any 19 with the (6.)36 which
ma%es it a4ailable to any user who has access to a machine with these characteristics.
)ebug can only create files with a .93( extension and because of the characteristics of these
%inds of programs they cannot be larger that $" %b and they also must start with displacement
offset or 0100: memory direction inside the specific segment.
)ebug pro4ides a set of commands that lets you perform a number of useful operations
2 Assemble symbolic instructions into machine code
D )isplay the contents of an area of memory
E Enter data into memory beginning at a specific location
: ?un the executable program in memory.
; @ame a program
1 1roceed or execute a set of related instructions
Sir Syed University of Engineering and Technology Page $
Microprocessor Based System Design-Lab Manual
A Auit the debug program
& )isplay the contents of one or more registers
$ Trace the contents of one instruction
Bnassembled machine code into symbolic code
= -rite a program onto dis%
't is possible to 4isuali/e the 4alues of the internal registers of the 91B using the )ebug
program. To begin wor%ing with )ebug type the following prompt in your computer5
C+,BDebug CEnterD
3n the next line a dash will appear this is the indicator of )ebug at this moment the
instructions of )ebug can be introduced using the following command5
-rCEnterD
A7C0000 07C0000 97C0000 )7C0000 61C;;EE 01C0000 6'C0000 )'C0000
)6C0)$2 E6C0)$2 66C0)$2 96C0)$2 '1C0100 @= E' 1L @D @A 13 @9
0)$250100 2E 965
0)$250101 !03E)3);00 9(1 0ETE 1T? F);)3G00 965);)3C03
All the contents of the internal registers of the 91B are displayed> an alternati4e of 4iewing
them is to use the HrH command using as a parameter the name of the register whose 4alue
wants to be seen.
<or e@ample+
.rbx
07 0000
5
2SSEMBLE& S$&C$&E
'n assembly language code lines ha4e two parts the first one is the name of the instruction which is
to be executed and the second one are the parameters of the command. ;or example5
add a%'b%
Sir Syed University of Engineering and Technology Page %
Microprocessor Based System Design-Lab Manual
:ere HaddH is the command to be executed> in this case an addition and HahH as well as HbhH are the
parameters.<or e@ample+
mo! al' 2)
'n the abo4e example we are using the instruction mo4 it means mo4e the 4alue 2# to al
register.The name of the instructions in this language is made of two three or four letters. These
instructions are also called mnemonic names or operation codes since they represent a function the
processor will perform.
D6&EC$ 2DD&ESS6;:
6ometimes instructions are used as follows5
add al'C370D
The brac%ets in the second parameter indicate to us that we are going to wor% with the content of
the memory cell number 1&0 and not with the 1&0 4alue this is %nown as direct addressing.
Creating basic assembler program+
a 100FenterG
mo4 ax0002FenterG
mo4 bx000"FenterG
add axbxFenterG
nopFenterGFenterG
95IJdebug
.a 100
0)$250100 mo4 ax0002
0)$250103 mo4 bx000"
0)$25010$ add axbx
0)$25010! nop
0)$25010,
Type the command HtH KtraceL to execute each instruction of this program example
Sir Syed University of Engineering and Technology Page &
Microprocessor Based System Design-Lab Manual
.t
A7C0002 07C0000 97C0000 )7C0000 61C;;EE 01C0000 6'C0000 )'C0000
)6C0)$2 E6C0)$2 66C0)$2 96C0)$2 '1C0103 @= E' 1L @D @A 13 @9
0)$250103 000"00 (3= 07000
Eou see that the 4alue 2 mo4e to A7 register. Type the command HtH KtraceL again and you
see the second instruction is executed.
.t
A7C0002 07C000" 97C0000 )7C0000 61C;;EE 01C0000 6'C0000 )'C0000
)6C0)$2 E6C0)$2 66C0)$2 96C0)$2 '1C010$ @= E' 1L @D @A 13 @9
0)$25010$ 01)! A)) A707
Type the command HtH KtraceL to see the instruction add is executed you will see the follow
lines5
.t
A7C000$ 07C000" 97C0000 )7C0000 61C;;EE 01C0000 6'C0000 )'C0000
)6C0)$2 E6C0)$2 66C0)$2 96C0)$2 '1C010! @= E' 1L @D @A 1E @9
0)$25010! ,0 @31
LA0 30ME9T'=E65 LA0 30ME9T'=E65
TA6+N1 TA6+N15 5 )isplay the contents of the defined memory locations 120 133 122 using D
command.
TA6+N25 TA6+N25 Edit the contents of the abo4e memory locations 120 133122 by 020"03
respecti4ely using E command.
TA6+N35 TA6+N35 Then again display the contents of the memory locations which we edit in the Tas%N
2.
TA6+N"5 TA6+N"5 Add the contents of the abo4e defined memory location using mo! instruction.
TA6+N#5 TA6+N#5 6ubtract the content of 120 location by 133 and then store the result in the120 location
and add the new 120 location contents with the content of 122 location.
Sir Syed University of Engineering and Technology Page '
Microprocessor Based System Design-Lab Manual
TA6+N$5 TA6+N$5 1erform the following debug acti4ities
2C$ 3.3 + 2C$ 3.3 + Use debug command U100 to un-assemble the instructions in ACT 1.1. What is the
machine code corresponding to each assembly code instruction.
2ssembly Code Mac%ine Code
mo! a@'2EFG%
add a@'*7GH%
mo! b@'a@
sub b@'2E0)
nop
2C$ 3.2 + 2C$ 3.2 + How many bytes does it need to represent each instruction in binary.
2ssembly Code ;o. 4" Byte
mo! a@'2EFG%
add a@'*7GH%
mo! b@'a@
sub b@'2E0)
nop
2C$ 3.* + 2C$ 3.* + What are the contents of C ! "# ! A$ % &$ '. Use debug command ( to display these
information.
&egister Content
CS
61
2>
B>
2C$ 3.G + 2C$ 3.G + #redict the contents of the following registers after e)ecution of each instruction C ! "# !
A$ ! &$
&egister Mo! a@'2EFG 2dd a@'*7HG Mo! b@'a@
CS
61
2>
B>

L2B02
4B5EC$67E
Sir Syed University of Engineering and Technology Page (
Microprocessor Based System Design-Lab Manual
$o understand t%e basic concept and "unctionality o" 2ssembly Language.
$8E4&9
2SSEMBL9 L2;:2:E
Assembly language is a machine specific programming language with a
one.to.one correspondence between its statements and the computerOs nati4e machine language.
There are many different types of assembly language each specific to a processor or processor
family. '0(.19 assembly language refers to instruction recogni/ed by a number of different
microprocessors in the 'ntel family5 !0!$ !0!! !01!$ !02!$ !03!$ !0"!$ and 1entium.
SES+
Assembly language is used most often when either communicating with the operating
system or directly accessing computer hardware.
6econdly assembly language is used to optimi/e certain critical areas of application
programs to speed up their runtime execution.
2SSEMBLE&
An assembler is a program that con4erts source code programs from the assembly
language into machine language. The assembler can optionally generate a source. listing file with
line numbers memory addresses source code statements and a cross.reference listing of symbols
and 4ariables used in a program.
The most popular assemblers for the 'ntel family are (A6( K(icrosoft AssemblerL TA6( KTurbo
AssemblerL.
L6;(E&
A companion program that combines indi4idual files created by an assembler into a
single executable file
DEB::E&
A program that pro4ides a way for a programmer to trace the execution of a program and
examine the contents of memory.
M6C&41&4CESS4& 2&C86$EC$&E
As assembly language is microprocessor specific so before writing assembly language
programs it is re8uired to %now the architecture of that microprocessor.
E0EF M6C&41&4CESS4&+
-e will be studying the assembly language for the microprocessor !0!$.
Sir Syed University of Engineering and Technology Page )
Microprocessor Based System Design-Lab Manual
!0!$ microprocessor is a 1$.bit microprocessor Ka 1$.bit microprocessor can operate on
the 1$.bits of data at a timeL ha4ing 1$. bit registers.
1$.bit data bus and 20.bit address bus.
't can access 1 (0 of total memory.
To write the assembly language programs for !0!$ microprocessor we are re8uired to %now the
internal organi/ation at least programming model
1&4:&2MM6;: M4DEL+
The programming model of the !0!$ through 1entium '' is considered to be program 4isible
because its registers are used during application programming and are specified by the
instruction.3ther registers are considered to be program in4isible because they are not addressed
directly during application programming but may be used indirectly during system programming.
&E:6S$E&S CL2SS6<6C2$64;5 The registers inside the microprocessor are classified
according to the function they perform.
'n general they are classified as
)ata registers
Address registers
6egment register
3ffset registers
6tatus register
S4ME :E;E&2L 1&14SE &E:6S$E&S+
<eneral purpose register we already defined in the Lab N1.
SE:ME;$ 2;D 4<<SE$ &E:6S$E&S+
Address registers store addresses of instructions and data in memory.
These 4alues are used by the microprocessor to access memory locations.
E4ery memory location is actually identified by an address of 20.bit.
-e are ha4e the registers of 1$.bits son that o4er 20.bit address K1hysical AddressL is store
into two parts in two 1$.bit registers called segment number and offset
A memory segment is a bloc% of 2P1$ K$" +L consecuti4e memory bytes.
A segment number called segment address Kstarting with 0L identifies each segment.
A segment number is 1$ bits so the highest segment number is ;;;;h.
-ithin segment gi4ing an offset number called the offset identifies a memory location.
This is the number of bytes from the beginning of the segment.
-ith a $"+0 segment the offset can be gi4en as a 1$.bit number.
The first byte in a segment has offset 0.
The last offset in a segment is ;;;;h.
1&4:&2M SE:ME;$S
A machine language program consists of instructions KcodeL and data.
Sir Syed University of Engineering and Technology Page
Microprocessor Based System Design-Lab Manual
A data structure called 6tac% is used by the microprocessor to implement procedure calls.
The programOs code data and stac% are loaded into different memory segments called code
segment data segment and the stac% segment.
SE:ME;$ &E:6S$E&S
To %eep trac% of the 4arious program segments the !0!$ microprocessor is e8uipped
with four segment registers to hold the segment numbers.
The 96 )6 and 66 registers contain the code data and stac% segment numbers
respecti4ely.
'f a program needs to access a second data segment it can use the E6 KExtra 6egmentL
register.
146;$E& 2;D 6;DE> &E:6S$E&S
The registers 61 01 6' and )' normally points to Kcontain the offset address ofL memory
location.
These registers can be used in arithmetic and other operations.
S1 (S$2C( 146;$E&)
The 61 register contains the offset of the top of stac%.
The 61 and 66 registers combine to form the complete address of the top of the stac%.
B1 (B2SE 146;$E&)
The 01 register contains an assumed offset from the 66 register as does the stac% pointer.
The 01 register is often used by a subroutine to locate 4ariables that were passed on the
stac% by a calling program.
The 01 register can be used for other segment unli%e 61 register.
S6 (S4&CE 6;DE>)
The 6' register is used to point to memory locations in the data segment addressed by )6.
This register ta%es its name from the string mo4ement instructions in which the source
string is pointed to by the 6' register.
D6 (DES$6;2$64; 6;DE>)
The )' register performs the same operation as the 6' register.
The )' register acts as the destination for string mo4ement instructions.

C4;$&4L &E:6S$E&
61 (6;S$&C$64; 146;$E&)
The '1 register contains the offset of the next instruction to be executed within the current
code segment.
The '1 and 96 registers combine to form the complete address of the next instruction.
Sir Syed University of Engineering and Technology Page !
Microprocessor Based System Design-Lab Manual
<L2:S (<L2:S &E:6S$E&)
This is a special register with indi4idual bit positions assigned to show he status of the 91B
or the results of arithmetic operations.
Each rele4ant bit is gi4en a name and others are undefined.
2SSEMBL9 1&4:&2M S9;$2>
Assembly language program consists of statements.
A statement is either an instruction to be executed when the program runs or a directi4e for
the assembler.
A program normally consists of three parts or segments.
D2$2 SE:ME;$
=ariables are declared in the data segment.
Each 4ariable is assigned space in memory and may be initiali/ed.
E@p+
A )- 3#01:
't sets memory for a 4ariable called A and initiali/e it to 3#01:.
)- . )efine word K1$ bits C 2 memory locationsL
A )- KQL > un. initiali/ed 4ariable
C4DE SE:ME;$
1rogram instructions are placed in the code segment. 'nstructions are actually organi/ed
into units called procedures. E4ery procedure starts with a line.
E@p+
Main 1rocI
(ain is the name of procedure and 1?39 is the directi4e identify the start of the procedure
Main EndpI
(ain is again the name of the procedure and Endp is the direciti4e > identifies the end
of the procedure
S$2C( SE:ME;$
The stac% segment is used for temporary storage of addresses and data. 'f no stac% segment
is declared an error message is generated so there must be a stac% segment e4en if the
program doesnOt utili/e the stac%.
These segments begin with the directi4es .stac/ .code and .data
1&4:&2M S9;$2>
T'TLE first program syntax
.(odel 6mall >6pecifies the memory model used
.6tac% 100: >allocate 100: memory locations for stac%
.)ata >start of the data segment
> )ata definitions here
A )0 Q
RR..
.9ode >start of the code segment
Sir Syed University of Engineering and Technology Page "
Microprocessor Based System Design-Lab Manual
(ain 1roc >start of the first procedure
> instructions here
RR
(ain Endp >end of the first procedure
> 3ther procedures here
End (ain >end of the complete assembly program
B2S6C D6&EC$67ES
;ollowing are the description of commonly used directi4es>
M4DEL+ 't is used to specify the memory model used for program to identify the si/e of code and
data segments.
S$2C(+ )efines the si/e of stac% used in program
D2$2+ )efines the data segments for data used in the program. (ar% the beginning of the data
segment
C4DE+ 'dentifies the code segment which contains all the statements. Also .code mar%s the
beginning of the code segment.
1&4C+ 0eginning of the procedure
E;D1+ End of the procedure
E;D+ End of assembly language program
B2S6C M47 6;S$&C$64;+
-e already defined in the LabN1
&ES$&6C$64;S+
(o4e between memory to memory is not allowed.
A number directly inside a segment register is not allowed.
6egment to segment registers mo4e is not allowed.
6;1$,4$1$ 41E&2$64;S
To display a character is an output operation.
-e actually want to display single character from the microprocessor to the screen.
-e donOt ha4e any instruction that perform this operation li%e printf in 9 language.
-e actually use the ser4ice routines which are already designed and assembled programs to
perform the '3 operations.
Sir Syed University of Engineering and Technology Page #
Microprocessor Based System Design-Lab Manual
There are two categories of ser4ice routines
Basic 6nput 4utput System (B64S) routines
D4S routines
The 0'36 routines are stored in ?3( and interact directly with the '23 ports. -e carry out basic
screen operations.
The )36 routines are the part of the operating system running into the system.
)36 routines can carry out more complex tas%s e.g. printing a character string.
)36 routines actually use the 0'36 routines to perform direct '23 operations.
6;$ 6;S$&C$64;
'@T instruction is used to in4o%e a )36 or 0'36 routine.
6yntax '@T 10: K 0'36 routine callL
'@T 21: K)36 routine callL
<;C$64; ;MBE& # 28 &E:6S$E&
A routine is actually a collection of different functions.
A function is a set of basic instructions used to actually perform the operation.
A5-hen we call a routine it means we are in4o%ing a large number of )36 functions but which
functionQ
A5A particular function is re8uested by placing a function number in the A: register and in4o%ing
'@T 21:.
6;$ 23%+
This can be used to in4o%e large number of )36 functions. A particular function is re8uested by
placing a function number in the A: register and in4o%ing '@T 21h.
;or E.g. following functions can be used in our program5
<unction ;o. &outine
02h 6ingle character output
Single C%aracter 4utput
(3= A:02: I display c%aracter "unction
Sir Syed University of Engineering and Technology Page $
Microprocessor Based System Design-Lab Manual
(3= )LOQO I c%aracter is JKL
'@T 21h I c%aracter -ill be displayed
Sample 1rogram
4B5EC$+ 4B5EC$+
Title a program that displays single character on screen.
S4&CE C4DE+ S4&CE C4DE+
.model small *specify memory model
.stac/ 300% * specify si+e of stac,
.code * start of the code segment
main proc * start of the first procedure
mo! a%'02% * display a single character
mo! dl'M2M * transfer A to register dl
int 23% * -. routine interrupt
mo! a%'Gc% * e)it -. function
int 23%
main endp
end main
S$E1S $4 <4LL4=+
2SSEMBL6;:+
1.<o to preferencesAssemblywrite your file name with .asm extension.
Sir Syed University of Engineering and Technology Page %
Microprocessor Based System Design-Lab Manual
4$1$+
2.<o to preferences)36 tool-rite your file name.
Sir Syed University of Engineering and Technology Page &
Microprocessor Based System Design-Lab Manual
L2B0*
4B5EC$67E
To understand the concept of new line using carriage return line feed and macros.
$8E4&9
6;$ 23%+
This can be used to in4o%e large number of )36 functions. A particular function is re8uested by
placing a function number in the A: register and in4o%ing '@T 21h.
;or E.g. following functions can be used in our program5
<unction ;o. &outine
1h 6ingle %ey input
E@amples+
Single (ey 6nput
(3= A:01: I input /ey "unction
'@T 21h
M2C&4S
A macro is a bloc% of code that has been gi4en a name and when the compiler encounters such
name it expands the macro copies the bloc% of code at the place of in4ocation into the program.
The text may contain instructions or references to other macros.
The basic ad4antage of using a macro is to create new instructions. These macros can be a part of
the program or they can be written in a separate file and that file can be included in the program.
There is a list of useful macros which are helpful to be %ept in the macro library of the assembly
language compiler and these can be used in other user programs.
These can also be written in the lines of code of the program without any name gi4en to them.
Sir Syed University of Engineering and Technology Page '
Microprocessor Based System Design-Lab Manual
E@ample+
C2&&62:E &E$&;
This macro can be used for the purpose of carriage return.
C2&N&$; M2C&4
M47 28' GC8
6;$ 238
E;DM
3nce declared and defined this macro can be in4o%ed anywhere in the program by the name
9A?S?T@.The name of the macro can be any string as defined by the user.
L6;E <EED
This macro can be used to feed a new line in the output and is 4ery useful as a new line is needed
many times during a formatted output.
;E=NL6;E M2C&4
M47 28' 028
M47 DL' 0D8
6;$ 238
M47 DL' 028
6;$ 238
E;DM
3nce declared and defined this macro can be in4o%ed anywhere in the program to insert a new
line. The name of the macro can be any string as defined by the user.
LA0 30ME9T'=E5 LA0 30ME9T'=E5
$as/035-rite a program that ta%es a single character input and displays it in a new line.
Sir Syed University of Engineering and Technology Page (
Microprocessor Based System Design-Lab Manual
L2B0G
4B5EC$67E
$o understand t%e concept o" displaying string in assembly language.
$8E4&9+
<unction ;o. &outine
,h 9haracter 6tring 3utput
E@ample 5
C%aracter String 4utput
M47 28' 0H8 I input /ey "unction
M47 D>'4<<SE$ MS: I mo!es t%e o""set o" t%e msg to t%e
register
6;$ 23%
S$&6;:S+
A string is a list of characters treated as a unit. 'n programming languages we denote a string
constant by using 8uotation mar%s e.g. TEnter first numberU.
'n !0!$ assembly language single or double 8uotes may be used.
De"ining String 7ariables
The following 3 definitions are e8ui4alent ways of defining a string VabcO5
4ersion1 db TabcU > string constant
4ersion2 db VaO VbO VcO > character constants
4ersion3 db ,& ,! ,, > A69'' codes
The first 4ersion uses the method of high le4el languages and simply encloses the string in 8uotes.
This is the preferred method.
The second 4ersion defines a string by specifying a list of the character constants that ma%e up the
string.
-e may also combine the abo4e methods to define a string as in the following example5message db
T:ello worldU 13 10 VWO
Sir Syed University of Engineering and Technology Page !)
Microprocessor Based System Design-Lab Manual
S$&6;: 4$1$
(6.)36 pro4ides subprogram number H% to display strings which are terminated by the JOL
character. 'n order to use it we must5
3. Ensure the string is terminated with the VWO character.
2. 6pecify the string to be displayed by storing its address in the d@ register.
*. 6pecify the string output subprogram by storing ,h in ah.
G. Bse int 21h to call (6.)36 to execute subprogram ,h.
).
(ey-ord + MS:
The message to be displayed in the output can also be declared in the data segment using
the %eyword (6< mo4ing the string in the register )0 and can be used afterwards.
(6< )0 V:ELL3XWO
The TWU mar%s the end of the string and is not displayed. 'f the string contains the A69'' code of a
control character the control function is performed.
Sample 1rogram
S4&CE C4DE+ S4&CE C4DE+
4bPect+ -rite a program to display a string.
.model small ; specify memory model
.stac% 100h ; specify size of stack
.data ; start of the data segment
msg1 db YType 9haracter 5 WY
.code ; start of the code segment
main proc ; start of the first program
mo4 axZdata
mo4 dsAx ; mov content ax to ds
mo4 dxoffset msg1
mo4 Ah0,h ; reads from offset and display on output
int 21h ; interrupt call
mo4 Ah"ch ; exit dos function
int 21h ; interrupt call
Sir Syed University of Engineering and Technology Page !
Microprocessor Based System Design-Lab Manual
end main
LA0 30ME9T'=E65 LA0 30ME9T'=E65
$2S(035 -rite a program to display your bio data using carriage return and line feed macro
$2S(035 -rite a program to ma%e your 3
rd
semester mar% sheet.
L2B0)
4B5EC$67E+
Sir Syed University of Engineering and Technology Page !!
Microprocessor Based System Design-Lab Manual
To understand the concepts of loop in assembly language
$8E4&9
Loop
A loop is a se8uence of instructions that is repeated. The number of times to repeat may be %nown
in ad4ance or it may depend on conditions i.e. itOs a count controlled loop.
<4& Loop
This is a loop structure in which the loop statements are repeated a %nown number of times.
(E9=4&D+ L441
A ;3? loop is implemented using the L331 instruction. The counter for the loop is the 97
register which is initiali/ed to loopScount which is the number of times the loop is executed.
Execution of the L331 instruction causes 97 to be decremented automatically. 'f 97 becomes
0the next instruction after loop is done.
Sample 1rogram+
S4&CE C4DE+
4bPect+$itle a program t%at prints a c%aracter 300 times.
.model small
.stac% 100h
.code
main proc
mo4 ah 02h Idisplay a c%aracter
mo4 cx 100 Inumber o" times loop -ill e@ecute
mo4 dl V[O I2SC66 code o" c%aracter 0

print5 Iloop starts "rom %ere
int 21h
loop print Ie@ecutes t%e <4& loop
mo4 ah "ch Iterminates t%e current process
int 21h
main endp
end main
<igure . <4& L441
Sir Syed University of Engineering and Technology Page !"
count*
)
count* count -

Statemen
ts
+nitiali,e
count
Microprocessor Based System Design-Lab Manual
;alse
True
LA0 30ME9T'=E65 LA0 30ME9T'=E65
$as/ 003+-rite a program to print V[O 100 times using linefeed and carriage return.
$as/002+-rite a program to print A69'' characters.
$as/00*+-rite a program to print your name 10 times using linefeed and carriage return.
L2B0F
4B5EC$67E+ 4B5EC$67E+
Sir Syed University of Engineering and Technology Page !#
Microprocessor Based System Design-Lab Manual
To understand the concept of stac% in assembly language.
Sample 1rogram+
L2B0)
$2S(+ $2S(+
Ta%e input from user at run time and show the output in re4erse order.
Sir Syed University of Engineering and Technology Page !$
S4&CE C4DE+
4bPect+ $a/e t%e input "rom user at run time and s%o- output in re!erse order.
.model small
.stac% 100h
.code
main proc
mo4 ah02h
mo4 dlQ
int 21h
xor cxcx
mo4 ah01h
int 21h
whileS5
cmp al0dh
\e endSwhile
push ax
inc cx
int 21h
\mp whileS
endSwhile5
mo4 ah02h
mo4 bl0dh
int 21h
mo4 ah02h
mo4 dl0ah
int 21h
\ex/ exit
top5
pop dx
int 21h
loop top
exit5
moh ah"ch
int 21h
main endp
end main
Microprocessor Based System Design-Lab Manual
'nput a string5
6tring in ?e4erse 3rder5
L2B07 L2B07
Sir Syed University of Engineering and Technology Page !%
Microprocessor Based System Design-Lab Manual
4B5EC$67E+ 4B5EC$67E+
'ntroduction to ()A * !0!$ Training +it
6;$&4DC$64;+
()A.!0!$ has high performance $"+.byte monitor program. 't is designed for easy function.
After power is on the monitor begins to wor%. 'n addition to all the %ey function the monitor has a
memory chec%ing routine.
The following is a simple description of the %ey functions.
<;C$64; 4< (E9S+
$EC8;6C2L S1EC6<6C2$64;S+
Sir Syed University of Engineering and Technology Page !&
Microprocessor Based System Design-Lab Manual
91B !0!$
Sir Syed University of Engineering and Technology Page !'
Microprocessor Based System Design-Lab Manual
(ain ?A( $" +0 K$22#$ x 2L
(onitor ?3( $" +0 K2&92#$ x 2L
)isplay Bnit L9) K1$ x 2 LineL
'23 1ort !2##A
6erial 1ort ?6.2329 K!2#1A x 1L
6ystem 9loc% ".,1#2 (:/
9loc% <enerator !2!"
'nterrupt 9ontroller !2#,
Le4el (eter 10 step
)3T (atrix ! x ! K3 9olorL
3peration 6ystem 6oftware !0!$ Assembler
+eyboard 1$ +ey of data 10 +ey of function
6ystem bus indicator LE) K3]L x 12
Expansion 9onnector
6ystem bus $2pin x 1
External 'nterface 20pin x 1
6tep (otor 'nterface )ri4er T.? x "
A2) )2A 9on4erter
A)9 5 A)9 0!0"
)A9 5 )A9 0!00
1ower 110=2220=
0oard si/eKmmL 310 x 2$#
-ood caseKmmL 100K:L x 300K)L x "30K-L ^ 10KmmL
2bout MD2 Q E0EF+ 2bout MD2 Q E0EF+
- ()A is a company name T(idas EngineeringU.
- 't is a trainer board of !0!$ microprocessor ha4ing an '9 on !0!$ inside.
- 't consists of an L9) screen 1$ data %eys and 10 function %eys.
- 't has 2 ?A( K2x32+bL and 2 ?3( K2x32+bL included.
- 't can be operated in two modes
o +'T (3)E
o 19 (3)E
- 't also includes a & segment dot matrix )2A A2) Le4el meter and stepping motor pro\ects.
L2B0E
Sir Syed University of Engineering and Technology Page !(
Microprocessor Based System Design-Lab Manual
4B5EC$67E+
To understand the basic operations of ()A !0x!$ trainer %it.
$8E4&9+ $8E4&9+
3n a power up following message will be displayed on L9).
6o as to use serial monitor mo4e \umper 11 which located on the 190 li%e this.

-hene4er ?E6 is pressed the display becomes ;'<B?E 1.1 and user can operate %eyboard only in
this situation.
E>2M1LE 3. 6ET T:E 93@TE@T6 '@ (E(3?E.
Sir Syed University of Engineering and Technology Page ")
Microprocessor Based System Design-Lab Manual

Sir Syed University of Engineering and Technology Page "
Microprocessor Based System Design-Lab Manual

Sir Syed University of Engineering and Technology Page "!
Microprocessor Based System Design-Lab Manual
$as/03+ $as/03+ 1er"orm t%e "ollo-ing operation on MD2 Q E0EF.
Set Segment and o""set address 0000+3000
Enter eRui!alent mac%ine code o" t%e "ollo-ing statements.
M47 2L ' *E
2;D 2L ' 0<
Sir Syed University of Engineering and Technology Page ""
Microprocessor Based System Design-Lab Manual
Steps+ Steps+
3. 2D 0000
2. + 3000
*. D2 B0 M47 2L ' *E
G. S *E
). S 2G
F. S 0< 2;D 2L ' 0<
7. S H0 ;41
E. 1ress again + /ey and t%en set o""set !alue -%ic% you set starting o" t%e program.
H. S$1
30. &E: S%o- 2> T &esult
C2LCL2$64;+ C2LCL2$64;+
0011 0011 1110 3E 1110 3E
_ 0000 _ 0000 1111 0; 1111 0;
0000 0000 1110 0E 1110 0E
&ESL$+ &ESL$+
After entering the abo4e commands in the ()A * !0!$ the following result was obtained5
A7 C 0E A7 C 0E
-hich is the 4erification of the calculated answerX
Sir Syed University of Engineering and Technology Page "#
Microprocessor Based System Design-Lab Manual
L2B0H
4B5EC$67E+
To understand the concept of how to access a memory of trainer !0!$ and
understand some Assembly instructions.

$8E4&9+
:ow to retrie4e data from memory.1ut some data on memory location Ke.g 200 and
300L and retrie4e data to the specified location.

F200G
F201G
F300G F301G
Code+
(3= A7F200G
(3= 07F300G
A)) A707
(3= F200G07
6B0 A707
Steps to "ollo-+
1. ;irst store some data on location number F200G e.gK000#L
2. 6econdly store some data on location number F300G e.gK000$L
3. Then again set segment 5offset K000051000L
". Enter e8ui4alent machine code of the abo4e code.
#. 6et again offset 000051000
$. 1ress 6T1 and then ?E<
&. And 4erify result.
Sir Syed University of Engineering and Technology Page "$
0#
00
R..
R..
0$
00
R..
R.
Memor
y
Microprocessor Based System Design-Lab Manual
$as/02+
$8E4&9+
S8L+ S%i"t Logical Le"t+
'ntel !0x!$> shifts the contents of a data register or memory location K! 1$ or 32
bitsL to the left Ktowards most significant bitL by a specified amount Kby 1 by 0 to 31 bits specified by an
immediate operand.
S8&+ S%i"t Logical &ig%t+
'ntel !0x!$> shifts the contents of a data register or memory location K! 1$ or 32
bitsL to the right Ktowards least significant bitL by a specified amount Kby 1 by 0 to 31 bits specified by an
immediate operand.
<ollo-ing lab -ill be per"orm on /it mode.
4bPecti!e+
-rite a program to transfer following 4alues in the specified registers
ALCAA0LC;0)LC!A9LC03
Bsing (i)as !0!$ trainerfind the 4alue of AL at the end of the following instructions5
iL A)) AL 0L
iiL 6B0 AL0L
iiiL 6:L )L9L
i4L 6:? )L9L
4L A@) AL0L
4iL 3? AL0L
4iiL 73? AL0L
4iiiL @3T AL
Steps to "ollo-+
iL ;ind the e8ui4alent machine code of the abo4e code.
iiL Enter machine code in the !0!$ Trainer %it.
iiiL =erify result using 6T1 snd ?E< %ey
L2B030
Sir Syed University of Engineering and Technology Page "%
Microprocessor Based System Design-Lab Manual
4B5EC$67E+
To understand the different commands of ()A !0x!$ trainer +it.
$8E4&9+
SE&62L M4;6$4&
6erial monitor is the basic monitor program to do data communicate between ()A.!0!$ and computer.
4peration serial monitor command
Bser can only use command which stored at serial monitor. 6erial monitor can execute to command
when user type command and then 9?Kcarriage returnL %ey.
'f there is no any command at serial monitor error message will be )isplayed with bell sound
and serial monitor prompt will be displayed again.

!0!$ JQ
8EL1 C4MM2;D
E segment 5 offset...................5 Enter )ata To (emory
D segment 5 offset length............5 )ump (emory 9ontents
& Fregister nameG..................5 ?egister )isplay _ 9hange
M address1 length address2........5 (o4e (emory ;rom 1 to 2
< address length data..............5 ;ill (emory -ith Any )ata
L ?eturn %ey.......................5 1rogram )own Load
: segment 5 offset...................5 Execute 1rogram
$..................................5 1rogram 1 step execute
Sir Syed University of Engineering and Technology Page "&
** 8086 Monitor
1.0 **
** Midas 335-
Microprocessor Based System Design-Lab Manual
C4MM2;DS+
3. Memory modi"y command
Synta@+ E segment+ o""set
1urpose+ This command is used to enter data to memory.
E@ample+
!0!$ J E 000051000
000051000 ;; Q 11
000051001 ;; Q 22
000051002 ;; Q 33
000051003 ;; Q ""
00005100" ;; Q ##
00005100# ;; Q 2 K3ffset decrementL
00005100" ## Q
2.Memory display command
Synta@+ D segment+ o""set
1urpose+ This command is used to display the data stored in memory.
E@ample+
!0!$J ) 000051000
000051000 11 22 33 "" ## ;; ;; ;; . ;; ;; ;; ;; ;; ;; ;; ;;
000051020 ;; ;; ;; ;; ;; ;; ;; ;; . ;; ;; ;; ;; ;; ;; ;; ;;
*.Display &egisters Command.
Synta@+ &
1urpose+The ? command is used to display the !0!$ processor registers
E@ample+
E0EF B &
A7C0000 07C0000 97C0000 )7C0000
61C0#"0 01C0000 6'C0000 )'C0000
)6C0000 E6C0000 66C0000 96C0000
'1C1000 ;LC0000 C . . . . . . .
$o c%ange indi!idual register+-
E0EF B & 2>
Sir Syed University of Engineering and Technology Page "'
Microprocessor Based System Design-Lab Manual
A7 C 0000 123"
E0EF B & B>
07 C 0000 "#$&
E0EF B & C>
97 C 0000 &&!!
E0EF B & D>
)7 C0000 1111
$o see t%e result+
E0EF B &
A7C123" 07C"#$& 97C&&!! )7C1111
61C0#"0 01C0000 6'C0000 )'C0000
)6C0000 E6C0000 66C0000 96C0000
'1C1000 ;LC0000 C . . . . . . .
$2S(03+
3-To store the following data to the gi4en addresss
2-)isplay all registers with its content.
LetOs store the following li%e to 01000: ` 01003:
2DD&ESS D2$2
01000 A0
01001 9)
01002 E;
01003 3"
$2S(02+
3.To enter data from 000050000 memory address to 000050020 memory address using command.
Sir Syed University of Engineering and Technology Page "(
Microprocessor Based System Design-Lab Manual
2.)isplay the data you entered in tas%N1 using command.
*.9hange all register content using command then display all registers.
$2S(0*+
1.;ill the data #$&!123" from "000 to "100 addresses
2.(o4e the abo4e filled data to address 2000
3.Assume your roll number as data and fill it from 0 to 2#$ addresses.@ote your roll no should
contain four digit.Example 0001
L2B 0 33
Sir Syed University of Engineering and Technology Page #)
Microprocessor Based System Design-Lab Manual
4B5EC$67E+
-rite a program to display the digits in decimalfrom 0.& in to &.segment.
$8E4&9+
7 SE:ME;$ D6S1L29+ 7 SE:ME;$ D6S1L29+
The & segment inside the ()A * !0!$ trainer %it can be used to display numbers.
This re8uires 1'3 !2## ports which are already connected to the & segment internally.
Through the code we can access these ports and pro4ide binary or hex 4alue to switch the re8uired
segment on and off.
'n order to turn a segment 3@ a logical 0 is re8uired as shown below.

Any number from 0 * , can be display on the & segment by pro4iding the actual hex or binary 4alue
which turns those segments 3@ to display the digit.

S4&CE C4DE+ S4&CE C4DE+
Sir Syed University of Engineering and Technology Page #
Microprocessor Based System Design-Lab Manual
2ssembly code ERui!alent mac%ine language code
(o4 Al !0: >to ma%e all port out use
!0h
in command byte
03 !0
3ut 1; AL > mo4 !0h to port 9 E$ 1;
(o4 AL00: > mo4 00C3 to AL 00 00
3ut 1,: AL > mo4 00C3 to port A E$ 1,
'nt 3 99
S$E1S $4 <4LL4=+ S$E1S $4 <4LL4=+
1. S$E1035 1ut the +it in 19 mode mo4e \umper 11 which located on the %it li%e this.

2. S$E102 59onnect ?6232 cable to 19.
3. S$E10*5 After mo4ing M11 to serial monitor status and if on a power.up or pressing ?E6
%eyfollowing message will be displayed on L9) and data communication is possible with
computer.

Eou are now ready to wor% in 19 mode.
". S$E10G53pen wincomm and set segment and offsetKe.g5E 000051000L
#. S$E10)5-rite abo4e machine language code in wincomm.
$. S$E10F51ress < for execute.
SC&EE; S84$S+
Sir Syed University of Engineering and Technology Page #!
Microprocessor Based System Design-Lab Manual

4$1$+ *U (B0) is displayed on t%e 7 segment in MD2 Q E0EF
$2S(035-rite a program to display all digits from 0., as shown in the following diagram.
L2B 0 32
Sir Syed University of Engineering and Technology Page #"
Microprocessor Based System Design-Lab Manual
4b Pecti!e+
To initiali/e )3T (AT?'7 )'61LAE.
$%eory+
Dot Dot M Ma at tr ri@ i@ Dis Disp play lay
1. 1. The )ot (atrix inside the ()A * !0!$ trainer %it can be used to display any pattern of
LE)s in the dot matrix display.
2. This re8uires 1'3 !2## ports which are already connected to the )ot (atrix internally.
3. Through the code we can access these ports and pro4ide binary or hex 4alue to switch the
re8uired LE)s on and off.
". 'n order to turn an LE) 3@ a logical 0 should be pro4ided to the row and a logical 1 should
be pro4ided to the column because of the following arrangement
#. Any particular shape aur design can be formed by turn on the re8uired LE)s on the )ot
(atrix )isplay.
S S4 4& &CE CE C4D C4DE E+ +
2ssembly code ERui!alent mac%ine language code
Mo! 2l' E08 00 !0
4ut 3E' 2L E$ 1E
Mo! 2L' 038 * column to pro/ide
logical 1
00 01
4ut 3C8' 2L E$ 19
Mo! 2L' 008 * row to pro/ide logical
0
00 00
4ut 328' 2L E$ 1
Mo! 2L' <<
00 ;;
4ut 3E8' 2L
E$ 1!
9
9
Sir Syed University of Engineering and Technology Page ##
S Ste tep ps s t to o < <ollo- ollo-
&. S $E 1 0 3 5 1ut the +it in 19 mode mo4e \umper 11 which located on the %it li%e this.
1. S $E 1 02 +9onnect ?6232 cable to 19.
2. S $E 1 0 * 5 After mo4ing M11 to serial monitor status and if on a power.up or pressing
?E6 %ey following message will be displayed on L9) and data communication is
possible with computer.
Eou are now ready to wor% in 19 mode.
3. S $E 1 0 G 53pen wincomm and set segment and offsetKe.g5E 000051000L
". S $E 1 0 ) 5-rite abo4e machine language code in wincomm.
#. S $E10F 51ress < for execute.
S creen S% ots +
4u tpu t+ ;irst 9olumn LE)s are acti4ated
L La ab b 3 3b\ b\ec ecti4 ti4e es5 s5
TA0112-rite a program to display 2
nd
column with alternate colors ledOs.
TA0132-rite a program to display a pattern V+A?A9:'O on )3T (AT?'7.
L2B 0 3*
4b Pecti!e
Exploring ()E !0#1 (icrocontroller Trainer 0oards
$% eory
6ntrod u c t ion t o Mic r oco n tr o ll e r s
A microcontroller Ksometimes abbre4iated a9 u9 or (9BL is a small computer on a single
integrated circuit containing a processor core memory and programmable input2output
peripherals. (icrocontrollers are designed for embedded applications in contrast to the
microprocessors used in personal computers or other general purpose applications.
(icrocontrollers are used in automatically controlled products and de4ices such as automobile
engine control systems implantable medical de4ices remote controls office machines
appliances power tools toys and other embedded systems. 0y reducing the si/e and cost
compared to a design that uses a separate microprocessor memory and input2output de4ices
microcontrollers ma%e it economical to digitally control e4en more de4ices and processes.
MDE E0)3 $ rain er Board s
The !0#1 board is a useful tool for embedded control and robotics pro\ects for both students and
hobbyists. 'ts 4ersatile design and programmable microcontroller lets you access numerous
peripheral de4ices and program the board for multiple uses. The board has many '23 connectors
and supports a number of programming options including !0#1 assembly and 9.
The !0#1 trainer board has ! switches and ! buffered LE)s for connection to the
microcontroller bread board or peripheral de4ices. 't pro4ides access to pins of the !0#1 through
sip male and female connectors for wiring to bread board or attaching )iligent 1modb
peripheral modules. )iligent peripheral modules include :.bridges analog.to.digital and
digital. to analog con4erters spea%er amplifier switches buttons LE)s as well as con4erters
for easy connection to screw terminals 0@9 \ac%s ser4o motors and more.
;eatures include5
A (axim 6emiconductor )6!,9"#0 microcontroller Kan !0#12#2L with $"+ bytes of on.
chip ;lash memory
Eight on.board switches accessible 4ia both male and female connector
Eight on.board LE)s accessible 4ia both male and female connector
An on.board 4oltage regulator Kin some 4ersionsL
Two 20.pin male and female connectors allowing access to all !0#1 ports of 10 11 12
and 13 for connection to external de4ices such as bread board or )iligent peripheral
module boards.
6upport for the (axim on.chip serial programmer
Two ?6232 compatible 6erial ports with )0, connectors
An small bread board can be screwed on the board to insert any external '9 and connect
it to the board
()E !0#1Trainer 0oard
()E !0#1 9ircuit
)iagram
<un ctional Desc rip tion
The !0#1 is designed for embedded control and robotic applications as well as microprocessor
experimentation. The !0#1 has an on.chip loader2programmer5 The loader 2 programmer are
accessed 4ia 6erial 93( 1ort N0 )0, 9onnector. The !0#1 Trainer features a flexible power
supply routing system with =99 and <@) pin a4ailable on 20 pin male and female connector
for powering the '9s on the bread board as well as )iligent 1mod peripheral modules connected
to the board. )iligent 1mod peripheral modules can be connected to the connectors on the !0#1
Trainer board 4ia cables. )iligent has a 4ariety of 1mod interconnect cables a4ailable.
1rog ra mmin g t%e E0)3 $rain er
The !0#1 Trainer programming can be accomplished using 6erialN0. 1rogramming 4ia 6erialN0
re8uires use of the :yperTerminal program which comes with the (icrosoft -indows 3perating
6ystem.
L La ab b 3 3b\ b\ec ecti4 ti4e es5 s5
TA011: :ow to Test )ownload and ?un a 1rogram on the ()E !0#1 Trainer 0oard.
S tep s to " oll o-
9onnecting the !0#1 Trainer to 19 with :yperTerminal5
1. 9onnect the 6erial 0 connector of the !0#1 Trainer to 93( port of the 19 using )0.,
cable as shown below.
2. 3n your 19 go to 6tart Accessories 9ommunications select :yperTerminal.
3. Enter a name for the terminal session.
". 6elect the 19 93( 1ort the ()E !0#1 is connected to.
9onfigure :yperTerminal for ,$00 !n1 with no hardware flow control
#. 9onnect the power and put the 6witch on 1?< as 6hown bellow. KThe 1?< LE) is
turned on nowL
$. <o to your :yperTerminal. 1ress Enter couple of times and examine the :yper Terminal
screen. Eou should now see the following message on the screen.
&. 9lear KEraseL the ;lash by entering letter ( followed by Enter.
!. ?eady to download by entering letter L followed by Enter.
,. Bsing :yperTerminal send a text file to the trainer li%e shown below.
10. -hen the dialogue appears select all files and na4igate to find your :E7 file to be sent
to the trainer.
11. Eou should see a series of <s appear on your screen if the download is successful.
3therwise repeat the process.
12. 'f the )ownload is successful you can mo4e the 6witch to ?un position and press
?E6ET button to execute the code.
4b Pecti!e+
L 2 B 03G
1rogramming !0#1 '23 1orts as 'nput 1orts
$ % e o r y
The four !.bit '23 ports 10 11 12 and 13 each use ! pins. All the ports upon ?E6ET are
configured as input ready to be used as input ports. -hen the first 0 is written to a port it
becomes an output. To reconfigure it as an input a 1 must be sent to the port. To use any of these
ports as an input port it must be programmed.
14&$ 0
't can be used for input or output> each pin must be connected externally to a 10+ ohm pull.up
resistor. This is due to the fact that 10 is an open drain unli%e 11 12 and 13. 3pen drain is a
term used for (36 chips in the same way that open collector is used for TTL chips.
'n order to ma%e port 0 an input port the port must be programmed by writing 1to all the bits.
1ort 0 is also designated as A)0.A)& allowing it to be used for both address and data. -hen
connecting an !0#1231 to an external memory port 0 pro4ides both address and data
14&$ 3
1ort 1 can be used as input or output. 'n contrast to port 0 this port does not need any pull.up
resistors since it already has pull.up resistors internally. Bpon reset port 1 is configured as an
input port. To ma%e port 1 an input port it must be programmed as such by writing 1to all its bits
14&$ 2
1ort 2 can be used as input or output. Must li%e 11 port 2 does not need any pull.up resistors
since it already has pull.up resistors internally. Bpon reset port 2 is configured as an input port.
To ma%e port 2 an input port it must be programmed as such by writing 1 to all its bits. 'n many
!0#1.based systems 12 is used as simple '23. To ma%e port 2 an input port it must be
programmed as such by writing 1 to all its bits. 'n many !0#1.based systems 12 is used as
simple '23.
14&$ *
1ort 3 can be used as input or output. 't also does not need any pull.up resistors. 1ort 3 is
configured as an input port upon reset> this is not the way it is most commonly used.
L La ab b 3 3b\ b\ec ecti4 ti4e es5 s5
$as / 03 -rite a program for the )6!,9"20 to toggle all the bits of 10 11 and 12 e4ery 12" of
a second
6ource 9ode in Assembly Language
3?< 0
0A9+5 (3= AN##:
(3= 10A
(3= 11A
(3= 12A
A9ALL A6)ELAE
(3= AN0AA:
(3= 10A
(3= 11A
(3= 12A
A9ALL A6)ELAE
6M(1 0A9+
A6)ELAE5
(3= ?# N11
:35 (3= ?" N2"!
:25 (3= ?3 N2##
:15 )M@D ?3 :1
)M@D ?" :2
)M@D ?# :3
?ET
E@)
L2B0 3)
4b Pecti!e+
1rogramming !0#1 '23 1orts as 'nput 1orts and 3utput 1orts
$% eory+
?efer Lab N12
L La ab b 3 3b\ b\ec ecti4 ti4e es5 s5
$as/ 03 -rite a program to that ta%es input from switch to port 1 and display output at port 2
3?< 0
(3= AN0
(3= 12A>12 as output
(3= AN0;;:
(3= 11A >11 A6 '@1BT
0A9+5
(3= A11 >get data from 6-s on 11
(3= A12 >send it to LE)s 12
6M(1 0A9+ >%eep doing it
E@)

You might also like