Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADDWF instruction in pic microcontroller

khatus

Member level 3
Member level 3
Joined
Oct 7, 2017
Messages
64
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,754
I can’t understand How the W register is incremented every time with the value 22H since the content of 12H register is 0 and every time we add it with 0 and stores the result back in the w register it becomes 0+22H = 22H. I think the result will be a fixed value i.e 22H

in line 4 ADDWF 12H, W: This instruction adds the value in register 12H (which is 0) to the value in the W register (which is 22H) and stores the result back in the W register. The W register now contains 22H.

in line 5 ADDWF 12H, W: This instruction again adds the value in register 12H (still 0) to the value in the W register (which is 22H) and stores the result back in the W register. The W register now contains 22H.

w_reg.PNG


I wrote here what I understood,


  1. MOVLW 0: This instruction loads the literal value 0 into the W register.
  2. MOVWF 12H: This instruction moves the value in the W register (which is now 0) into register 12H.
  3. MOVLW 22H: This instruction loads the literal value 22H into the W register.
  4. ADDWF 12H, W: This instruction adds the value in register 12H (which is 0) to the value in the W register (which is 22H) and stores the result back in the W register. The W register now contains 22H.
  5. ADDWF 12H, W: This instruction again adds the value in register 12H (still 0) to the value in the W register (which is 22H) and stores the result back in the W register. The W register now contains 22H.
    W = (W=22H +0) = 22H
  6. ADDWF 12H, W: This instruction repeats the addition, resulting in the W register having 22H.
    W = (W= 22 H +0) = 22H
  7. ADDWF 12H, W: The final addition takes place, and the W register now holds 22H.

 
Score: Khatus Wins, Whoever wrote that loses their job!

I think they swapped lines 1 and 3. They intended to demonstrate putting 22H into address 12H, clearing W then adding the contents of address 12H four times.
In addition, file register 12H is used for other purposes on most PICs so it shouldn't be used as variable storage.

Brian.
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top