Jump to content
Sign in to follow this  
Mac

Help With Boostc Macros

Recommended Posts

Gentlemen, is there a way to duplicate the function of this cycle accurate fixed delay assembler macro in BoostC, please?

 

;
;  in-line fixed delay macro, 0..1027 cycles, 14 bit core
;
clock   equ	 8; 8-MHz
usecs   equ	 clock/2; cycles/usec multiplier
tStep   equ	 1*usecs; 1T "step" time

inDlyCy macro   delay; generates 0 to 7 instructions
	local   loop
 if delay > 3
	movlw   delay/4-1;
loop	addlw   -1; borrow?  (4 cycle loop)
	bc	  loop; no, branch, else, fall thru'
 endif
 if delay%4 >= 2
	goto	$+1; delay%4 == 2 or delay%4 == 3
 endif
 if delay%4 & 1
	nop; delay%4 == 1 or delay%4 == 3
 endif
	endm

 

Here's how I would like to use it in BoostC (below)...

 

	asm {
	bsf	 STATUS,RP0; bank 1					|B1
	movf	bdat+0,W; TRISIO = bdat[0];		 |B1
	movwf   TRISIO;						   |B1
	inDlyCy(1*tStep-2); delay 1T minus 2 cycles   |B1
	movf	bdat+1,W; TRISIO = bdat[1];		 |B1
	movwf   TRISIO;						   |B1
	inDlyCy(2*tStep-2); delay 2T minus 2 cycles   |B1
	bcf	 STATUS,RP0; bank 0					|B0
}

 

I would just code in the assmebler delays by hand but the the assember is crippled, that is, the compiler doesn't evaluate assembler expressions such as the expression in this assembler operand; movlw (32*tStep-2)/4-1.

 

Thank you in advance for your time and kind consideration.

 

Regards, Mike

Edited by Mac

Share this post


Link to post
Share on other sites

ANSI standard C compilers usually do not provide that sort of macro facility and compile time expression evaluation is extremely limited. I know of no way to do that sort of stuff without a customised preprocessor or using an external macro assembler as the final code generator. AFAIK BoostC doesn't support replacing the preprocessor. If it was simple, Dave and Pavel would be using it for their own delay macros . . . and MPASM was dropped as the code generator when C2C became BoostC.

Share this post


Link to post
Share on other sites
ANSI standard C compilers usually do not provide that sort of macro facility and compile time expression evaluation is extremely limited. I know of no way to do that sort of stuff without a customised preprocessor or using an external macro assembler as the final code generator. AFAIK BoostC doesn't support replacing the preprocessor. If it was simple, Dave and Pavel would be using it for their own delay macros . . . and MPASM was dropped as the code generator when C2C became BoostC.

 

As a possible awkward workaround ....

What if you evaluate the expression in C, assign it to a variable, then load the variable in assembler?

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...