I am trying to learn to call some C floating point routines from Assembly. I am quite proficient in writing Assembly programs which | have done commercially for many years. I have read the <http://www.keil.com/support/docs/697.htm> page but can make no sense of it Basically where is what to be done? For example what does "You can then use the src file as a template to...." And "....you must also include the EXTRN directive for the function, eg: EXTRN CODE (_foo)" I include it where? Will the final project be an assembly project or a C project? I have written my own Assy routines for +-x/ in Floating point but now need some Sin/Cos/log functions. Hence the need for C. Which I hate. I found that it is not possible to use the #pragma src is directed and I have to assemble the file twice. Can some kind person please help by, say, pointing to some page where I can begin to understand Keil C language conventions. The Keil Documents do not give a place where I can find the start of a thread to unravel. Every explanation points to another explanation in another place. I do know C/C++ but not segment controls much. Thanks for the help
"what does 'You can then use the src file as a template to'"
They mean that it gives you an example showing how a call to a 'C' function is done in assembly - so you can modify and/or expand that example to suit you particular requirements to do whatever it is that you want to do in your application!
"....you must also include the EXTRN directive for the function, eg: EXTRN CODE (_foo)"
I thought you said you were a proficient assembly programmer? EXTRN is a standard assembler directive - you use it in exactly the same way that you would in any other assembly sourcefile. http://www.keil.com/support/man/docs/a51/a51_st_extrn.htm
"Will the final project be an assembly project or a C project?"
The tools rely on finding a 'C' main() function to tell them to include all the necessary support for 'C' - including floating point. Therefore, it is probably easiest to have your application start from a 'C' main() function.
You can do all necessary support for 'C' "manually" - and there are plenty of discussion threads and knowledgebase articles about that - but it seems to me like deliberately making things difficult for yourself!
"...C. Which I hate"
Why do you hate it? Doesn't this very question give you a very good reason to embrace it?
He may Hate C. But I assume he hates doing Floating point in ASM more.
I wonder if he really needs it anyhow...?
As the OP said in his opening gambit:
I am trying to learn to call some C floating point routines from Assembly.
There is a difference between trying to learn and needing. In achieving his goal he may well learn plenty of other aspects useful to future projects.
Hi fellas! Thanks for all your comments and very helpful suggestions.
Like my usual hasty self. Perhaps I did not explain too well. The Situation: I am self taught; Therefore there are holes (gaping voids in fact) in my understanding of programming. I can and do professionally write embedded programs for industry. (I make/sell machines from gas fired conversions for diesel generaors to environment monitoring/logging for GMP) All I ever learned was to use some basic assembly rules. My assy programs (all) have one core *.asm file where I start from the reset jump to a central sections. I include my self-written *.inc libraries. (I have these by the scores) the only assembler directive I have ever used are ( examples)
$include (TRIAXDEF.inc) org 0 rx_buf_head data 12 ; This is how I allocate space for program varialbels ljmp start in_progress: db 'Cutting in Progress ',22h all_clear: mov @r0,#0 (a label) END And a few more
That about all I know about how to use assy. I never used segmentation or any advanced control. I have witten extensive libraries of routines (assy) as *.inc files which I add to the programs I write to call my functions. All variables are in fixed locations except I define more than one variable at the same location if they are needed elsewhere/elsewhen later.
When I started to get problems with handling very large or small numbers, and particularly division, I tried to use C routines . but I found that I did not understand the C conventions and I have no patience for learning. So I decided to write my own Floating point software. The four basic functions are easy to do ascii to float and vice-versa a bit more tedious.
However soon I ran into log, trig and xendental functions and had to search through the Taylor/Mclaurin expansion based methods. Too much work required. (By the way I did write some of the higher functions using the Folder routines but for use with programmable hardware, (VHDL, not u controllers) But I don't get that sort of work often). That is when I decided to go back and learn some C (by this I mean the controls/directives etc. I can make C code no prob).
I find the readable material at Keil to be rather useless. I think the writers assume that the reader already knows everything about Keil C. What then the purpose? I guess I need a proper tutorial for Keil C. I don't/shouldn't expect you guys to teach me C on the forum. All I hope is to find a tutorial written in a curt and precise manner to read through. I assure you I possess normal intelligence and don't need "C for dummies" type of guides. My problem is with declarations, acesssibility/scope, linkages etc and the control directives.etc etc. I understand the MCS 51 hardware like the back of my hand.
All I hope for is your help, to find the right tutorial. I, once long ago, when learning C bought a book which after page 30 was still discussing, in a puerile fashion, the Printf() command. I had to throw it away at page 31. I am 66 and have no time for the too basic. I need something curt, but COMPLETE, written in a linear fashion, not circuitous.
Please help
Thanks Guys.
Why nitpick on words? need? want? They are used interchangeably in conversation bro.
Yes! Did you ever write code for y = log ( x/sin(x) )? Ain't pleasant, I assure you.
Why?
Did you ever write code for y = log ( x/sin(x) )?
Actually, yes I have. Years ago for the 6502 and the Z80.
Ain't pleasant, I assure you.
You're right there.
"I ... now need some Sin/Cos/log functions"
But there are techniques to do trig functions without floating-point; eg,
en.wikipedia.org/.../CORDIC
Hi!
Thanks! I am aware of the Cordic (AKA Volders rtn) method and as I stated above have used it with CPLD devices to implement eg., some mass flow calculations in a batch metering system etc. I wrote code for the HW with VHDL. Sorry that I referred to the technique as Folders method ISO Volders which is pronounced Folders.
There is this strange gap that I want to close. I do everything in Assy, of which too I don't fully know the conventions. All I am good with is writing complex routines in assy, which I am able to, being a hardware man at heart. It is high time I learned proper C and Assy.
I feel like a fool when I visit various fora and cannot follow what is being discussed.
I have found this book on the internet and will have it printed. It might just be the trick. ( printed vs read from a screen )
The C Book1 Mike Banahan, Declan Brady, Mark Doran January 1991
main.c
void main(void) { assembly_code(); }
with org 0 ljmp assembly_code
the C funmctions will not work
ALSO beware of the compilers call stack etc, I recommend that ALL global variables re defined in a C file.
Erik
Ehh???!!!
No - they assume that you are profficient in 'C' in general and, therefore, focus only on the specific details of the Keil implementation.
Compiler manuals are never intended to teach you 'C' - their purpose is to explain the specific implementation details.
Just as you wouldn't expect the handbook for a car to teach you to drive!
"All I hope for is your help, to find the right tutorial"
My suggestions here: blog.antronics.co.uk/.../
"I am 66 and have no time for the too basic"
But you need to lay solid foundations before you can start start building - if you skimp on the basics, you will come unstuck later...
then the compiler will do all location and thus you will not have any conflicts.
all variables will, then, of course, be stated as externs in the assembler code