Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Use PIC18 IDE for this problem. Enter the following hex code in program memor

ID: 2080456 • Letter: 4

Question

4. Use PIC18 IDE for this problem. Enter the following hex code in program memory starting at the memory address 000020H. Execute the program using single step as described in Appendix F.1.2 in your text. Observe the sum in the WREG and REG2. Identify the flags that are affected after the addition.

Memory Addresses Hex Comments Mnemonics 0020 0E 3 7 MOVLW 0x37 Load first byte in W 0022 6 E 00 MOVWF REG0,0 Save first byte in REG0 0024 0 E 92 MOVLW 0x92 Load second byte in W 0026 6 E 01 MOVWF REG1,0 Save second byte in REG1 0028 2 400 ADDWF REG0,0 0 Add bytes and save sum in W 002A 6 E 0 2 MOVWF REG2,0 save sum in REG22 002C 0 0 0 3 SLEEP Power down

Explanation / Answer

From the given hex code, after execution of the instructions the resulting operations are depicted in the comment section of the HEX table below.

Flags in the STATUS REGISTER that are affected after execution of ADD instructions are C(Carry flag), DC(Digit Carry Flag) and Z (Zero Flag).

MEMORY ADDRESS

HEX

MNEMONICS

COMMENTS

0020

0E 37

MOVLFW 0x37

Load first byte in W; WREG=37H

0022

6E 00

MOVWF REG0,0

Save first byte in REG0; REG0=WREG=37H

0024

0E 92

MOVLW 0x92

Load second byte in W; WREG=92H

0026

6E 01

MOVWF REG1,0

Save second byte in REG1 ; REG1= W=92H

0028

24 00

ADDWF REG0,00

Add bytes and save sum in W; WREG+REG0 = W(NEW)

92H + 37H = C9H

WREG=C9H

FLAGS AFFECTED IN THE STATUS REGISTER:

Z=0 (Since Answer Is Not Zero)

C=0 (Since No Carryout From Most Signifact Bit)

DC= 0 (Since No Carry From 4th Bit To 5th Bit)

002A

6E 02

MOVWF REG2,0

Save sum in REG2; REG2=WREG= C9H

002C

00 02

SLEEP

Power down

MEMORY ADDRESS

HEX

MNEMONICS

COMMENTS

0020

0E 37

MOVLFW 0x37

Load first byte in W; WREG=37H

0022

6E 00

MOVWF REG0,0

Save first byte in REG0; REG0=WREG=37H

0024

0E 92

MOVLW 0x92

Load second byte in W; WREG=92H

0026

6E 01

MOVWF REG1,0

Save second byte in REG1 ; REG1= W=92H

0028

24 00

ADDWF REG0,00

Add bytes and save sum in W; WREG+REG0 = W(NEW)

92H + 37H = C9H

WREG=C9H

FLAGS AFFECTED IN THE STATUS REGISTER:

Z=0 (Since Answer Is Not Zero)

C=0 (Since No Carryout From Most Signifact Bit)

DC= 0 (Since No Carry From 4th Bit To 5th Bit)

002A

6E 02

MOVWF REG2,0

Save sum in REG2; REG2=WREG= C9H

002C

00 02

SLEEP

Power down

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote