The Elektor Forum will close. See also this link. From Friday March 1st it is no longer possible to log in to the forum. However, the content of the forum will remain visible until the end of March. As of April 1st the forum will definitely go off the air.

4.g assignment HELP

An Elektor Distance Learning Course

Postby iamborg1of1 » Thu Aug 01, 2013 12:00 am

4.g assignment

Hi in asm you have this piece of code

datawaiting:
movlw 32
andwf _pir1,0
bz datawaiting
movf _rcreg,0
movwf tmp

all of this I understand no problem but when it is converted to C
as follows

while(!(pir1 & 32));

For the love of god I cannot get my head around it ,is there any one who could explain to me what it does,
Peter
iamborg1of1
 
Posts: 9
Joined: Thu Jan 02, 2014 10:49 am

Postby geenbert » Thu Aug 01, 2013 12:00 am

The part:

movf _rcreg,0 movwf _tmp 


(note the underscore preceding temp) is translated to

tmp=rcreg;


So what remains is this:

datawaiting:movlw 32            // load 32 in wandwf _pir1,0       // AND w with pir1bz datawaiting      // if 0 (so not true) branch                          (jump) to datawaiting


Which is indeed translated to:

while(!(pir1 & 32)); 


If you "dissect" the C command you get:

pir1 & 32        meaning: AND 32 with pir1while(!     )        meaning: loop while the condition                   is not true   


Both mean the same: "if pir1 AND 32 is false stay in this loop".

Perhaps the explanations on page 98 and 138 are of help.


I've edited this three time but it's quite hard to get the code lined-up nicely.
geenbert
 
Posts: 83
Joined: Thu Jan 02, 2014 10:41 am


Return to Programming Embedded PIC Microcontrollers using Assembly, C and Flowcode

Who is online

Users browsing this forum: No registered users and 1 guest