From: Marcin C. <sa...@sa...> - 2010-09-10 22:03:57
|
On Fri, 10 Sep 2010, pito wrote: First, I am assuming that "Luboš assembler" is a set of words from the lib/assembler.frt file in the amforth distribution. Is this correct? > 1. I want to write a new word full in asm called fuX (a b c -- y ) > 2 I want to use an existing "code" written in assembler, it is > relocable. > 3. I will take a "template" from a word, I can see the header etc. (I don't understand this - what is your "header" etc.) > 4. the input and output is now clear to me, loadtos, savetos > indirect via Y. If you want to return only one cell ("y") you need just to set the TOS in tosh:tosl register pair. No need to use savetos. > Q: which registers (Rx) can I freely use without ANY limitation in > my fuX? I can see the register used in .lst of course, however I > need a proven list which really can be used. > Q: there are registers named tempx - again - which can be used? > There is a difference when using those tempx in Lubos' assmbler vs. > usage in normal asm - Lubos' asm is based on forth words, which may > use internally some registers, this was what I saw - some registers > combinations did garbage. Yes, tempx are left for free use of FORTH words. That's what Matthias wrote before already. First, from what I understand - Matthias please correct me if I am wrong - the "code" word creates a new word for you but it does not switch FORTH into the compilation mode (unlike ":" or "]"). So that means that all words (like "ld,", "st,") are executed immediately and they can produce compiled machine code entered into the dictionary only in the explicit way by using "," (comma) word. Practically means that all FORTH code in the assembler is executed immediately (think of it as they all were IMMEDIATE words) and the only thing you are left in your newly defined word is pure assembler code as defined by you. Luboš code is gone by the time you are executing a word. So it does not matter whether you use some registers when using code ... end-code or whether using direct assembly (like adding .asm file to your amforth). If you have some problems with "garbage" - please be more specific, it is possible that the error is somewhere else. > Q: which registers can we use in Lubos' asm, which in normal asm > (again - we can see the .lst allocation, but pls confirm. > Q: Lubos is using Z registers frequently - is it allowed (both in L > asm or normal asm)? We need some indirect addressing so is Z fully > free to use? I don't know - where does assembler use Z? See above - it probably does not matter at all. > Q: When using L.asm (Lubos') or normal asm - which regs shall be > pushed, popped? If you are only using tosh, tosl, tempX registers - none. Please be aware that push and pop goes to the machine stack which is FORTH return stack (therefore they are an equivalent of >r and r>). > Q: When RAM space is required in the asm code - can you give us some > RAM ragion where we may do what we really want? Please feel free to "allot" something and use that. There is also "pad" available as well. > Q: It is understood we cannot use calls inside fuX, only jumps. > L.asm needs a kind of table for jumps, normal asm does not I guess. I don't understand this problem. I think you can define labels using the assembler.frt. (I didn't use them though). I am not sure whether the code is correct in assembler.frt - it uses "here" to indicated labels in the code, where it should probably use "dp" (dictionary pointer) - due to RAM (last position pointed to by "here", advanced by "allot") and dictionary in flash (managed by "dp", advanced by comma) are different thing in amforth. > Q: shall the interrupts be disabled when in fuX? I don't think so. > Q: accessing vars - can we define a specific place in RAM where we > can place the local asm variables and which will not be interfered > by forth? Use "here" and "allot". > 6. the fuX will read the data from data stack, it will process it > (about 500 lines of assembler) and at the end it writes results to > data stack. Q: Can we create such long word? Any restriction on the > lenght of a word? No limits on length except size of your flash. > 8. forth's Return stack - my understanding is we cannot use it for > any assembler routine, can we? how? Of course you can use it. It's what "push" and "pop" do. See question above regarding push/pop. > 9. so now I have an asm word fuX - with header (copied from other > words and adjusted accordingly), body (~500lines asm) and it will > end with "rjmp DO_NEXT". I will include this fuX.asm into dictionary > and compile together with amforth. This is the basic Idea. You do not need "rjmp DO_NEXT" (or most probably "jmp DO_NEXT") if using "end-code" word ($940c and DO_NEXT address will be compiled - see "end-code.asm"). > I DO UNDERSTAND THIS WAY OF WORKING WITH AMFORTH IS NOT THE > PREFFERED ONE FROM PRINCIPLE (PORTABILITY), but I still cope with an > idea to be able to "link" _ANY_ asm code into an amforth word (input > output via dstack). I don't know what kind of portability you mean. Forth code is way more portable between different platforms than assembly code (with obvious limitations related to the low-level words). So writing words is assembler is not really the Forth way. The other thing you might mean is interoperability (not portability) as in "I want to write some code in C or assembly and attach it to my forth words". Sure you can. I was thinking about uploading .hex files or even ready-to-run object or ELF files that could be executed by the FORTH word. FORTH does not really limit you in this unless you need a bootloader-specific code. > Interrupts: No answers from me on that this time :-) --Marcin |