Searching \ for '[PIC] : Composed 16 bit return value in Hi-Tech C' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/languages.htm?key=c
Search entire site for: ': Composed 16 bit return value in Hi-Tech C'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] : Composed 16 bit return value in Hi-Tech C'
2001\06\01@112304 by Alvaro Deibe Diaz

flavicon
face
Hello everybody,

When I try to return an unsigned int value from an A/D acquisition routine,
in Hi-Tech C (16F877), the best I can do looks like this:

unsigned int lee_AD(unsigned char c)
{
...
return (unsigned int)((ADRESH<<8)|ADRESL)
}

this code makes the following asm:

movf   0x1E,W
movwf  0x72
clrf   0x71
bsf    0x3,0x5
movf   0x1E,W
iorwf  0x71
bcf    0x3,0x5
return

this seems too much code to return two bytes. I would spect something like
this:

movf   0x1E,W
movwf  0x72
bsf    0x3,0x5
movf   0x1E,W
movwf  0x71
bcf    0x3,0x5
return

How must I wrote the C return code to get this asm?

Thanks,

Alvaro.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\06\01@193927 by Mike Mansheim

flavicon
face
looks to me like your c compiler is doing great - only one more
instruction than you would do by hand.

>>
this code makes the following asm:

movf   0x1E,W
movwf  0x72
clrf   0x71
bsf    0x3,0x5
movf   0x1E,W
iorwf  0x71
bcf    0x3,0x5
return

this seems too much code to return two bytes. I would spect something like
this:

movf   0x1E,W
movwf  0x72
bsf    0x3,0x5
movf   0x1E,W
movwf  0x71
bcf    0x3,0x5
return
<<

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\06\01@200129 by Spehro Pefhany

picon face
At 06:29 PM 6/1/01 -0500, you wrote:
>looks to me like your c compiler is doing great - only one more
>instruction than you would do by hand.

That was my impresion.. if he really needs to save that one instruction,
he could do something like this (but I wouldn't bother except in very
special circumstances like bit-banging stuff out at high speed):

unsigned int lee_AD(void)
 {

 // rest of the function

 #asm
 movf  30,w
 movwf btemp+1
 bsf   3,5
 movf  30,w
 bcf   3,5
 movwf btemp
 #endasm
 }

(and ignore the warning about implicit return from non-void.. this should
work,
but not tested..)

Best regards,


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
spam_OUTspeffTakeThisOuTspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...