Unit 2 Programming Model 8085
Unit 2 Programming Model 8085
(a) General Purpose Registers – The 8085 has six general-purpose registers to store 8-bit
data; these are identified as- B, C, D, E, H, and L. These can be combined as register
pairs – BC, DE, and HL, to perform some 16-bit operation. These registers are used to
store or copy temporary data, by using instructions, during the execution of the
program.
The flag register is a special purpose register and it is completely different from other
registers in microprocessor. It consists of 8 bits and only 5 of them are useful. The other
three are left vacant and are used in the future Intel versions.These 5 flags are set or reset
(when value of flag is 1, then it is said to be set and when value is 0, then it is said to be
reset) after an operation according to data condition of the result in the accumulator and
other registers. The 5 flag registers are:
1. Sign Flag: It occupies the seventh bit of the flag register, which is also known as the
most significant bit. It helps the programmer to know whether the number stored in the
accumulator is positive or negative. If the sign flag is set, it means that number stored
in the accumulator is negative, and if reset, then the number is positive.
2. Zero Flag:: It occupies the sixth bit of the flag register. It is set, when the operation
performed in the ALU results in zero(all 8 bits are zero), otherwise it is reset. It helps in
determining if two numbers are equal or not.
3. Auxiliary Carry Flag: It occupies the fourth bit of the flag register. In an arithmetic
operation, when a carry flag is generated by the third bit and passed on to the fourth bit,
then Auxiliary Carry flag is set. If not flag is reset. This flag is used internally for
BCD(Binary-Coded decimal Number) operations. Note – This is the only flag register
in 8085 which is not accessible by user.
4. Parity Flag: It occupies the second bit of the flag register. This flag tests for number of
1’s in the accumulator. If the accumulator holds even number of 1’s, then this flag is set
and it is said to even parity. On the other hand if the number of 1’s is odd, then it is
reset and it is said to be odd parity.
5. Carry Flag: It occupies the zeroth bit of the flag register. If the arithmetic operation
results in a carry(if result is more than 8 bit), then Carry Flag is set; otherwise it is
reset.
(c) Memory Registers – There are two 16-bit registers used to hold memory addresses. The
size of these registers is 16 bits because the memory addresses are 16 bits. They are :-
Program Counter: This register is used to sequence the execution of the instructions. The
function of the program counter is to point to the memory address from which the next byte
is to be fetched. When a byte (machine code) is being fetched, the program counter is
incremented by one to point to the next memory location.
Stack Pointer: It is used as a memory pointer. It points to a memory location in read/write
memory, called the stack. It is always incremented/decremented by 2 during push and pop
operation.
The arithmetic
microprocessor,
any theislogical
and
Flag register a Special
flag Purpose
register
operation, theRegister.
consists flag bitsDepending
of 8bits become 5upon
and onlyset of orthe
(1)them value
reset
are ofInthe
(0).
useful. result after
8085
1. Sign Flag (S) – After any operation if the MSB (B(7)) of the result is 1, it indicates the number
is negative and the sign flag becomes set, i.e. 1. If the MSB is 0, it indicates the number is
positive and the sign flag becomes reset i.e. 0. from 00H to 7F, sign flag is 0 from 80H to FF,
sign flag is 1 1- MSB is 1 (negative) 0- MSB is 0 (positive)
Example: MVI A 30 (load 30H in register A) MVI B 40 (load 40H in register B) SUB B (A
= A – B) These set of instructions will set the sign flag to 1 as 30 – 40 is a negative number.
MVI A 40 (load 40H in register A) MVI B 30 (load 30H in register B) SUB B (A = A – B)
These set of instructions will reset the sign flag to 0 as 40 – 30 is a positive number.
2. Zero Flag (Z) – After any arithmetical or logical operation if the result is 0 (00)H, the zero
flag becomes set i.e. 1, otherwise it becomes reset i.e. 0. 00H zero flags is 1. from 01H to FFH
zero flag is 0 1- zero-result 0- non-zero result Example: MVI A 10 (load 10H in register A)
SUB A (A = A – A) These set of instructions will set the zero flag to 1 as 10H – 10H is 00H
3. Auxiliary Carry Flag (AC) – This flag is used in the BCD number system(0-9). If after any
arithmetic or logical operation D(3) generates any carry and passes it on to D(4) this flag
becomes set i.e. 1, otherwise, it becomes reset i.e. 0. This is the only flag register that is not
accessible by the programmer 1-carry out from bit 3 on addition or borrows into bit 3 on
subtraction 0-otherwise
Example: MVI A 2BH (load 2BH in register A) MVI 39H (load 39H in register B) ADD B
(A = A + B) These set of instructions will set the auxiliary carry flag to 1, as on adding 2B and
39, the addition of lower-order nibbles B and 9 will generate a carry.
4. Parity Flag (P) – If after any arithmetic or logical operation the result has even parity, an even
number of 1 bit, the parity register becomes set i.e. 1, otherwise it becomes reset i.e. 0. 1-
accumulator has an even number of 1 bits 0-accumulator has odd parity
Example: MVI A 05 (load 05H in register A) This instruction will set the parity flag to 1 as
the BCD code of 05H is 00000101, which contains an even number of ones i.e. 2.
5. Carry Flag (CY) – Carry is generated when performing n bit operations and the result is more
than n bits, then this flag becomes set i.e. 1, otherwise, it becomes reset i.e. 0. During
subtraction (A-B), if A>B it becomes reset, and if (A<B) it becomes set. Carry flag is also
called the borrow flag. 1-carry out from MSB bit on addition or borrow into MSB bit on
subtraction 0-no carry out or borrow into MSB bit.
Example: MVI A 30 (load 30H in register A) MVI B 40 (load 40H in register B) SUB B (A
= A – B) These set of instructions will set the carry flag to 1 as 30 – 40 generates a
carry/borrow. MVI A 40 (load 40H in register A) MVI B 30 (load 30H in register B) SUB B
(A = A – B) These set of instructions will reset the carry flag to 0 as 40 – 30 does not generate
any carry/borrow.
Examples:
MVI B 45 (move the data 45H immediately to register B)
LXI H 3050 (load the H-L pair with the operand 3050H immediately)
JMP address (jump to the operand address immediately)
Examples:
MOV A, B (move the contents of register B to register A)
ADD B (add contents of registers A and B and store the result in register A)
INR A (increment the contents of register A by one)
3. Direct Addressing Mode –
In direct addressing mode, the data to be operated is available inside a memory location
and that memory location is directly specified as an operand. The operand is directly
available in the instruction itself.
Examples:
LDA 2050 (load the contents of memory location into accumulator A)
LHLD address (load contents of 16-bit memory location into H-L register pair)
IN 35 (read the data from port whose address is 35)
Examples:
MOV A, M (move the contents of the memory location pointed by the H-L pair to the
accumulator)
LDAX B (move contents of B-C register to the accumulator)
STAX B (store accumulator contents in memory pointed by register pair B-C)
Examples:
CMA (finds and stores the 1’s complement of the contents of accumulator A in A)
RRC (rotate accumulator A right by one bit)
RLC (rotate accumulator A left by one bit)