Thread: [Flashforth-devel] AVR assembler and disassembler
Brought to you by:
oh2aun
From: Helge K. <Hel...@gm...> - 2021-12-31 11:36:07
|
Hello, I'm new to FlashForth. I want to use it for ATmega328 and ATmega2560. I try to implement an ISR for a bit bang serial port, since the ATmega328 has only one USART. My minimum code example is: $002b constant portd $002a constant ddrd $08 constant txd \ bit 3 $04 constant rxd \ bit 2 \ make an I/O addres from memory address for sbi and cbi. : >IO ( a - io ) $20 invert and ; : t2CompAIsr txd portd mset rxd portd mset rxd portd mclr txd portd mclr ; : t2CompAIsr_ [ portd >IO txd sbi, portd >IO rxd sbi, portd >IO rxd cbi, portd >IO txd cbi, ] ;i : irqCompAInit rxd ddrd mset \ to see write to rxd txd portd mset txd ddrd mset ['] t2CompAIsr_ compAIvec int! 208 ocr2a c! \ set comparator A register 2 tccr2a c! \ set CTC mode (WGM = 2) 6 tccr2b c! \ activate counter 2, clock source = clk_T2S/1 2 timsk2 mset \ activate timer2 comparatorA interrupt OCIE2A ; If I use mclr/mset to set the bits, I see the changes on the pins with a logic analyzer. But unfortunately I can't see any change on the PORTD pins if I use the word t2CompAIsr_. What's wrong with my assembler code? I want to verify what I compiled with the disassembler: see t2CompAIsr_ 975a 9a58 975c 9a5c 975e 985c 9760 9858 9762 940c 3c33 jmp ............... ok<$,ram> All the CBI/SBI is not decompiled. Probably this is not implemented in "forth/avr/see.fs". I also tried "forth/avr/see2.fs". The later file can't be compiled, a word sy1 is missing. How can I verify what's wrong with my simple code? Best regards, Helge |
From: Mikael N. <mik...@fl...> - 2021-12-31 14:59:20
|
<div dir='auto'>See2 requires that you compile asm2 first.<div dir="auto"><br></div><div dir="auto">: toIO $20 - ;</div><div dir="auto"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 31 Dec 2021 13:35, Helge Kruse <Hel...@gm...> wrote:<br type="attribution" /><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Hello,</p> <p dir="ltr">I'm new to FlashForth. I want to use it for ATmega328 and ATmega2560.</p> <p dir="ltr">I try to implement an ISR for a bit bang serial port, since the<br> ATmega328 has only one USART. My minimum code example is:</p> <p dir="ltr">$002b constant portd<br> $002a constant ddrd<br> $08 constant txd    \ bit 3<br> $04 constant rxd    \ bit 2</p> <p dir="ltr">\ make an I/O addres from memory address for sbi and cbi.<br> : >IO  ( a - io )  $20 invert and ;</p> <p dir="ltr">: t2CompAIsr  txd portd mset  rxd portd mset  rxd portd mclr  txd portd<br> mclr ;</p> <p dir="ltr">: t2CompAIsr_<br>     [<br>       portd >IO txd sbi,<br>       portd >IO rxd sbi,<br>       portd >IO rxd cbi,<br>       portd >IO txd cbi,<br>     ]<br> ;i</p> <p dir="ltr">: irqCompAInit<br>     rxd ddrd mset \ to see write to rxd<br>     txd portd mset  txd ddrd mset</p> <p dir="ltr">     ['] t2CompAIsr_ compAIvec int!<br>     208 ocr2a c!  \ set comparator A register<br>     2 tccr2a c!   \ set CTC mode (WGM = 2)<br>     6 tccr2b c!   \ activate counter 2, clock source = clk_T2S/1<br>     2 timsk2 mset \ activate timer2 comparatorA interrupt OCIE2A<br> ;</p> <p dir="ltr">If I use mclr/mset to set the bits, I see the changes on the pins with a<br> logic analyzer. But unfortunately I can't see any change on the PORTD<br> pins if I use the word t2CompAIsr_.</p> <p dir="ltr">What's wrong with my assembler code? I  want to verify what I compiled<br> with the disassembler:</p> <p dir="ltr">see t2CompAIsr_<br> 975a 9a58<br> 975c 9a5c<br> 975e 985c<br> 9760 9858<br> 9762 940c 3c33 jmp   ...............<br>  ok<$,ram></p> <p dir="ltr">All the CBI/SBI is not decompiled. Probably this is not implemented in<br> "forth/avr/see.fs". I also tried "forth/avr/see2.fs". The later file<br> can't be compiled, a word sy1 is missing.</p> <p dir="ltr">How can I verify what's wrong with my simple code?</p> <p dir="ltr">Best regards,<br> Helge<br><br><br><br></p> <p dir="ltr">_______________________________________________<br> Flashforth-devel mailing list<br> Fla...@li...<br> https://lists.sourceforge.net/lists/listinfo/flashforth-devel<br> </p> </blockquote></div><br></div> |
From: Helge K. <Hel...@gm...> - 2021-12-31 15:28:26
|
But loading asm2.fs calls *-as* and makes the asm words forgotten. Does that mean that I should use asm2 instead of asm? Best regards, Helge Am 31.12.2021 um 15:04 schrieb Mikael Nordman: > See2 requires that you compile asm2 first. > > : toIO $20 - ; > > |
From: Mikael N. <mik...@fl...> - 2021-12-31 18:00:47
|
<div dir='auto'>Yes. Or you can try to remove the -as line from the asm2 file.</div><div class="gmail_extra"><br><div class="gmail_quote">On 31 Dec 2021 17:28, Helge Kruse <Hel...@gm...> wrote:<br type="attribution" /><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div> <p>But loading asm2.fs calls <b>-as</b> and makes the asm words forgotten. Does that mean that I should use asm2 instead of asm?</p> <p>Best regards,<br /> Helge<br /> </p> <div>Am 31.12.2021 um 15:04 schrieb Mikael Nordman:<br /> </div> <blockquote> <div dir="auto">See2 requires that you compile asm2 first. <div dir="auto"><br /> </div> <div dir="auto">: toIO $20 - ;</div> <div dir="auto"><br /> </div> </div> <div><br /> </div> </blockquote> </div> </blockquote></div><br></div> |
From: Stefan <fli...@gm...> - 2022-01-02 08:30:21
|
Hallo Helge, disassembled code is: 9a58 -> sbi PORTD,0 (that's 8 mod 8 because only values from 0 to 7 are allowed) 9a5c -> sbi PORTD,4 ... because cbi/sbi use the bitnumber and not the bitmask. use: 3 constant txd_pin 2 constant rxd_pin greetz bitflipser Am 31.12.2021 um 12:35 schrieb Helge Kruse: > Hello, > > I'm new to FlashForth. I want to use it for ATmega328 and ATmega2560. > > I try to implement an ISR for a bit bang serial port, since the > ATmega328 has only one USART. My minimum code example is: > > $002b constant portd > $002a constant ddrd > $08 constant txd \ bit 3 > $04 constant rxd \ bit 2 > > \ make an I/O addres from memory address for sbi and cbi. > : >IO ( a - io ) $20 invert and ; > > : t2CompAIsr txd portd mset rxd portd mset rxd portd mclr txd portd > mclr ; > > : t2CompAIsr_ > [ > portd >IO txd sbi, > portd >IO rxd sbi, > portd >IO rxd cbi, > portd >IO txd cbi, > ] > ;i > > : irqCompAInit > rxd ddrd mset \ to see write to rxd > txd portd mset txd ddrd mset > > ['] t2CompAIsr_ compAIvec int! > 208 ocr2a c! \ set comparator A register > 2 tccr2a c! \ set CTC mode (WGM = 2) > 6 tccr2b c! \ activate counter 2, clock source = clk_T2S/1 > 2 timsk2 mset \ activate timer2 comparatorA interrupt OCIE2A > ; > > If I use mclr/mset to set the bits, I see the changes on the pins with a > logic analyzer. But unfortunately I can't see any change on the PORTD > pins if I use the word t2CompAIsr_. > > What's wrong with my assembler code? I want to verify what I compiled > with the disassembler: > > see t2CompAIsr_ > 975a 9a58 > 975c 9a5c > 975e 985c > 9760 9858 > 9762 940c 3c33 jmp ............... > ok<$,ram> > > All the CBI/SBI is not decompiled. Probably this is not implemented in > "forth/avr/see.fs". I also tried "forth/avr/see2.fs". The later file > can't be compiled, a word sy1 is missing. > > How can I verify what's wrong with my simple code? > > Best regards, > Helge > > > > > > _______________________________________________ > Flashforth-devel mailing list > Fla...@li... > https://lists.sourceforge.net/lists/listinfo/flashforth-devel |
From: Helge K. <Hel...@gm...> - 2022-01-02 10:22:53
|
Hi Stefan, > because cbi/sbi use the bitnumber and not the bitmask. Yes, now I understand why the code didn't work. I put two questions in one mail. Therefore the second question about the missing implementation for SBI/CBI in *see *is somehow lost. It was just a pity that see could not be used to verify the compiled code. I added some lines to see.fs: : .xbi ( addr -- addr) *@ dup 3 rshift 1f and ." r" decimal 2 u.r hex ." ," 7 and . cell+ ; : ?cbi ( addr -- addr f ) *@ ff00 and 9800 - ; : ?sbi ( addr -- addr f ) *@ ff00 and 9a00 - ; ?sbi 0= if 5sp ." sbi " .xbi else ?cbi 0= if 5sp ." cbi " .xbi else With these lines I get more info, at least for CBI/SBI. I wasn't aware that the implementation in see.fs is far from a complete discompiler. Best regards, Helge Am 02.01.2022 um 09:30 schrieb Stefan: > Hallo Helge, > > disassembled code is: > > 9a58 -> sbi PORTD,0 (that's 8 mod 8 because only values from 0 to 7 are > allowed) > 9a5c -> sbi PORTD,4 > ... > because cbi/sbi use the bitnumber and not the bitmask. > > use: > 3 constant txd_pin > 2 constant rxd_pin > > greetz bitflipser > > > Am 31.12.2021 um 12:35 schrieb Helge Kruse: >> Hello, >> >> I'm new to FlashForth. I want to use it for ATmega328 and ATmega2560. >> >> I try to implement an ISR for a bit bang serial port, since the >> ATmega328 has only one USART. My minimum code example is: >> >> $002b constant portd >> $002a constant ddrd >> $08 constant txd \ bit 3 >> $04 constant rxd \ bit 2 >> >> \ make an I/O addres from memory address for sbi and cbi. >> : >IO ( a - io ) $20 invert and ; >> >> : t2CompAIsr txd portd mset rxd portd mset rxd portd mclr txd portd >> mclr ; >> >> : t2CompAIsr_ >> [ >> portd >IO txd sbi, >> portd >IO rxd sbi, >> portd >IO rxd cbi, >> portd >IO txd cbi, >> ] >> ;i >> >> : irqCompAInit >> rxd ddrd mset \ to see write to rxd >> txd portd mset txd ddrd mset >> >> ['] t2CompAIsr_ compAIvec int! >> 208 ocr2a c! \ set comparator A register >> 2 tccr2a c! \ set CTC mode (WGM = 2) >> 6 tccr2b c! \ activate counter 2, clock source = clk_T2S/1 >> 2 timsk2 mset \ activate timer2 comparatorA interrupt OCIE2A >> ; >> >> If I use mclr/mset to set the bits, I see the changes on the pins with a >> logic analyzer. But unfortunately I can't see any change on the PORTD >> pins if I use the word t2CompAIsr_. >> >> What's wrong with my assembler code? I want to verify what I compiled >> with the disassembler: >> >> see t2CompAIsr_ >> 975a 9a58 >> 975c 9a5c >> 975e 985c >> 9760 9858 >> 9762 940c 3c33 jmp ............... >> ok<$,ram> >> >> All the CBI/SBI is not decompiled. Probably this is not implemented in >> "forth/avr/see.fs". I also tried "forth/avr/see2.fs". The later file >> can't be compiled, a word sy1 is missing. >> >> How can I verify what's wrong with my simple code? >> >> Best regards, >> Helge >> >> >> >> >> >> _______________________________________________ >> Flashforth-devel mailing list >> Fla...@li... >> https://lists.sourceforge.net/lists/listinfo/flashforth-devel > > > > _______________________________________________ > Flashforth-devel mailing list > Fla...@li... > https://lists.sourceforge.net/lists/listinfo/flashforth-devel |