Erich Waelde <ew.fo...@nassur.net> writes:

> Hi Enoch,
>
> since you asked for comments ...

I certainly do!

> On 02/13/2013 05:38 AM, Enoch wrote:
>> Hello Matthias and all,
>> 
>> I'd like to see this forum also offering code snippets, so here's my
>> first humble attempt of harnessing the atomic bit manipulation
>> instructions.
>> 
>> : port:hi ( portadr bitno -- )           \ SBI
>>      swap $20 - 3 lshift or $9A00 or code , end-code
>> ;
>> 
>> : port:lo ( portadr bitno -- )           \ CBI
>>      swap $20 - 3 lshift or $9800 or code , end-code
>> ;
>> 
>> example:
>> 
>> PORTB 7 port:hi green.hi
>> PORTB 7 port:lo green.lo
>> 
>
> So you want to set or clear a bit in some register.
>
> What is wrong with the words found in bitnames.frt?
>
>   include lib/bitnames.frt
>   PORTB 7  portpin: green
>
> and later
>
>   green pin_output
>   green high
>   \ do something here
>   green low

SBI/CBI can change bits in the 0..31 I/O range without needing a -int /
+int protection. avr-gcc, for example, would use SBI when compiling
PORTA |= _BV(0);

> Sure, bitnames is doing read+modify+write on the memory mapped
> location of the register, while your solution uses sbi/cbi which
> does not work on the memory mapped location (hence $20 - ).
> But what exactly is better with using sbi/cbi? That sbi/cbi
> cannot be interrupted once the instruction is executing? But
> all the instructions leading up to the sbi/cbi can be
> interrupted, can't they? Do I miss the entire motivation of
> the code snippet? Would you dare to enlighten me??

Well, let's try the following indirect argument:

Atmel thought these instructions to be important enough to "spend" 2^10
opcodes out of their precious 2^16 RISC range. Don't we need to respect
that engineering decision by suitable Amforth words?

> As Matthias pointed out elsewhere: your snippet is intersting,
> because assembly instructions are coded in at compile time
> without loading the full assembler. That I can see.

Yes, that DIY assembly approach can do things which lib/assembler.frt
may find difficult to follow :-)

Regards, Enoch.

>
> Cheers,
> Erich
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_feb


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel

Reply via email to