Programming Model of 8085:
The programming model of 8085 consist of an 8-bit accumulator, one flag register, 6 general 8-bit purpose registers, and two 16-bit special purpose registers. These registers are critically required when programming a 8085 processor. The different register in the programming model are explained below:
Figure-1: Programming Model of 8085:
Accumulator is an 8-bit register. For processing the numbers, 8085 assumes that one of the numbers is in accumulator. After processing, the result is accumulated in accumulator. The usage of the accumulator is given below in assembly language format:
MOV A, M ; this instruction moves the content of a memory location into accumulator
MOV B, C ; It moves the content of register C into register B
ADD B ; it add the content of Accumulator(A) and B and saves the result in Accumulator(A). Aß A+B
STA 2020H ; This instruction saves the content of accumulator at memory location given in HL pair.
General purpose registers:
8085 has six general purpose registers . These are B, C, D, E, H, L registers and are given below:
Figure-2: General Purpose Registers of 8085
All these registers are 8-bits each. These registers can also be used in pair as BC, DE and HL for use as 16-bit data operations. The above registers when used in pair act as follows:
BC : 8-bit B and 8-bit C registers can be used as one 16-bit BC register pair. When used as a pair register C contains the low-byte. Some instructions use register pair BC as a data pointer.
DE : 8-bit D and 8-bit E registers can be used as one 16-bit DE register pair. When used as a pair register E contains the low-byte. Some instructions use register pair DE as a data pointer.
HL : 8-bit H and 8-bit L registers can be used as one 16-bit HL register pair. When used as a pair register L contains the low-byte. Some instructions use register pair HL as a memory pointer.
Program Counter (PC)
This 16-bit register deals with sequencing the execution of instructions. This register is a memory pointer. Memory locations have 16-bit addresses, and that is why this is a 16-bit register.
The microprocessor uses this register 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 (SP)
The stack pointer is also a 16-bit register used as a memory pointer. It points to a memory location in R/W memory, called the stack. The beginning of the stack is defined by loading 16-bit address in the stack pointer. The 8085 uses PUSH and POP instructions for stack operations.
ALU of 8085 contains a special register called a “Flag register” and is an 8-bit register. At the time of design of 8085 only five flags of this register were used and the rest three were reserved. These flags are set or reset after an operation according to data conditions of the result in the accumulator and other registers. They are called Zero(Z), Carry (CY), Sign (S), Parity (P), and Auxiliary Carry (AC) flags; their bit positions in the flag register are shown in the Figure below. The most commonly used flags are Zero, Carry, and Sign. The microprocessor uses these flags to test data conditions.
Figure-3: Flag Register of 8085
Carry flag is used to indicate the status whether the carry is generated as a result of adding two numbers
Figure-4 (a): Example of carry as a result of adding two numbers
Figure (a) above shows that a carry is generated as a result of adding two binary numbers ‘A’ and ‘B’. When a carry is generated the LSB of the flag register (carry flag ‘Cy) sets to 1, when there is no carry as a result of addition, the carry flag is reset to ‘0’.
Parity flag is used to indicate whether the parity of the number has changed or not. The parity flag (‘P’) is set to one if the number of ‘1’s in the result is odd. The flag is reset to ‘0’ if the number ‘1’ in the result is even. In figure (a) the result of ‘A+B’ = 1010111. Here number of 1’s is five i.e. odd number of bits are high (‘1’), so the parity flag get set to ‘1’.
Auxiliary Carry Flag (AC):
This flag is set or reset depending on whether there is a carry out as result of addition of the lower nibble data of an eight bit number.
Figure-4(b) Example of Auxiliary Carry Generation
Figure above shows the addition of two one byte (8-bit) numbers. It is observed that there is a carry out of the 1st nibble into the upper nibble, so the auxiliary flag (AC) will be set to ‘1’ . In case there is no carry out of 1st nibble addition then the auxiliary (AC) flag will be reset to ‘0’.
The zero flag is an indication of whether the result of addition or subtraction is zero or non-zero. If the addition or subtraction of two numbers result in zero, the zero (Z) flag is set to ‘1’, in case of a non-zero result the flag will be reset to zero.
Figure-5(c ) and (d): Example of Zero and Sign Flag setting
Figure (c ) above show binary subtraction of two equal numbers. The result is “ 0 0 0 0 “ which is zero, therefore the zero (Z) flag will be set to ‘1’.
The MSB of the number indicates its sign, and is of interest when dealing with signed numbers. For processing the unsigned numbers, we simply ignore the sign bit. The sign (S) flag will be set to ‘1’ if the result of addition or subtraction results in a negative answer. For the positive result the sign flag will be reset to ‘0’.
In the above figure (d), +ve numbers is represented by taking the sign bit as ‘0’ and negative number is represented by taking the sign-bit as ‘1’. Negative number (-7) is represented as 11111000 in 1’s complement representation. So the addition of +6 (“00000110”) and -7(11111000”) results in “11111110”. In the example above the MSB of the result is ‘1’, it indicates that the result is negative, and this sets the sign (S) flag to ‘1’. For the positive result i.e. when the MSB of the result is ‘0’, the sign (S) flag is reset to ‘0’.