Re: [Flashforth-devel] Switching Endians -- swapbytes for FF18
Brought to you by:
oh2aun
From: Mikael N. <mik...@pp...> - 2014-03-27 19:15:47
|
That's great Craig, but can you spot the bug in your code ? It can also be done with temp registers, since FF has alot of interrupt safe temp registers, Tp(fsr1) in this case. Swapbytes is called '><' in the Atmega FF. It was needed there to manipulate return addresses. : >< [ Sminus, w, a, movf, ] [ Srw, Tp, movff, ] [ Splus, a, movwf, ] [ Tp, Srw, movff, ] ; BR Mike On 03/27/2014 08:18 PM, craig bair wrote: > I needed to swap bytes to send to another machine, so I implamented > one of my favorite tricks from "back in the day" when I was learning > MACRO-11 on the college PDP-11/40... Swapping register contents > without auxiliary storage. Mike's made it easy for us in the Pic18-s, > probably the rest of the chips, too. > > swapbytes ( xy -- yx ) \ reverses byte order on Top-Of-Stack > > craig bair > > --------------- > > \ Reverse ENDIAN-ness of 16-bit on Top Of Stack > \ i.e. Swap Bytes > \ ...minimalist approach, no temp storage loc > \ > \ needed constants (could be hardwired into code > $ffe9 constant fsr0 \ ; 0xFE9 FSR0L > \ $ffea constant fsr0h \ ; 0xFEA FSR0H > $ffef constant indf0 \ INDirect-by-FSR0 FileRegister > 1 constant f, \ Destination File > \ > \ needed assembler constructor > : as2 ( opcode "name" -- ) ( f a -- ) > co: > does> rot ic, or ic, ; > \ > \ needed assembler instructions > $04 as3 decf, ( f d a -- ) > $28 as3 incf, ( f d a -- ) > $18 as3 xorwf, ( f d a -- ) > $6e as2 movwf, ( f a -- ) > \ > \ actual word > : swapbytes ( xy -- yx ) \ swap Hi:Lo bytes on Top of Stack > [ indf0 w, a, movf, ] > [ fsr0 f, a, decf, ] > [ indf0 f, a, xorwf, ] > [ indf0 w, a, xorwf, ] > [ indf0 f, a, xorwf, ] > [ fsr0 f, a, incf, ] > [ indf0 a, movwf, ] > ; > > ...averaging may or may not help clarify data. > If Bill Gates walks into a bar, > the average patron becomes a millionaire... > > > ------------------------------------------------------------------------------ > > > _______________________________________________ > Flashforth-devel mailing list > Fla...@li... > https://lists.sourceforge.net/lists/listinfo/flashforth-devel |