From: pito <pi...@vo...> - 2010-09-07 23:52:31
|
Hi, I started with LP asm (amforth 4.0): \ ----- Test AvrAsm ----- : loadtos, 16 Y+ ld, 17 Y+ ld, ; \ define macro : savetos, -Y 17 st, -Y 16 st, ; \ tosl=r22, tosh=r23 code dup_ savetos, end-code \ insert asm code code drop_ loadtos, end-code and I get: > 10 dup_ ok > .s 0 16379 10 1 16381 9546 ok > 20 dup_ ok > .s 0 16375 20 1 16377 9546 2 16379 10 3 16381 9546 ok > drop_ drop_ ok > .s 0 16379 20 1 16381 9546 ok > the ++_ demo crashes... Any help, new update, or I did something wrong (I loaded assembler.frt of course). P. |
From: Marcin C. <sa...@sa...> - 2010-09-08 00:47:53
|
On Wed, 8 Sep 2010, pito wrote: > Marcin, thanks! So when I dump: > > then I see at sp0 = 16383 is 0. Why the 111 is written to 16381 > (low) and 16382 (high) and not to 16382 (low) and 16383 (high)? Not > so important, only the alignment of words on odd addresses is > something unusual to see..P. Why not? That's because that's the way loadtos and savetos macros are constructed. low byte goes to the low address (even). There is no requirement to align words on a word boundary. Which leads me to another point: On Wed, 8 Sep 2010, pito wrote: > Hi, I started with LP asm (amforth 4.0): > \ ----- Test AvrAsm ----- > : loadtos, 16 Y+ ld, 17 Y+ ld, ; \ define macro > : savetos, -Y 17 st, -Y 16 st, ; \ tosl=r22, tosh=r23 Maybe 16, 17 are wrong values for your CPU? --Marcin |
From: Marcin C. <sa...@sa...> - 2010-09-08 09:08:03
|
On Wed, 8 Sep 2010, pito wrote: > Hi, I started with LP asm (amforth 4.0): > \ ----- Test AvrAsm ----- > : loadtos, 16 Y+ ld, 17 Y+ ld, ; \ define macro > : savetos, -Y 17 st, -Y 16 st, ; \ tosl=r22, tosh=r23 > > code dup_ savetos, end-code \ insert asm code > code drop_ loadtos, end-code On my ATmegas (328P) this works fine: decimal : loadtos, 24 Y+ ld, 25 Y+ ld, ; : savetos, -Y 25 st, -Y 24 st, ; TOS is in r24/r25 (check your loadtos/storetos macro in your assembler listing). --Marcin |
From: pito <pi...@vo...> - 2010-09-08 09:29:24
|
Marcin, I am ansewering to you in this thread: No, R16 and R17 are ok for my cpu, but not correct from OS prospecive. I've spent a sleepless night with playing with registers against definitions in macros.asm (it seems Registers 10,11,12,13, are not used by OS but in reality code crashes) and the preliminary result is: \ ----- Test AvrAsm ----- \ : loadtos, 16 Y+ ld, 17 Y+ ld, ; \ define macro \ : savetos, -Y 17 st, -Y 16 st, ; \ tosl=r22, tosh=r23 : loadtos, 24 Y+ ld, 25 Y+ ld, ; \ define macro : savetos, -Y 25 st, -Y 24 st, ; \ tosl=r22, tosh=r23 code dup_ savetos, end-code \ insert asm code code drop_ loadtos, end-code code ++_ \ ( x1 x2 x3 -- x4 ) R18 push, R19 push, \ R24 push, \ R25 push, R18 0 ldi, R19 0 ldi, R24 Y+ ld, R25 Y+ ld, R18 R24 add, R19 R25 adc, R24 Y+ ld, R25 Y+ ld, R18 R24 add, R19 R25 adc, R24 Y+ ld, R25 Y+ ld, R18 R24 add, R19 R25 adc, R24 R18 mov, R25 R19 mov, \ R24 255 ldi, \ R25 128 ldi, -Y R25 st, -Y R24 st, \ R25 pop, \ R24 pop, R19 pop, R18 pop, end-code > 100 200 300 ++_ ok > .s 0 16381 28171 ok > 100 200 300 ++_ ok > .s 0 16379 28471 1 16381 28471 ok > > 100 dup_ ok > .s 0 16379 100 1 16381 100 ok > 300 dup_ ok > .s 0 16375 300 1 16377 300 2 16379 100 3 16381 100 ok > drop_ ok > .s 0 16377 300 1 16379 100 2 16381 100 ok > drop_ drop_ drop_ ok > .s ok > The loadtos and savetos works somehow, but I am not able to run ++_ My current understanding is something still overwrites registers used. Based on used set of registers the results vary. It would be nice to have a list (or a brief Guide) which Registers one may use in such assembler run within forth. Pito ----- PŮVODNÍ ZPRÁVA ----- Od: "pito" <pi...@vo...> Komu: sa...@sa..., amf...@li... Předmět: [Amforth-devel] Assembler - initial issues or bug Datum: 8.9.2010 - 1:52:22 > Hi, I started with LP asm (amforth 4.0): > \ ----- Test AvrAsm ----- > : loadtos, 16 Y+ ld, 17 Y+ ld, ; \ define macro > : savetos, -Y 17 st, -Y 16 st, ; \ tosl=r22, > tosh=r23 > > code dup_ savetos, end-code \ insert asm code > code drop_ loadtos, end-code > > and I get: > > 10 dup_ > ok > > .s > 0 16379 10 > 1 16381 9546 > ok > > 20 dup_ > ok > > .s > 0 16375 20 > 1 16377 9546 > 2 16379 10 > 3 16381 9546 > ok > > drop_ drop_ > ok > > .s > 0 16379 20 > 1 16381 9546 > ok > > > > the ++_ demo crashes... Any help, new update, or I > did something > wrong (I loaded assembler.frt of course). P. > > > ------------------------------------------------------------------------------ > > This SF.net Dev2Dev email is sponsored by: > > Show off your parallel programming skills. > Enter the Intel(R) Threading Challenge 2010. > http://p.sf.net/sfu/intel-thread-sfd > _______________________________________________ > Amforth-devel mailing list > Amf...@li... > https://lists.sourceforge.net/lists/listinfo/amforth-devel |
From: Marcin C. <sa...@sa...> - 2010-09-08 09:41:00
|
On Wed, 8 Sep 2010, pito wrote: > Marcin, I am ansewering to you in this thread: No, R16 and R17 are > ok for my cpu, but not correct from OS prospecive. I've spent a > sleepless night with playing with registers against definitions in > macros.asm (it seems Registers 10,11,12,13, are not used by OS but > in reality code crashes) and the preliminary result is: pito, please please - study the Amforth 4.0 Technical Guide - part 4.2 describes the register usage. Second, please do study the assembler listing (the large file I told you once to generate) - it contains whole source of the amforth compiled *including* generated machine code - this is the best for debugging assembly. --Marcin |
From: pito <pi...@vo...> - 2010-09-08 10:27:10
|
Marcin, yes to study the manual is important! However, we do not do it quite often.. I've seen the manual and therefore I am using register allowed. loadtos and savetos works with 24 and 25(? as used in loadtos, savetos), and I used 10-13 and 14-21 for ++_ routine. However results differs. So my understanding is you shall be careful to use those registers so freely as described in manual. Maybe someone experienced helps with the bug in the ++_ routine, which crashes: code ++_ \ ( x1 x2 x3 -- x4 ) R10 push, \ save everything R11 push, R24 push, \ shall this be pushed and popped ? R25 push, R10 0 ldi, \ x4 - accumulates result, zero it R11 0 ldi, R24 Y+ ld, \ loadtos R25 Y+ ld, \ load data x3 from stack R10 R24 add, \ add x4 = x3 + 0 R11 R25 adc, R24 Y+ ld, R25 Y+ ld, \ load data x2 from stack R10 R24 add, \ add x4 = x2 + x3 + 0 R11 R25 adc, R24 Y+ ld, R25 Y+ ld, \ load data x1 from stack R10 R24 add, \ add x4 = x1 + x2 + x3 + 0 R11 R25 adc, R24 R10 mov, \ mov x4 to R25,24 R24 R10 movw, R25 R11 mov, \ R24 255 ldi, \ for testing purposes \ R25 128 ldi, -Y R25 st, \ savetos, save x4 to tos -Y R24 st, R25 pop, \ load back everything R24 pop, R11 pop, R10 pop, end-code |
From: pito <pi...@vo...> - 2010-09-08 11:01:41
|
A version with unused registers, crashes (anforth 4.0, assembler.frt). \ Manual v 4.0 : The registers from R10 to R13 are currently unused, \ but may be used for the VM extended registers X and Y sometimes. code ++_ \ ( x1 x2 x3 -- x4 ) R10 push, \ save everything R11 push, R12 push, \ shall this be pushed and popped ? R13 push, R10 0 ldi, \ x4 - accumulates result, zero it R11 0 ldi, R12 Y+ ld, \ loadtos R13 Y+ ld, \ load data x3 from stack R10 R12 add, \ add x4 = x3 + 0 R11 R13 adc, R12 Y+ ld, R13 Y+ ld, \ load data x2 from stack R10 R12 add, \ add x4 = x2 + x3 + 0 R11 R13 adc, R12 Y+ ld, R13 Y+ ld, \ load data x1 from stack R10 R12 add, \ add x4 = x1 + x2 + x3 + 0 R11 R13 adc, R12 R10 mov, \ mov x4 to, R12 R10 movw, R13 R11 mov, -Y R13 st, \ savetos, save x4 to tos -Y R12 st, R13 pop, \ load back everything R12 pop, R11 pop, R10 pop, end-code |
From: Marcin C. <sa...@sa...> - 2010-09-08 12:09:47
|
On Wed, 8 Sep 2010, pito wrote: > A version with unused registers, crashes (anforth 4.0, > assembler.frt). > > \ Manual v 4.0 : The registers from R10 to R13 are currently unused, > > \ but may be used for the VM extended registers X and Y sometimes. > > code ++_ \ ( x1 x2 x3 -- x4 ) Looking at my assembly listing: .def temp0 = r16 .def temp1 = r17 .def tosl = r24 .def tosh = r25 PFA_PLUS: C:0039ab 9109 ld temp0, Y+ C:0039ac 9119 ld temp1, Y+ C:0039ad 0f80 add tosl, temp0 C:0039ae 1f91 adc tosh, temp1 C:0039af ce5e rjmp DO_NEXT So, that means that simple ld temp0, Y+ ld temp1, Y+ add tosl, temp0 adc tosh, temp1 ld temp0, Y+ ld temp1, Y+ add tosl, temp0 adc tosh, temp1 rjmp DO_NEXT should do the trick. Doing in Forth: R16 constant temp0 R17 constant temp1 R24 constant tosl R25 constant tosh code ++_ temp0 Y+ ld, temp1 Y+ ld, tosl temp0 add, tosh temp1 adc, temp0 Y+ ld, temp1 Y+ ld, tosl temp0 add, tosh temp1 adc, end-code hex 1000 100 10 ++_ . 1110 ok 1111 222 33 ++_ . 1366 ok It's really beneficial to study existing assembler code! It also is immediately clear that ++_ is the equivalent of + + - what I did is just + operation inlined twice. --Marcin |
From: pito <pi...@vo...> - 2010-09-08 16:56:24
|
.. and my not so elegant code, it works as well and is commented a little bit. Good for beginners who are not reading forth's sources.. Thanks a lot Marcin, your code is of course optimised to the bones..Pito \ Assembler demo \ ATmega 1284p, amforth 4.0 \ v68.0, Pito 9/2010 marker -asstest : loadtos, R24 Y+ ld, R25 Y+ ld, ; \ define macro : savetos, -Y R25 st, -Y R24 st, ; \ tosl=R24, tosh=R25 code ++_ \ ( x1 x2 x3 -- x4 ) \ R8 R6 - tmp reg. \ x3 already in tos R8 R24 mov, R6 R25 mov, \ tmp = x3 \ drop x3 loadtos, \ x2 in tos R8 R24 add, R6 R25 adc, \ add tmp = x3 + x2 \ drop x2 loadtos, \ x1 in tos R8 R24 add, R6 R25 adc, \ add tmp = x3 + x2 + x1 \ drop x1 loadtos, \ put x4 on tos, x4 = tmp R24 R8 mov, R25 R6 mov, savetos, end-code ---------------------------- Ex: > 1111 2222 3333 ++_ . .sls 6666 [TOS> ] ok > 30000 -28000 -4000 ++_ . .sls -2000 [TOS> ] ok > -30000 15000 15000 ++_ . .sls 0 [TOS> ] ok > |
From: Matthias T. <mt...@we...> - 2010-09-09 18:10:28
|
Pito, > Hi, I started with LP asm (amforth 4.0): > \ ----- Test AvrAsm ----- > : loadtos, 16 Y+ ld, 17 Y+ ld, ; \ define macro > : savetos, -Y 17 st, -Y 16 st, ; \ tosl=r22, tosh=r23 The assembler may use any register. But one has to be careful when changing registers used by amforth itself. The actual register allocation is in the macros.inc file. Its safe to use the registers labeled as temp, all others should not be changed at all. Some are seldom used, others only if special words are used (such as the extended vm registers from reg-a.asm). There is no way to use forth words from within the assembler code. For that you need to initialize a forth vm and call it. The only "guide" for that is the startup code itself (amforth.asm). Matthias |
From: Kalus M. <mic...@on...> - 2010-09-09 18:49:55
|
Am 09.09.2010 um 20:10 schrieb Matthias Trute: ... > There is no way to use forth words from within the > assembler code. For that you need to initialize > a forth vm and call it. The only "guide" for that > is the startup code itself (amforth.asm). and goes like this: <snip> sei ; global interupt enable. push XL push XH lds XL,0x5F ; status register push XL .. maybe you have to include even more registers push R22 ; tosl = r22 push R23 ; tosh = r23 push R24 ; wl push R25 ; wh push YL push YH push ZL push ZH ... <your code> ... ; switch to high level forth: : sei ldi XL,low(pfa_forthISR) ldi XH,high(pfa_forthISR) jmp DO_NEXT ; -- pointer to NEXT word: pfa_forthISR: .dw XT_MAINWORD ; -- come back to code: .dw PC+1 ; next IP .dw PC+1 ; next cfa ... <more of your code> ... pop ZH pop ZL pop YH pop YL pop R25 pop R24 pop R23 pop R22 .. maybe you have to include even more registers pop XL sts 0x5F,XL pop XH pop XL jmp DO_NEXT (or RTI if you are in an ISR) </snip> see examples in paper VD1/2010 http://www.forth-ev.de/filemgmt/ viewcat.php?cid=53 worked with amforth3.6 still good with 4.1? Michael |
From: pito <pi...@vo...> - 2010-09-11 16:12:35
|
Michael, thanks! I will rather start step by step, so no forth words called from within assembler now! As I can see the tosl and tosh and register setup are changing. I hope they are same for any processor type within a release. P. > worked with amforth3.6 > still good with 4.1? > Michael |