Beruflich Dokumente
Kultur Dokumente
THEORY: -
Data transfer instructions performs the primary function of copying data, from a register or
I/O or memory, which is called the source, to another register or I/O or memory, which is
called the destination.
Example Program: Write an assembly language program (ALP) to load register B with data
38H & transfer the contents of register B to the contents of register C and to memory
location F000H.
Program Documentation:
Contents before execution:
B = XX C = XX F000H = XX
Contents after execution:
B = 38H C = 38H F000H = 38H
Example Program 2: Write an assembly language program to store the data 32H into
memory location 2025H.
Program Documentation:
Contents before execution:
2025H = XX
Contents after execution:
2025H=32H
Example Program 3: Write an assembly language program to interchange the data content
stored at memory location 4000H and 4001H.
Let the content of 4000H location is 10H and 4001H memory location is 20H
EXERCISE
3) A two 16-bit data are stored in consecutive memory location starting from F000H
with lower bytes stored first. Write an assembly language program to copy this data
in four consecutive memory locations starting from D000H.
4) Write an assembly language program to load register pair BC and DE with 16-bit of
data F0F1H and E0E1H respectively and copy this data in consecutive memory
location starting with lower bytes first.
5) Write and A.L.P. to delete the data byte (i.e. make 00H) stored at memory location
whose address is stored at DE register pair.
THEORY: -
Arithmetic and logic instruction performs various arithmetic and logical operations.
Arithmetic instruction
register pair.
All
DCR R Decrement the contents of a
16 1 Register OF except
register.
CY
Decrement the contents of a
All
DCR M 1 memory location, whose OF, MR,
17 Indirect except
address is stored in HL MW
CY
register pair.
Decrement the contents of a
18 DCX Rp 1 -- OF None
register pair.
The 16-bit contents of
DAD Rp register pair are added to the
OF, BI,
19 1 contents of HL register & the Register Only CY
BI
sum is saved in the HL
register.
The contents of accumulator
are changed from a binary
DAA value to its equivalent two,
20 1 Implied OF All
4-bit binary coded
decimal(BCD). Used in BCD
arithmetic
Logical instruction
Instruction
Sr. No. of Addressing Machine Flags
Opcode Description
No. Bytes Mode Cycles Affected
Operand
Logically AND the
CY=0, AC=1,
contents of register with
S,Z,P as per
1 ANA R 1 the contents of the Register OF
result
accumulator.
Example Program 1: Add two 8 bit numbers stored in register B & C store result in register D
Example Program 2: Subtract 8 bit data stored at memory location 2100h from data stored at
memory location 2101h. Store result at memory location 2102h
Example data:
[1] 2100: 45 2101: 33 Note down result at 2102: _____
[2] 2100: 53 2101: 54 Note down result at 2102: _______ (Observe how negative answer is
represented)
Example Program 3: Implement the Boolean equation D = (B+C)E, where B,C, D and E represents
data in various registers of 8085
Example Program 4: Add the contents of memory locations 40001H and 4001H and place the lower
byte of result in the memory locations 4002Hand higher byte in 4003H.
Memory Mnemonics M/C code No.of Comments
Address bytes
4000H LXI H, 4000H 21,00,40 3 Set HL register pair as a memory pointer
4003H MOV A, M 7E 1 Get data from memory location 4000
4004H INX H 23 1 Increment memory location
4005H ADD M 86 1 Add to accumulator
4006H INX H 23 1 HL Points 4002H
4007H MOV M,A 77 1 Store the lower byte of result at 4002H
4008H MVI A,00 3E,00 2 Initialize higher byte result with 00H
400AH ADC A 8F 1 Add carry in the high byte result
400BH INX H 23 1 HL Points 4003H
400CH MOV M, A 77 1 Store the higher byte of result at 4003H
400DH HLT 76 1 Terminate program execution
Example Data:
(4000H) = 7FH
(400lH) = 89H
Result = 7FH + 89H = 108H
(4002H) = 08H
(4003H) = 0lH
Example Program 5: Subtract the 16-bit number in memory locations 9002H and 9003H from the
16-bit number in memory locations 9000H and 9001H. The most significant eight bits of the two
numbers are in memory locations 9001H and 9003H. Store the result in memory locations 9004H
and 9005H with the most significant byte in memory location 9005H
EXERCISE
1. Specify the register contents as the following instructions in the given program are
executed.
A H L CY Z S P AC
MVI A, 5EH
ADI A2H
SUB A
MVI H, FFH
MOV L,H
INR H
INX H
HLT
2. Specify the register contents as the following instructions in the given program are
executed.
A B CY Z S
MVI A, 40H
MVI b, 20H
SUB B
MVI A, 20H
MVI B, 40H
SUB B
HLT
3. Two 16 bit data bytes are stored in memory from location 2050H with lower
bytes stored first. Write a program to add these two data and store the result
from 2054H. (Do it with and without using DAD instruction)
4. Write a program to multiply a number stored in accumulator by 3. (Assume
that the result is less then FFH)
5. Two BCD data are stored in memory location 2050H and 2051H. Write a
program to add this two data and store the result in memory location 2052H.
The result should be in BCD.
6. Two data bytes are stored in memory location 2041H and 2042H. Write a
program to add the higher 4 bits of the first data with lower 4 bits of second
data. Store the result in memory location 2043H.
7. Assume some data in register B and C. Mask all the bits except D0 from register
B and C. If D0 is at logic 1 in both registers, store 01H in memory location 2050
H otherwise store 00H.
8. Assume some data in accumulator and register B. If data of accumulator is less
than the data of register B then store 01H in memory location 2050H otherwise
store 00H.
THEORY: -
Branching instruction changes the sequence of program execution. This is useful in
conditional execution and iterations. Branching instructions also called as Jump instructions
are mainly of two types: Unconditional jump instruction and conditional jump instructions.
Branching instruction
Example Program 1: Write an assembly language program to copy block of 10 data stored in
memory starting from memory location 2050h to memory locations starting from 3000h
Example Program 2: Write a program to store data 33H at each memory location starting
from 20F0H to 20FFH.
Mnemonics Comments
LXI H, 20F0H HL initialized as memory pointer
MVI C,10H C initialized as counter
MVI A,33H Load required data into A
LOOP: MOV M,A Copy data from A to ML pointed by HL
INX H Update memory pointer to next ML
DCR C Update counter by decrementing by 1
JNZ LOOP If counter is not zero then jump & repeat
HLT If counter is zero then program ends
EXERCISE
1. A set of 16 data are stored in memory locations starting from 2050H to 205FH. To
insert additional five data bytes of data it is necessary to shift the data string by five
memory locations. Write a program to store data string from 2055H to 2064H.
2. Write a program to find maximum number in a given block of data. The block starts
at 3000H. The 1st data shows the length of block. Store the result at end of the
block.
3. A set of eight data bytes are stored in memory locations starting from 2070H. Write
a program to add two bytes at a time and store the sum in same memory location,
low order sum replacing 1st byte and a carry replacing 2nd byte. If any pair does not
generate a carry, the memory location of the 2nd byte should be cleared.
4. A set of readings is stored in memory locations starting from 2050H and last reading
is FFH. Write a program to check each byte in the string and save the bytes in the
range of (100)d to (150)d (both inclusive) in memory location starting from 2070H.
Also store number of bytes in a given range at 206FH memory location.
5. A set of ten current readings is stored in memory locations starting at 2060H. The
readings are expected to be signed. Write a program to check each reading whether
it is positive or negative and eliminate all negative readings, thus reducing the size
of data set.
Simulate following programs on the simulator and either write or attach a print-out
of the same in the file.
1 Six data bytes are stored at memory locations starting from 2050H. Write a program
to separate data with odd parity. Store all such data bytes at memory location
2060H.
2 Write to count how many increments and decrements are required to equalize 67H
and 85H respectively. 67H should increment and 85H should decrement one by one.
3 A set of data bytes is stored in the memory locations starting at 2050H. Check each
data byte for bits D7 and D0. If D7 or D0 is 1, reject the data byte, otherwise store
the data at memory location starting at 2080H. The end of data string is indicated
by the data byte 00H.
4 A bar code scanner scans the boxes being shipped from the loading dock and
records all the codes in computer memory. The end of data is indicated by 00H. 8
bit bar code 10100011(A3H) is assigned to 19 TV sets. Write a program to counter
the number of 19 TV sets that were shipped from given data.
5 A set of five readings is stored in memory locations starting at 2050H. Sort the
readings in ascending order.
4. Write a program to generate a square wave of 2.5 kHz frequency. Use D0 bit of
output port ACH, to output the square wave.
5. Make an up-down counter that will count from 00H to 10H in upward & again
from 10H to 00H in downward. Send the counts to output port CDH. Between
each count, there should be a time delay of 1 second approximately.(Assume
crystal of 6.144MHz frequency).