swapf() macro

Post your requests and ideas on the future development of mikroC.
Post Reply
Author
Message
alex.forencich
Posts: 56
Joined: 11 Jun 2006 03:49
Location: Lake Oswego, Oregon
Contact:

swapf() macro

#1 Post by alex.forencich » 17 Dec 2006 02:46

It would be really nice to have a simple swapf() macro. It is not difficult to insert an assembly swapf, but determining the thing that needs to be swapped (in assembly) can be quite difficult.

alex.forencich
Posts: 56
Joined: 11 Jun 2006 03:49
Location: Lake Oswego, Oregon
Contact:

#2 Post by alex.forencich » 15 May 2007 07:00

Any news on this? It seems like this should be a very simple thing to add.

User avatar
rajkovic
mikroElektronika team
Posts: 694
Joined: 16 Aug 2004 12:40

Re: swapf() macro

#3 Post by rajkovic » 15 May 2007 07:54

alex.forencich wrote:It would be really nice to have a simple swapf() macro. It is not difficult to insert an assembly swapf, but determining the thing that needs to be swapped (in assembly) can be quite difficult.
We will implement this.

andrixnet
Posts: 8
Joined: 12 May 2011 11:50

Re: swapf() macro

#4 Post by andrixnet » 26 Apr 2012 18:11

Compiler v4.60 lists this in the help :
Swap
Prototype char swap(char input);

Returns Swapped nibbles of the input byte.

Description Function swaps nibbles of the input parameter.

This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.

Requires Nothing.

Example char input, swapped_input;

input = 0xAF;
swapped_input = swap(input); // routine will return 0xFA i.e. swapped nibbles of the input parameter
It is clearly stated that this is an inline routine and does not count agaisnt the nested call limit.

However ...

Code: Select all

void main() {
 char x;
 x=53;
 swap(x);
}
Generates the following listing :

Code: Select all

_Swap:
;__Lib_System.c,44 :: 		
;__Lib_System.c,45 :: 		
0x000B	0x1283      	BCF        STATUS, 5
0x000C	0x0823      	MOVF       FARG_Swap_input, 0
0x000D	0x00D0      	MOVWF      R0
;__Lib_System.c,46 :: 		
0x000E	0x0ED0      	SWAPF      R0, 1
;__Lib_System.c,47 :: 		
;__Lib_System.c,48 :: 		
0x000F	0x0008      	RETURN
; end of _Swap

;test-def.c,29 :: 		swap(x);
0x0047	0x0822      	MOVF       main_x_L0, 0
0x0048	0x00A3      	MOVWF      FARG_Swap_input
0x0049	0x200B      	CALL       _Swap
Shouldn't it just generate something like this : with an optional bankselect if necessary ?

Code: Select all

SWAPF main_x_L0, 1

andrixnet
Posts: 8
Joined: 12 May 2011 11:50

Re: swapf() macro

#5 Post by andrixnet » 25 May 2012 12:56

I would like to report a bug in MikroC for PIC.

swap() is documented as a macro, but code is generated as a function with all due overhead, instead of a single SWAPF instruction.

Post Reply

Return to “mikroC Wish List”