Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 9 Weeks Ago, 6 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
For each of the following complex operations, write a sequence of PIC 16F1829 instructions thatperforms an equivalent operation. Assume that X, Y, and Z are 16-bit values split into individualbytes as shown in the following cblock directive, which defines two additional variables you canuse:
Â
cblock 0x70
XH, XL ; High and low bytes of X
YH, YL ; High and low bytes of Y
ZH, ZL ; High and low bytes of Z
TEMP ; Temporary byte, if needed
COUNT ; Loop counter, if needed
Endc
Â
1. Perform the 16-bit addition: X = Y + Z. Do not change Y or Z when performing this
operation.
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
2. Perform the 16-bit subtraction: X = Y – Z. Do not change Y or Z when performing this
operation.
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
3. Perform a 16-bit arithmetic right shift: X = Y >> ZL. (Note that, because the shift amount isno greater than 15, a single byte is sufficient to hold that value.) Do not change Y or ZLwhen performing this operation.
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
4. Given an 8-bit variable, YL, perform the multiplication:
YL = YL * 10
Â
Hint: Note that multiplication by a constant amount can be broken into a series of shift and addoperations. For example, in general:
Â
X * 2 can be implemented by shifting X to the left by 1 (X << 1)
Â
X * 5 can be implemented as (X * 4) + X = (X << 2) + X
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
5. Given two 8-bit variables stored in XL and YL, copy the value of bit position YL within
variable XL into the carry flag. For example:
Â
If XL = 0x03 and YL = 0x00, set C to the value of bit 0 within XL.
o Since XL = 0x03 = 0000 00112, C = 1
Â
If XL = 0xC2 and YL = 0x04, set C to the value of bit 4 within XL.
o Since XL = 0xC2 = 1100 00112, C = 0
Â
Note that:
* This operation is very similar to the bit test (BT) instruction in the x86 architecture.
* Since YL is not a constant, you cannot use the value of YL directly in any of the PIC bit
test instructions (for example, btfsc XL, YL is not a valid instruction).
* Your code should not modify either XL or YL.
-----------