0
\$\begingroup\$

Need to shift 3bytes each in RAM buffer to the next 3 RAM locations in a circular manner. The below code is ok, but is there any compact method to do it?

;cblock 40h
                L1,L2,L3
                L4,L5,L6
                L7,L8,L9
                L10,L11,L2
                L13,L14,L15
                L16,L17,L18
                L19,L20,L21
                ;
                L22,L23,L24
                L25,L26,L27
                L28,L29,L30
                L31,L32,L33
                L34,L35,L36
                L37,L38,L39
                L40,L41,L42
                endc


Shift_Buffer_3X_Up  
                movf    L1,W
                movwf   Temp_L1
                movf    L2,W
                movwf   Temp_L2
                movf    L3,W
                movwf   Temp_L3
                movlw   L4
                movwf   FSR
                movlw   .13
                movwf   Rotate_Count
Shift_3X_Up_Loop    movf    INDF,W
                movwf   Red
                incf    FSR,F
                movf    INDF,W
                movwf   Green
                incf    FSR,F
                movf    INDF,W
                movwf   Blue
                movlw   .3
                subwf   FSR,F
                movf    Blue,W
                movwf   INDF
                decf    FSR,F
                movf    Green,W
                movwf   INDF
                decf    FSR,F
                movf    Red,W
                movwf   INDF
                movlw   .6
                addwf   FSR,F
                decfsz  Rotate_Count,F
                goto    Shift_3X_Up_Loop
                movf    Temp_L1,W
                movwf   L40
                movf    Temp_L2,W
                movwf   L41
                movf    Temp_L3,W
                movwf   L42
                return
\$\endgroup\$
  • 1
    \$\begingroup\$ It looks like a general embedded programming question with no direct connection to electronics or hardware, next time it's better to use codereview.stackexchange.com, and tag it "hardware" and "embedded". \$\endgroup\$ – 比尔盖子 Jun 26 at 12:21
0
\$\begingroup\$

Some hints:

  • Make sure your Temp_L1, Temp_L2 and Temp_L3 are located immediately after L42.

  • Copy 1 byte at a time, not 3.

  • If you have two FSRs, use both of them.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.