Sei sulla pagina 1di 17

Programming of Microprocessor

• To perform a particular task the programmer prepares a sequence of


instruction known as program.
• The program is stored in the memory
• The microprocessor takes one instuction of the program at a time from
memory and executes it.It executes all the instructions of programm one
by one and produce desired result.
• A computer works in the binary systems and understands the information
composed of zeros and ones. Hence the instructions are coded and store
in the memory in the form of zeros and ones.A program written in the
form of zers and ones is called machine language.
• Eg: to move the content of reg A to reg B the binary code is 01111000
• It is very difficult for the programmer to write the program in binary
codes. Programs are long and it is error prone.
• The program can be easily be written in hexadecimal system compared to
binary system. The mistake can be eassily detected.
• As the microcomputer understands the progrm written only in binary
system, the program written in hexadecimal system is converted into
binary system. All microprocessor kit have provision for such conversion.
• Writing the program in machine language is very difficult and error
prone. Hence to facilitate the programmer easily understandable languages
have been developed. Assembly language is one of them. A programmer
can easily write a program in alphanumeric symbols instead of zeros and
ones.
• Meaningfull and easily rememberable symbols are choosen for the purpose
eg. ADD for addition, SUB for subtraction
• Such symbols are called mnemonics
● A program written in mnemonics is known as assembly language
program.
● A program which translates assembly language program into
machine language is called assembler.
● In an ordinary kit assembler is not available.
● The programmer first of all writes the programs in assembly
language and then he fills up machine code corresponding to each
mnemonics. This is called hand assembly.
● The codes are written inhexadecimal system using keyboards and
in the kit there is an arrangement to convert this hexadecimal
code to binary.
1. Place 05 in register B
Memory Machine Mnemonics Operand Comments
address code
FC00 06,05 MVI B,05 Get 05 in reg B

FC02 76 HLT Stop


● The first byte of the instruction is 06 which is he machine code for
the instruction MVI B.The second byte 05 is the date to be moved to
reg B
● The machine code 06 is entered in the memory location FC00H ; 05 in
FC01 and 76 in FC02
● Memory address can be changed to suit the memory kit available in
the laboratory
2.Get 05 in register A and then move it to
register B
Memory Machine Mnemonics Operand Comments
FC00 3E,05 MVI A, 05 Get 05 in reg A
FC02 47 MOV B,A Transfer 05 from reg
A to reg B
FC03 76 HLT Stop

● First byte of instruction 3E is for MVI A and second byte is the the
data 05which is to be placed in A
● Mahine code 47 is for move data from reg A to reg B
3. Load the content of the memory location FC50H
directly to the reg A , then transfer it to reg B
Memory Machine Mnemonics Operand Comments
FC00 3A,50,FC LDA FC50 Get the content of
the memory location
FC50H into accumulator

FC03 47 MOV B,A Move the content


of reg A to reg B
FC04 76 HLT
● The instruction LDA loads the accumulator directly with the content of
the memory location specified in the instruction. The instruction Mov
A,B will move the content of the accumulator to reg B. After execution
of the program reg B will contain the data in FC50
Move the content of the memory location FC50 to
reg C
Memory Machine Mnemonics Operand Comments
FC00 21,50,FC LXI H,FC50 Load H-L pair
with FC50H
FC03 4E MOV C,M Move the content
of the memory
location whose
address is in HL pair to reg C
FC04 76 HLT
● Instruction LXI H, FC50 will place FC50 in HL pair.FC50 is the
address of the memory location from where the data is to be
transfered to Reg C
● First byte of the instruction is 21 is the machine code for LXI H. The
second byte of the instruction is 50 and it is the 8 LSB of the
operand. The 3rd byte FC which is the 8 MSBs of the operand
● In code form LSB is written first then MSB
Addition of two 8 bit numbers;sum 8bits
(1st number 49 H
is in the memory 2501 , second number in 2502 and result
is to be stored in the memory location 2503)

Mnemonics Operand Comments


LXI H,2501 Get the address of the 1st number in HL pair
MOV A,M 1st number in the accumulator
INX H Increment content of HL pair(from 2501 to
2502)
ADD M [A] [A]+[M]
STA 2503 Store sum in memory 2503H
HLT
● Data:
2501-49H; 2502-56H ; result 2503-9FH
8 bit subtraction
(First number is in 2501 second number is in 2502 and the result is to be
stored in 2503)

Mnemonics Operand Comments


LXI H,2501 Get the address of the 1st number in HL pair
MOV A,M 1st number in the accumulator
INX H Increment content of HL pair
SUB M [A] [A]-[M]
INX H increment the content of HL pair (ie 2503)
MOV M,A Store result in 2503
HLT

Addition of two 8 bit numbers (result and carry
present)
(1st number is in the memory 2501 , second number in 2502 and
result is to be stored in the memory location 2503 and carry to be
stored in 2504)
Mnemonics Operand Comments
LXI H,2501 Get the address of the 1st number in
HL pair
MVI C,00 Initial value of reg C to be 00
MOV A,M 1st number in the accumulator
INX H Increment content of HL pair
ADD M [A] [A]+[M]
JNC AHEAD Is cary?No go to label the label
INR C Yes, Increment C
AHEAD STA 2503 Store sum in memory 2503H
MOV A,C Move the content of reg C to A
STA 2504 Store carry in the memory location 2504
HLT
Addition of two 16bit numbers
Mnemonics Operand Comments
LHLD 2501H load 1st 16 bit number from 2501
and 2502 to HL register pair.
XCHG Get first number in DE register
pair
LHLD 2503H Load 2nd 16 bit number from 2503
and 2504 to HL register pair
MVI C,00 Set initial value of reg C as Zero
DAD D 1st number + 2nd number
JNC L1 Is carry?No, go to label L1
INR C Yes, Increment C
L1 SHLD 2505H Store Sum in 2505 and 2506
MOV A,C move carry from reg C to Reg A
STA 2507H store carry in 2507
HLT
To find the largest of two numbers
Mnemonics Operand Comments

LXI H,2501 Address of the 1st number in HL pair


MOV A,M 1st number in the accumulator
INX H Address of the 2nd number in HL pair
CMP M Compare 2nd number with 1st number(A-M)
JNC L1 Larger number is in the accumulator
MOV A,M larger number is in the memory and move
it to reg A
L1 STA 2503 Store larger number in 2503H
HLT

● CMP M means theta the content of memory is compared with the


content of tthe accumulator. Here the content of the memory location
addressed by the HL pair had been subtracted from the content of the
accumulator.However the content of the accumulator remain unchanged
for further processing
Shift an 8 bit number left by one bit
Mnemonics Operand Comments
LDA 2501 Get data in accumulator
ADD A Shift it left by one bit
STA 2502 store result
HLT Halt

65=0110 0101
● This program does not take carry into account after ADD instruction
Shift an 8 bit number left by two bit
Mnemonics Operand Comments
LDA 2501 Get data in accumulator
ADD A Shift it left by one bit
ADD A Again shift by one bit
STA 2502 store result
HLT Halt


Shift a 16 bit number left by two bit
Mnemonics Operand Comments
LHLD 2501 Get data in accumulator
DAD H Shift it left by one bit
SHLD 2502 store result
HLT Halt

7596=0111 0101 1001 0110


● Shift a 16 bit number left by 2 bit
Mask off least significant 4 bits of 8 bit
number
Mnemonics Operand Comments
LDA 2000 get data from memory 2000H
ANI F0 Mask of least significant bits
STA 2001 store result in 2001
HLT

Eg:- A6 ANDed with F0


● Mask off MSB 4 bits of an 8 bit number ??
MULTIPLICATION OF TWO 8 BIT NUMBERS (first number
in the memory location 2501 and second number in the
memory location 2502)
Mnemonics Opernad Opcode
MVI D,00 initialise reg D
MVI A,00 Initialise accumulator
LXI H,4501 get address of the first number in HL reg pair
MOV B,M get first number in reg B
INX H get address of the second number in HL reg pair
MOV C,M get second number in reg C
Loop ADD B
JNC L2
INR D
L2 DCR C
JNZ Loop
STA 2503
MOV D,A
STA 2504

● Data 2501-43 2502-07 Result :- 2503-D5 2504-01


Division of two 8 bit numbers
Mnemonics Operand Comments
LDA 4201H Load divisor in the accumulator
MOV B,A transfer the divisor to reg B
LDA 4202H Load dividend in the acumulator
MVI C,00 initialise reg C
L2 CMP B Is divisor > dividend
JC L1
SUB B A-B
INR C Increment result bit
JMP L2
L1 STA 4203 Store the remainder
MOV A,C transfer result from C to A
STA 4204 Store the result
HLT
Divisor 02 and Dividend 09

Potrebbero piacerti anche