#!/bin/bash set -e badusage () { echo >&2 'bad usage'; exit 1; } comment=';' macros=false case "$1" in --by-opcode) cohere=$1; sortkey=1 ;; --by-desc) cohere=$1; sortkey=29 ;; --by-official) cohere=$1; sortkey=68 ;; --macros) macros=true ;; --descs) comment='' ;; *) badusage ;; esac test $# = 1 || badusage flags () { eval "flags_$1=$2"; } flags addwf F flags addwfc F flags andwf ZN flags clrf Z flags comf ZN flags decf F flags incf F flags iorwf ZN flags movf ZN flags negf F flags rlcf ZNC flags rlncf ZN flags rrcf ZNC flags rrncf ZN flags subfwb F flags subwf F flags subwfb F flags xorwf ZN flags daw C flags addlw F flags andlw ZN flags iorlw ZN flags sublw F flags xorlw ZN if [ x$cohere != x ]; then sed <$0 -e '1,/^#'$cohere'--/d; /^#--0--/,$d' "$0" --descs | sort -t % -k 1.$sortkey test "${PIPESTATUS[*]}" = "0 0" sed <$0 -e '1,/^#--3--/d; /^#--0--/,$d' exit 0 fi w=0xfe8 lab=n lit=k desc () { local use=$1 new=$2 formargs=$3 notes=$4 eval "flags__use=\$flags_$use" local fan="$(printf "%-6s %s" "$formargs" "$flags__use$notes")" if $descs; then printf "$comment %-13s %-12s %-39s %s\n" \ "$new" "$fan" "$ds" "$use" fi } mapargs () { local str=$1 printf "%s\n" "$str" \ | sed -e 's/\b[a-z]\b/insn_aliases_arg_&/g' } alias_r () { local use=$1 new=$2 actargs=$3 formargs=$4 if $macros; then mapargs \ "$new macro $formargs $use $actargs endm" fi } alias_f () { local use=$1 new=$2 actargs=$3 formargs=$4 notes="$5" formargs=${formargs#,} desc $use $new "$formargs" "$notes" alias_r "$use" "$new" "$actargs" "$formargs" } als_fa () { local use=$1 base=$2 ext=$3 actargs=$4 formargs=$5 desc $use "$base$ext" f$formargs a alias_r $use ${base}${ext} f$actargs f$formargs alias_r $use ${base}a${ext} f$actargs,0 f$formargs alias_r $use ${base}b${ext} f$actargs,1 f$formargs } als_fa_1fw () { local use=$1 base=$2 ext=$3 actargs=$4 formargs=$5 als_fa $use ${base}f "$ext" "$actargs" "$formargs" alias_f $use ${base}w$ext $w$actargs,0 "$formargs" w } als_fda_2fw () { local use=$1 base=$2 ext=$3 als_fa $use ${base}f "$ext" ,1 als_fa $use ${base}w "$ext" ,0 } als_fda_1fw () { local use=$1 base=$2 ext=$3 actargs=$4 formargs=$5 als_fa $use ${base}f "$ext" $actargs,1 "$formargs" als_fa $use ${base}fw "$ext" $actargs,0 "$formargs" alias_f $use ${base}w$ext $w$actargs,0,0 "$formargs" w } als_k_lw () { local use=$1 base=$2 alias_f $use ${base}_lw $lit $lit } als_k_lw_fda_2fw () { local base=$1 als_fda_2fw ${base}wf ${base}_wf als_k_lw ${base}lw ${base} } als_k_lw_fa () { local base=$1 als_fa ${base}wf ${base}_wf als_k_lw ${base}lw ${base} } noalias () { local insn="$1" formargs=$2 notes=$3 desc "$insn" "$insn" "$formargs" "${notes}u" } descs_bra () { local what=$1 flag=$2 ds="Branch if $what"; alias_f b$flag bra_$flag $lab $lab 8r ds="Branch if Not $what"; alias_f bn$flag bra_n$flag $lab $lab 8r } if $macros; then echo ' ; autogenerated - do not edit'; echo ' nolist'; fi # `literal operations' (DS282) that are also mirrored by # `byte-oriented file register operations' (DS280) ds='Add'; als_k_lw_fda_2fw add ds='Bitwise AND'; als_k_lw_fda_2fw and ds='Bitwise Inclusive OR'; als_k_lw_fda_2fw ior ds='Bitwise Exclusive OR'; als_k_lw_fda_2fw xor ds='Move (flags unchanged)'; als_k_lw_fa mov ds='Multiply'; als_k_lw_fa mul # `byte-oriented file register operations' (DS280) ds='Add with carry'; als_fda_2fw addwfc addc_wf ds='Clear'; als_fa_1fw clrf clr_ ds='Complement (bitwise NOT)'; als_fda_1fw comf com_ ds='Compare; if F!=W then...'; als_fa cpfseq cmp_fw _ifne ds='Compare; if F<=W then...'; als_fa cpfsgt cmp_fw _ifle ds='Compare; if F>=W then...'; als_fa cpfslt cmp_fw _ifge ds='Decrement'; als_fda_1fw decf dec_ ds='Decrement; if !=0 then...'; als_fda_1fw decfsz dec_ _ifnz ds='Decrement; if =0 then...'; als_fda_1fw dcfsnz dec_ _ifz ds='Increment'; als_fda_1fw incf inc_ ds='Increment; if !=0 then...'; als_fda_1fw incfsz inc_ _ifnz ds='Increment; if =0 then...'; als_fda_1fw infsnz inc_ _ifz ds='Move'; als_fa movf mov_fw '' ,0 ds='Move F to same F'; als_fa movf mov_fsf '' ,1 ds='Move (flags unchanged)'; alias_f movff mov_ff f,g f,g ds='Test'; alias_f movf tst_w $w,0,0 '' w ds='Negate'; als_fa_1fw negf neg_ ds='Rotate left (through carry)'; als_fda_1fw rlcf rlc_ ds='Rotate left'; als_fda_1fw rlncf rl_ ds='Rotate right (through carry)'; als_fda_1fw rrcf rrc_ ds='Rotate right'; als_fda_1fw rrncf rr_ ds='Set all bits'; als_fa_1fw setf set_ ds='Subtract with borrow'; als_fda_2fw subfwb subb_fw ds='Subtract with borrow'; als_fda_2fw subwfb subb_wf ds='Subtract'; als_fda_2fw subwf sub_wf ds='Swap nybbles'; als_fda_1fw swapf swap_ ds='Test; if !=0 then...'; als_fa_1fw tstfsz tst_ _ifnz # `bit-oriented file register operations' (DS280) ds='Bit Clear'; als_fa_1fw bcf bc_ '' ,b ,b ds='Bit Set'; als_fa_1fw bsf bs_ '' ,b ,b ds='Bit Toggle'; als_fa_1fw btg btg_ '' ,b ,b ds='Bit Test; if 1 then...'; als_fa_1fw btfsc bt_ _if1 ,b ,b ds='Bit Test; if 0 then...'; als_fa_1fw btfss bt_ _if0 ,b ,b # `control operations' (DS281) descs_bra Carry c descs_bra Negative n descs_bra Overflow ov descs_bra Zero z ds='Branch unconditionally'; noalias bra $lab 11r ds='Call subroutine'; noalias call $lab 20 ds='Call subr., saving W,S,BSR'; alias_f call call_s $lab,1 $lab 20 ds='Clear watchdog timer'; noalias clrwdt ds='Decimal adjust'; alias_f daw da_w ds='Jump unconditionally'; noalias goto $lab 20 ds='No Operation'; noalias nop ds='Pop top of return stack'; noalias pop ds='Push PC+2 onto stack'; noalias push ds='Branch to subroutine'; noalias rcall $lab 8r ds='Reset the microcontroller'; noalias reset ds="Return, reenabling Int's"; noalias retfie ds="Return, ena.Int's, restoring W,S,BSR"; alias_f retfie retfie_r 1 ds='Return with literal in W'; noalias retlw $lit ds='Return from subroutine'; noalias return ds='Return, restoring W,S,BSR'; alias_f return return_r 1 ds='Go into standby mode'; noalias sleep # `literal operations' (DS282) ds='Subtract'; als_k_lw sublw sub ds='Move literal to BSR' alias_f movlb mov_lb $lit $lit 4 ds='Move literal to FSR' alias_f lfsr mov_lfsr i,$lit $lit,i 12,2 ds='Table Read' noalias tblrd */*+/*-/+* ds='Table Write' noalias tblwt */*+/*-/+* if $macros; then echo ' list'; fi exit 0 #--by-opcode-- PIC18F458 INSTRUCTIONS AND PROVIDED OPCODE ALIASES sorted by OPCODE/ALIAS Our opcode Args Notes Description Official ------------- ------ ----- --------------------------------------- ------- #--0-- #--by-desc-- PIC18F458 INSTRUCTIONS AND PROVIDED OPCODE ALIASES sorted by DESCRIPTION Our opcode Args Notes Description Official ------------- ------ ----- --------------------------------------- ------- #--0-- #--by-official-- PIC18F458 INSTRUCTIONS AND PROVIDED OPCODE ALIASES sorted by OFFICIAL INSN Our opcode Args Notes Description Official ------------- ------ ----- --------------------------------------- ------- #--0-- #--3-- ------------- ------ ---- --------------------------------------- ------- Notes: r Branch uses relative offset. a Uses BSR for F iff F address is not in Access Bank. There are also _a (always uses access bank) and _b (always uses BSR). (_[ab]_if for conditionals.) u Official opcode, not an alias/macro. Listed for completeness.y w Macro (alias) using WREG (the mapping of W in the Access Bank). digits Gives number of bits of address or offset. Z N C F Flags affected (out of C DC Z OV N). F: all of those affected. $Id$ #--0--