Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions