Situation
The language's loop form, currently implemented as a PIC macro, is compiled into instructions including SUBWF, BTFSC and a recursive function call.
For example, the following expression:
is expanded into:
(let ((_loop (i)
(if (= i 0)
0
(progn
0
(_loop (- i 1))))))
(_loop 10)
then, is compiled into:
MOVLW 00Ah
MOVLW I0
GOTO __LOOP1014
__LOOP1014
MOVF I0,W
MOVWF L0
MOVLW 000h
SUBWF L0,W
BTFSC STATUS,Z
GOTO _ELSE10
RETLW 000h
_ELSE10
MOVLW 001h
SUBWF L0,W
MOVWF L1
MOVF L1,W
MOVWF I0
GOTO __LOOP1014
Problem
There are unnecessary instructions in the compiled assembly compared with the case using DECFSZ instruction.
- get from and put into an input pseudo-register
- the first
GOTO instruction
- a conditional branch with
SUBWF and BTFSC instructions
SUBWF instruction for decrement
Goal
Make loop forms compiled into instructions using DECFSZ instruction.
MOVLW 00Ah
MOVWF L0
__LOOP
DECFSZ L0,F
GOTO __LOOP
RETLW 000h
Approach
The following approaches are considerable:
- introducing
loop syntax, not as a PIC macro
- identifying loop structure to be optimized (chains of recurrences?)
Notes
There are some notes.
- updating
mdelay1 function's magic number
Situation
The language's
loopform, currently implemented as a PIC macro, is compiled into instructions includingSUBWF,BTFSCand a recursive function call.For example, the following expression:
is expanded into:
then, is compiled into:
Problem
There are unnecessary instructions in the compiled assembly compared with the case using
DECFSZinstruction.GOTOinstructionSUBWFandBTFSCinstructionsSUBWFinstruction for decrementGoal
Make
loopforms compiled into instructions usingDECFSZinstruction.Approach
The following approaches are considerable:
loopsyntax, not as a PIC macroNotes
There are some notes.
mdelay1function's magic number