swapf() macro
-
- Posts: 56
- Joined: 11 Jun 2006 03:49
- Location: Lake Oswego, Oregon
- Contact:
swapf() macro
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.
-
- Posts: 56
- Joined: 11 Jun 2006 03:49
- Location: Lake Oswego, Oregon
- Contact:
Re: swapf() macro
We will implement this.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.
Re: swapf() macro
Compiler v4.60 lists this in the help :
However ...
Generates the following listing :
Shouldn't it just generate something like this : with an optional bankselect if necessary ?
It is clearly stated that this is an inline routine and does not count agaisnt the nested call limit.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
However ...
Code: Select all
void main() {
char x;
x=53;
swap(x);
}
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
Code: Select all
SWAPF main_x_L0, 1
Re: swapf() macro
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.
swap() is documented as a macro, but code is generated as a function with all due overhead, instead of a single SWAPF instruction.