The code segment implements C instructions to increment and decrement long variables i and j, and add i to j, in assembly for a PIC18 microcontroller. It initializes WREG to 0, moves it to i, increments i, decrements j, adds j and i by storing their sum in WREG, and then moves WREG to j to update it with the sum.
Write a code segment in assembly of PIC18 that implement the following.docx
1. Write a code segment in assembly of PIC18 that implement the following instructions in C.
Note: Variables are long type (4 bytes) Long i,j; i++; i--; j = i+j
Solution
org 0x0000 ; program starting address after reset
goto start
org 0x08
retfie ; high priority interrupt service routine
org 0x18
retfie ; low priority interrupt service routine
start mov.b #0, w0 ;WREG=0=0x64 Initializing the variable
mov.b WREG.0x0800 ; i=WREG
inc.b 0x0800 ;i=i++ or i=i+1
dec.b 0x801 ;j=j-1 or j—
sdd.b 0x0801, WREG ; WREG=j+WREG (ie j+i)
mov.b WREG, 0x0801 ;j=WREG (iej=i+j)
end