Wednesday, January 7, 2009

Flag Register & Instruction Organization

FLAG REGISTER
The Status Flags of the 8080 and 8085 are single bits which indicate the logical conditions that existed as a result of the execution of the instruction just completed. This allows instructions following to act accordingly, such as a branch as a result of two values comparing equal. The flags are:
ZERO FLAG: This flag is set to a 1 by the instruction just ending if the A Register contains a result of all 0’s. Besides the obvious mathematical applications, this is useful in determining equality in a compare operation (a value subtracted from a second value with an answer of 0), or in logical AND or OR operations where the result left the A Register with no bit set to a 1 (the AND was not satisfied). If any bits were left set to a 1 in the A Register, the flag will be reset to a 0 condition.
SIGN FLAG: This flag is set to a 1 by the instruction just ending if the leftmost, or highest order, bit of the A Register is set to a 1. The leftmost bit of a byte in signed arithmetic is the sign bit, and will be 0 if the value in the lower seven bits is positive, and 1 if the value is negative.
PARITY FLAG: This flag is set to a 1 by the instruction just ending if the A Register is left with an even number of bits set on, i.e., in even parity. If the number of bits in the A Register is odd, the bit is left off. This may be useful in I/O operations with serial devices, or anyplace that error checking is to be done.
CARRY FLAG: This flag is set to a 1 by the instruction just ending if a carry out of the leftmost bit occurred during the execution of the instruction. An example would be the addition of two 8-bit numbers whose sum was 9 bits long. The 9th bit would be lost, yielding an erroneous answer if the carry bit was not captured and held by this flag. This flag is also set if a borrow occurred during a subtraction or a compare operation.
AUXILIARY CARRY FLAG: This flag is set to a 1 by the instruction just ending if a carry occurred from bit 3 to bit 4 of the A Register during the instruction’s execution. Because of the relationships of decimal in pure BCD to hexadecimal coding, it is possible to bring BCD values directly into the A Register and perform mathematical operations on them. The result, however, will be as if two hex characters are being processed. If the result must be returned to the program as BCD rather than as hex, the Decimal Adjust Accumulator (DAA) instruction can make that translation; the Auxiliary Carry Flag is provided to assist in this operation.
INSTRUCTION ORGANIZATION
The 8085’s instructions are made up of bytes. In microprocessor parlance, a byte is described as 8 contiguous binary bits treated as a unit. The least significant bit is on the right, and is labeled Bit 0. The most significant bit is on the left, and is Bit 7. Thus, the machine coding is "origin zero", unless noted otherwise. Note also that there is no parity bit, or provision for it, as would be found in larger systems.
The 8085’s instructions are either one, two, or three bytes long. In all cases, the first byte contains the essential information, such as the OP code. The second and third bytes, if included, provide operand information that won’t fit in the first byte.
A close look at the first byte of each instruction will reveal a very great similarity between the 8085’s instruction format and that of the PDP11 system by DEC. In many instances, the description of the instructions in the Intel documentation specifies that certain bits of the first byte (#2,1,0) be designated as the "source" operand, and others (#5,4,3) as the "destination" operand. In this manner, all of the major functional units available to the programmer are encoded into three bits, according to the chart below:
DDD or SSS
Register Name
111
A
000
B
001
C
010
D
011
E
100
H
101
L
Similarly, the registers may be defined as register pairs, and two bits within the first byte may then be used to define these:
RP Bits
Register Pair
00
B-C
01
D-E
10
H-L
11
SP
The similarity between PDP11 and 8085 instruction sets is interesting, but by no means rigid. Many differences exist, primarily due to the difference between the 8- and 16-bit architectures.

6 comments:

  1. where is the diagram for flag register?

    ReplyDelete
  2. try to be specific and neat!!!!

    ReplyDelete
  3. Satisfactory. Got wht I wanted.

    ReplyDelete
  4. give example of use of auxillary carry flag in programming?

    ReplyDelete
  5. why the gaps are given between the flags registers plz give suggestion as soon as possible

    ReplyDelete