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.

12 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
    Replies
    1. It is used in BCD or decimal arithmetic programs to show whether the lower nibble of result is valid or invalid
      Eg. ADDITION OF TWO BCD NOS 09 and 18
      09= 00001001bcd
      + +
      18= 00011000bcd
      __ _____________
      27 00100001=21, which is invalid bcoz Auxiliary carry is generated as d3 bit of both nos is 1 if we add them then carry is generated which is called auxiliary carry.. hence AC flag will set..
      To correct the result add 06(00000110) to the result..
      Then result is 00100001+00000110= 00100111=27 result corrected..


      Let the program as:
      MVI A,09
      MVI B,18
      ADD B
      DAA
      HLT
      here the work of correction tjat is addition of 06 is done by DAA instruction.

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

    ReplyDelete
  6. How to move flag register content into L register?

    ReplyDelete
  7. if we add F0 AND F1, is auxiliary carry generated?

    ReplyDelete