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.

Please explain the calculation in the below assembly language program for pic

Status
Not open for further replies.

rangerskm

Full Member level 4
Joined
Jan 23, 2013
Messages
199
Helped
0
Reputation
2
Reaction score
0
Trophy points
1,296
Activity points
2,663
Code:
 list p=pic16f73
    #include "p16f73.inc"
    cblock 0x20
    r0,r1,r2,r3
    endc
    org 0x00
    movlw 0x0ef
    movwf r0
    movlw 0x0ff
    movwf r1
    movlw 0x0ff
    movwf r2
    movlw 0x0ff
    movwf r3
    movf r2,w
    subwf r0,1 
    btfss status,0
    goto x
    movlw 0x01
    subwf r3,1 
x:  Movf r3,w
    subwf r1,1
    goto $
    end
 

r0, r1, r2, r3 are 1 byte variables starting at address 0x20

movlw 0xFF means move literal value 0xFF to W (working register)
movwf r1 means move value in W to r1

0xEF is moved to r0

0xFF is moved to r1, r2, r3

value in r2 which is 0xFF is copied to W

subtracts W from f and stores the result in f

subwf r0,1

subtracts 0xFF from r0 (which is 0xEF) and stores the result in r0

btfss status,0 = If bit 0 of STATUS register is set then skip next instruction else execute next instruction

btfss status,0
goto x
movlw 0x01
subwf r3,1
x: Movf r3,w
subwf r1,1
goto $
end


If 0xEF - 0xFF set the 0th bit of STATUS register then

W = 0x01

subtract 0x01 from r3 (0xFF) and store in r3

else

move r3 (0xFF) to W
subtract 0xFF from r1 (0xFF) and store result in r1

goto next instruction which is end of program.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top