art 2: Status Flags There are more registers inside of the CPU that we don't have direct access to. One of these is the EFLAGS register. This register holds the values of the flags used in the CPU's operation. Flags are just single bit values that represent the state of the processor - usually 1 means a setting is on or true, and 0 means it is off or false.  If a flag has the value 1, we say the flag is set. If it has the value 0, we say it is clear. "Setting" a flag means setting it's value to 1, and "clearing" a flag means setting its value to 0.  The status flags are flags that show the outcomes of certain operations. These can be used to check the state of the computations and react accordingly. For example, the carry flag is set if the result of an unsigned addition is too large to fit into the same space as the numbers used during the addition. Look at the following addition operation: 11111111 + 00000001 = 100000000 Note that the result of the addition is 9 bits long, even though the two operands were 8-bit numbers. If the addition was performed using 8-bit registers, then the result is too large to fit into the space provided. In this case, the result of the addition would be stored as just "00000000", and the carry flag would be set. By examining the carry flag after the operation, we can determine that the stored result isn't complete and should have a 1 in front of it. We could then reconstruct the correct result in one of the 16-bit registers, which would be large enough to hold the 9-bit result. The status flags only store the results from the most recent operation performed. Once a new operation is performed, they are all cleared and then set to the status of the new operation's result instead.  Here is the list of the status flags: Carry flag: if an operation is assumed to use unsigned numbers, then this is set when the result of that operation is too large to fit into its destination. Overflow flag: if an operation is assumed to use signed numbers, then this is set when the result of that operation is too large to fit into its destination. Sign flag: if an operation is assumed to use signed numbers, then this is set when that operation has a negative result. Zero flag: set when an operation results in 0. Auxiliary carry flag: set when an operation causes a carry from bit 3 to bit 4 of an 8-bit operand. We will not use this one often. Parity flag: set if the lowest 8 bits of a result has an even number of 1's in it. (zero is an even number, so a result with no 1's would set this flag) Note that the carry flag always assumes that every operation is unsigned, and the overflow and sign flags always assume that every operation is signed. For example, let's say you are adding the unsigned numbers 01000000 and 01100000. The result is 10100000. Even though our intention was to add two unsigned numbers, the result would be negative under 2's complement representation. Therefore the sign flag would be set after this operation. For the questions below, state whether the carry flag, sign flag, zero flag, and parity flags would be set after the given operations. The size of the result should contain the same number of bits as the two operands in that operation. Don't worry about the overflow flag or auxiliary carry flags for now. 00011000 + 00100011 10000000 + 10000000 0000000011111111 + 0000000011111111 1111111111111111 + 0000000000000001 11101000 + 11011101

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter6: System Integration And Performance
Section: Chapter Questions
Problem 9VE
icon
Related questions
Question

Part 2: Status Flags

There are more registers inside of the CPU that we don't have direct access to. One of these is the EFLAGS register. This register holds the values of the flags used in the CPU's operation. Flags are just single bit values that represent the state of the processor - usually 1 means a setting is on or true, and 0 means it is off or false. 

If a flag has the value 1, we say the flag is set. If it has the value 0, we say it is clear. "Setting" a flag means setting it's value to 1, and "clearing" a flag means setting its value to 0. 

The status flags are flags that show the outcomes of certain operations. These can be used to check the state of the computations and react accordingly.

For example, the carry flag is set if the result of an unsigned addition is too large to fit into the same space as the numbers used during the addition. Look at the following addition operation:

11111111 + 00000001 = 100000000

Note that the result of the addition is 9 bits long, even though the two operands were 8-bit numbers. If the addition was performed using 8-bit registers, then the result is too large to fit into the space provided. In this case, the result of the addition would be stored as just "00000000", and the carry flag would be set. By examining the carry flag after the operation, we can determine that the stored result isn't complete and should have a 1 in front of it. We could then reconstruct the correct result in one of the 16-bit registers, which would be large enough to hold the 9-bit result.

The status flags only store the results from the most recent operation performed. Once a new operation is performed, they are all cleared and then set to the status of the new operation's result instead. 

Here is the list of the status flags:

  • Carry flag: if an operation is assumed to use unsigned numbers, then this is set when the result of that operation is too large to fit into its destination.
  • Overflow flag: if an operation is assumed to use signed numbers, then this is set when the result of that operation is too large to fit into its destination.
  • Sign flag: if an operation is assumed to use signed numbers, then this is set when that operation has a negative result.
  • Zero flag: set when an operation results in 0.
  • Auxiliary carry flag: set when an operation causes a carry from bit 3 to bit 4 of an 8-bit operand. We will not use this one often.
  • Parity flag: set if the lowest 8 bits of a result has an even number of 1's in it. (zero is an even number, so a result with no 1's would set this flag)

Note that the carry flag always assumes that every operation is unsigned, and the overflow and sign flags always assume that every operation is signed. For example, let's say you are adding the unsigned numbers 01000000 and 01100000. The result is 10100000. Even though our intention was to add two unsigned numbers, the result would be negative under 2's complement representation. Therefore the sign flag would be set after this operation.

For the questions below, state whether the carry flag, sign flag, zero flag, and parity flags would be set after the given operations. The size of the result should contain the same number of bits as the two operands in that operation. Don't worry about the overflow flag or auxiliary carry flags for now.

  1. 00011000 + 00100011
  2. 10000000 + 10000000
  3. 0000000011111111 + 0000000011111111
  4. 1111111111111111 + 0000000000000001
  5. 11101000 + 11011101 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 7 steps

Blurred answer
Knowledge Booster
Fundamentals of Computer System
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning