ARITHMETIC & LOGIC INSTRUCTIONS AND PROGRAMSExample: Write a program to transfer value 4. H serially (one bit at a time) via pin P2. Put two highs at the start and end of the data. Send the byte LSB first. Solution: MOV A,#4. HSETB P2. 1 ; high. SETB P2. 1 ; high. MOV R5,#8. AGAIN: RRC AMOV P2. C ; send CY to P2. DJNZ R5,AGAINSETB P2. SETB P2. 1 ; high. Example: Write a program to bring in a byte of data serially one bit at a time via pin P2. R2. The byte comes in with the LSB first. Solution: MOV R5,#8. AGAIN: MOV C,P2. 7 ; bring in bit. RRC ADJNZ R5, AGAINMOV R2,A ; save it. Single- bit Operations with CYExample: Assume that bit P2. P2. 5 a light inside a building. Show how to turn on the outside light and turn off the inside one. Solution: SETB C ; CY = 1. ORL C,P2. 2 ; CY = P2. Chapter 6 arithmetic, logic instructions. 6 arithmetic, logic instructions, and programs. Chapter 3 Arithmetic and logic instructions and programs.pdf from CS 4004 at American Intl. Chapter 3 Arithmetic and logic instructions and. ORed w/ CYMOV P2. C ; turn it on if not on. CLR C ; CY = 0. ANL C,P2. 5 ; CY = P2. ANDed w/ CYMOV P2. C ; turn it off if not off. Example: Write a program that finds the number of 1s in a given byte.
Solution: MOV R1,#0 ; R1 keeps number of 1s. MOV R7,#8 ; counter, rotate 8 times. MOV A,#9. 7H ; find number of 1s in 9. HAGAIN: RLC A ; rotate it thru CYJNC NEXT ; check CYINC R1 ; if CY=1, inc count. NEXT: DJNZ R7,AGAIN ; go thru 8 times. SWAPSWAP AIt swaps the lower nibble and the higher nibble. In other words, the lower 4 bits are put into the higher 4 bits and the higher 4 bits are put into the lower 4 bits. SWAP works only on the accumulator (A)Using a Lookup Table for ASCIIExample: Assume that the lower three bits of P1 are connected to three switches. Write a program to send the following ASCII characters to P2 based on the status of the switches.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2017
Categories |