0% found this document useful (0 votes)
727 views5 pages

PSW 8051

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
727 views5 pages

PSW 8051

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 5
2irzR020 8051 FLAG BITS AND THE PSW REGISTER ‘hen-how In Depth Tutorials and Information 8051 FLAG BITS AND THE PSW REGISTER Download PDF (Free) - Download PDF (Fre To View PDF, Download Here free.propafconverter.com Download PDF (Free) - Download PDF (Fre To View PDF, Download Here free. propdfconverter.com SECTION 2.6: 8051 FLAG BITS AND THE PSW REGISTER Like any other microprocessor, the 8051 has a flag register to indicate arithmetic conditions such as the carry bit. The flag register in the 8051 is called the program status word (PSW) register. In this section we discuss various bits of this register and provide some examples of how it is altered. PSW (program status word) re: The program status word (PSW) register is an 8-bit register. It is also referred to as the flag register. Although the PSW register is 8 bits wide, only 6 bits of it are used by the 8051. The two unused bits are user-definable flags. Four of the flags are called conditional flags, meaning that they indicate some conditions that result after an instruction is executed. These four are CY (carry), AC (auxiliary carry), P (parity), and OV (overflow). ‘As seen from Figure 2-4, the bits PSW.3 and PSW.4 are designated as RSO and RSI, respectively, and are used to change the bank registers. They are explained in the next section. The PSW.5 and PSW.1 bits are general- purpose status flag bits and can be used by the programmer for any purpose. In other words, they are user definable, See Figure 2-4 for the bits of the PSW register. cy | ac ] ro ] ws | wo] ov | — P cy Psw7 Cary flag AC PSWO Auiilary cary flag. Fo Psws Ayailuble to the wer for general purpose, RSI Pswa Register Bank selector bt |. RS PSW3 Register Rank selecor bit 0 ov Psw2 Overflow fla, — — Pswi Usersefinabie bi, P PSWo Parity flag Setileared by hardware each instuction eyele 40 indicate an odi/even number of 1 bits in the 2ccumulator RS1_RSO Register Bank, Address oo ¢ OOH 07 oi 1 OSH - OFH 10 2 10H. 17H rt 3 ISH FE Figure 2-4, its of the PSW Register hitpshvhatwnen-ow.com/806 t-microcontroler/8051-flag-bts-and-the-psw-regster! 18 2120020 6051 FLAG BITS AND THE PSW REGISTER The following is a brief explanation of four of the flag bits of the PSW register. The impact of instructions on these registers is then discussed. wiAdvertiseO:X. CY, the carry flag This flag is set whenever there is a carry out from the D7 bit. This flag bit is affected after an 8-bit addition or subtraction, It can also be set to 1 or 0 directly by an instruction such as “SETB C” and “CLR C” where “SETB * stands for “set bit carry” and “CLR C” for “clear carry”. More about these and other bit-addressable instructions will be given in Chapter 8. AC, the auxiliary carry flag If there is a carry from D3 to D4 during an ADD or SUB operation, this bit is set; otherwise, it is cleared. This flag is used by instructions that perform BCD (binary coded decimal) arithmetic. See Chapter 6 for more information, P, the parity flag The parity flag reflects the number of | s in the A (accumulator) register only. If the A register contains an odd number of Is, then P = 1. Therefore, P = 0 if A has an even number of Is. OY, the overflow flag This flag is set whenever the result of a signed number operation is too large, causing the high-order bit to overflow into the sign bit. In general, the carry flag is used to detect errors in unsigned arithmetic operations. The overflow flag is only used to detect errors in signed arithmetic operations and is discussed in detail in Chapter 6. hitpshvhatwnen-ow.com/806 t-microcontroler/8051-flag-bts-and-the-psw-regster! 218 2irzR020 8051 FLAG BITS AND THE PSW REGISTER Table 2-1: Instructions That Affect Flag Bits instruction CY _OV__AC x x ADDC x x SUBB xX MUL x DIV x DA RRC x REC x SETBC 1 CLRC 0 CPLE x ANLC.bit_X ANU. fit _X. ORL C.bit_X ORLC, Ait_X MOV CINE Note: X can be 0 or I. ADD instruction and PSW ‘Next we examine the impact of the ADD instruction on the flag bits CY, AC, and P of the PSW register. Some examples should clarify their status. Although the flag bits affected by the ADD instruction are CY (carry flag), P (parity flag), AC (auxiliary carry flag), and OV (overflow flag) we will focus on flags CY, AC, and P for now. A discussion of the overflow flag is given in Chapter 6, since it relates only to signed number arithmetic. How the various flag bits are used in programming is discussed in future chapters in the context of many applications, See Examples 2-2 through 2-4 for the impact on selected flag bits as a result of the ADD instruction. hitpshvhatwnen-ow.com/806 t-microcontroler/8051-flag-bts-and-the-psw-regster! ais 2irzR020 8051 FLAG BITS AND THE PSW REGISTER Example 2-2 Show the status of the CY, AC, and P flags after the addition of 38H and 2FH in the fol- lowing instructions. MOV A, #38H ADD A, #2FH jafter the addition A=67H, CY=0 Solution: 38 00111000 +2E SOLON 67 01100111 CY = 0 since there is no carry beyond the D7 bit. AC = I since there is a carry from the D3 to the D4 bit. P= since the accumulator has an odd number of Is (it has five Is). [Example 2-3 Show the status of the CY, AC, and P flags after the addition of 9CH and 64H in the fol- lowing instructions, MOV A, #9CH ADD A, #64H yafter addition A=00 and CY=1 Solution: 9c 10011100 + 1100100 100 00000000 CY = | since there is a carry beyond the D7 bit. AC = | since there is a carry from the D3 to the D4 bit. P=0 since the accumulator has an even number of Is (it has zero Is). [Example 24 ‘Show the status of the CY, AC, and P flags after the addition of 88H and 93H in the fol- lowing instructions. MOV A, #88H ADD A, #93H jafter the addition A=1BH,CY=1 Solution: 88 10001000 +B 10010011 1B 00011011 CY = | since there is a carry beyond the D7 bit. AC = 0 since there is no carry from the D3 to the D4 bit. P= 0 since the accumulator has an even number of Is (it has four 1s). hitpshvhatwnen-ow.com/806 t-microcontroler/8051-flag-bts-and-the-psw-regster! 46 2irzR020 8051 FLAG BITS AND THE PSW REGISTER > a © SPONSORED SEARCHES (Cheap World Flags _) C Fiag Carry Case _) (CC FanFlagsforSale )(__—‘FlagMakers_—_—«d) 051 RI Next post: ER BANKS AND STACK Previous post: 8051 DATA TYPES AND DIRECTIVES + Related Links © 8051 Microcontroller 8051 MICROCONTROI MICROCONTROLLERS AND EMBEDDED PROCESSORS OVERVIEW OF THE 8051 FAMILY 8051 ASSEMBLY LANGUAGE PROGRAMMING INSIDE THE 8051 Search WWH :: Search Google Custom Search Help Unprivileged Children | Careers ¥ Privacy Statement Copyright Information hitpshvhatwnen-ow.com/806 t-microcontroler/8051-flag-bts-and-the-psw-regster! 55

You might also like