[an error occurred while processing this directive]
И я спешу поделиться. (+)
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено adw 26 июля 2006 г. 14:12
В ответ на: Вот - дарю полезные макросы для AVR-assma. При отладке программ очень помогают (+) отправлено Assm 26 июля 2006 г. 13:51

Мне их прислал какой-то мужик, скорее всего его инициалы R.G.F., отчего и название файла такое.


;RGFMACRO.INC
;Created: 8/5/97

;Note on use of labels within Macros:
; Labels ARE allowed within macros for use in doing relative branches.
; They do not conflict with each other even with multiple invocations
; of the same macro.

;First, a complete list of all 64 macros contained herein, with usage.
;8-BIT:
; ADDI r16,$55 ;(valid: ZN) add the value $55 into r20
; ABS r0 ;(valid: ZN) give abs-value of signed 8-bit
; MUL8X8 r0,r1,r2 ;unsigned R0 * R1. R0 preserved, R2:R1 is result

;MIXED 8/16-BIT: (these require a spare high register. Valid: N.)
; ADS8_16 d_hi,d_lo,temp,src ;SIGNED add of an 8 to a 16
; SBS8_16 d_hi,d_lo,temp,src ;SIGNED subtr of an 8 from a 16

;16-BIT: (If R17:R16 specified, must use upper registers, otherwise use any.)
; LDI16 r17,r16,-4555 ;loads r17:r16 (hi,lo) w/ a constant value.
; ADD16 r1,r0,r3,r2 ;r1:r0 = r1:r0 + r3:r2. Signed or unsigned.
; ADDI16 r17,r16,$4b32 ;r17:r16 = r17:r16 + K. Signed or unsigned.
; SUB16 r1,r0,r3,r2 ;r1:r0 = r1:r0 - r3:r2. Signed or unsigned. Z valid.
; SUBI16 r17,r16,10000 ;r17:r16 = r17:r16 - K. Signed or unsigned. Z valid.
; CP16 r1,r0,r3,r2 ;compare r1:r0 w/ r3:r2. Flags same as CP opcode.
; CPI16 r17,r16,temp,0x5555 ;compare r17:r16 w/ K. Flags same as CP opcode.
; ABS16 r1,r0 ;convert r1:r0 into its absolute value.
; EXTD16 r1,r0 ;Sign-extend r0 into r1. Valid flag: N.
; NEG16 r1,r0 ;Negate (2's-complement) r1:r0. Valid flag: N
; ASR16 r1,r0 ;shift SIGNED 16-bit value down (divide by 2).
; SHFR16 r1,r0 ;Shift (hi:lo) down one bit w/ zero-fill top.
; SHFL16 r1,r0 ;Shift (hi:lo) up one bit w/ zero-fill bottom.

;POINTER OPERATIONS:
; CLRY, LDX, INCX, DECX, ADDXI, SUBXI, SHFLX, SHFRX, PUSHX, POPX
; CLRY, LDY, INCY, DECY, ADDYI, SUBYI, SHFLY, SHFRY, PUSHY, POPY
; CLRZ, LDZ, INCZ, DECZ, ADDZI, SUBZI, SHFLZ, SHFRZ, PUSHZ, POPZ

;'W' REGISTER (R25:R24) OPERATIONS:
; CLRW, LDW, INCW, DECW, ADDWI, SUBWI, SHFLW, SHFRW, PUSHW, POPW

;BRANCH OPERATIONS:
; SKIPNE, SKIPEQ, SKIPCS, SKIPCC, SKIPLO, SKIPSH, SKIPMI, SKIPPL,
; SKIPVC, SKIPVS, SKIPTS, SKIPTC, SKIPGE, SKIPLT, SKIP

;OTHER OPERATIONS:
; DOUBLENOP ;Wait two cycles in one instruction.

;Note that the ADDWI/SUBWI thru ADDZI/SUBWI are not the same as the
; native ADIW opcode. These are full 16-bit operands.

.def ZH =r31
.def ZL =r30
.def YH =r29
.def YL =r28
.def XH =r27
.def XL =r26
.def WH =r25
.def WL =r24

;***************************************************************************
.macro ADDI ;Adds an 8 bit immediate to a register
subi @0,-@1 ;subtract negative value
.endmacro

;Example -> ADDI r20,$55 ;add the value $55 to r20

;***************************************************************************
.macro ABS
sbrc @0,7 ;if bit clr, already is positive
neg @0
.endmacro

;***************************************************************************
.macro ADS8_16 ;usage: ADS8_16 dest_hi, dest_lo, temp, src
clr @2 ;sign-extend src
sbrc @3,7
ser @2
add @1,@3 ;add low bytes
adc @0,@2
.endmacro

;***************************************************************************
.macro SBS8_16 ;usage: SBS8_16 dest_hi, dest_lo, temp, src
clr @2
sbrc @3,7
ser @2
sub @1,@3 ;subtract lower bytes
sbc @0,@2
.endmacro

;***************************************************************************
.macro CP16 ;if equal, Z flag is set. If neg, C is set
cp @1,@3 ;Compare low bytes
cpc @0,@2 ;Compare high bytes w/carry propagation
.endmacro

;***************************************************************************
.macro CPI16 ;usage: CPI16 dest_hi, dest_lo, temp, src
cpi @1,low(@3) ;Compare low byte
ldi @2,high(@3) ;move hi into a temp reg, no CPCI opcode!
cpc @0,@2 ;Compare high bytes
.endmacro

;***************************************************************************
.macro PUSHW
push WH
push WL
.endmacro

;***************************************************************************
.macro POPW
pop WL
pop WH
.endmacro

;***************************************************************************
.macro PUSHX
push XH
push XL
.endmacro

;***************************************************************************
.macro POPX
pop XL
pop XH
.endmacro

;***************************************************************************
.macro PUSHY
push YH
push YL
.endmacro

;***************************************************************************
.macro POPY
pop YL
pop YH
.endmacro

;***************************************************************************
.macro PUSHZ
push ZH
push ZL
.endmacro

;***************************************************************************
.macro POPZ
pop ZL
pop ZH
.endmacro

;***************************************************************************
.macro NEG16
neg @0 ;negate hi
neg @1 ;negate low
breq ENDneg16
dec @0
ENDneg16:

; com @1 ;this variant uses high registers
; com @0 ;
; subi @1,$FF ;
; sbci @0,$FF ;
.endmacro

;***************************************************************************

.macro EXTD16
clr @0 ;clear hi byte
sbrc @1,7 ;skip if positive now
com @0 ;leave with 'N' flag valid
.endmacro

;***************************************************************************
.macro ABS16
tst @0 ;test neg flag of upper byte
brpl ENDabs16 ;if positive, exit
neg @0 ;2's-comp high byte
neg @1 ; and low byte.
breq ENDabs16 ;If low is 0, exit, else dec upper
dec @0
ENDabs16:
.endmacro

;***************************************************************************
.macro ADDI16 ;Adds a 16 bit immediate to a
;16 bit register variable
subi @1,low(-@2) ;subtract negative low byte
sbci @0,high(-@2) ;subtract negative high byte with carry
.endmacro

;Example -> ADDI16 r21,r20,$4b32 ;add the value $4b32 to r21:r20

;***************************************************************************
.macro ADD16
add @1, @3 ;Add low bytes
adc @0, @2 ;Add high bytes with carry
.endmacro

;***************************************************************************
.macro SUBI16 ;Subtracts a 16 bit immediate from
;a 16 bit register variable
subi @1,low(@2) ;Subtract low byte
sbci @0,high(@2) ;Subtract high byte with carry
.endmacro

;Example -> SUBI16 r21,r20,10000 ;subtracts 10000 from r21:r20

;***************************************************************************
.macro SUB16
sub @1,@3 ;Subtract low bytes
sbc @0,@2 ;Add high byte with carry
.endmacro

;***************************************************************************
.macro LDI16 ;Loads a 16 bit immediate to a 16 bit
;register variable
ldi @1,low(@2) ;Subtract low byte
ldi @0,high(@2) ;Subtract high byte with carry
.endmacro

;Example -> LDI16 r17,r16,-4555 ;loads r17:r16 with -4555

;***************************************************************************
.macro LDW ;Load the W-pointer with a 16 bit value
ldi WL,low(@0) ;Load low byte
ldi WH,high(@0) ;Load high byte
.endmacro

;Example -> LDW $0020 ;W points to start of user SRAM

;***************************************************************************
.macro LDX ;Load the X-pointer with a 16 bit value
ldi XL,low(@0) ;Load low byte
ldi XH,high(@0) ;Load high byte
.endmacro

;Example -> LDX $0020 ;X points to start of user SRAM

;***************************************************************************
.macro LDY ;Load the Y-pointer with a 16 bit value
ldi YL,low(@0) ;Load low byte
ldi YH,high(@0) ;Load high byte
.endmacro

;Example -> LDY $ffff ;Y points to end of external SRAM

;***************************************************************************
.macro LDZ ;Load the Z-pointer with a 16 bit value
ldi ZL,low(@0) ;Load low byte
ldi ZH,high(@0) ;Load high byte
.endmacro

;Example -> LDZ TABLE_START ;Z points to label TABLE_START

;***************************************************************************
.macro CLRW ;Clear the W-reg
clr WH ;Clear W high byte
clr WL ;Clear W low byte
.endmacro

;***************************************************************************
.macro CLRX ;Clear the X-pointer
clr XH ;Clear X-pointer high byte
clr XL ;Clear X-pointer low byte
.endmacro

;***************************************************************************
.macro CLRY ;Clear the Y-pointer
clr YH ;Clear Y-pointer high byte
clr YL ;clear Y-pointer low byte
.endmacro

;***************************************************************************
.macro CLRZ ;Clear the Z-pointer
clr YH ;Clear Z-pointer high byte
clr YL ;Clear Z-pointer low byte
.endmacro

;***************************************************************************
.macro ADDWI ;Add an immediate to the W-reg
subi WL,low(-@0) ;Add immediate low byte to WL
sbci WH,high(-@0) ;Add immediate high byte with carry to WH
.endmacro

;Example -> ADDWI 750 ;Increase W by 750

;***************************************************************************
.macro SUBWI ;Subtract an immediate from the W-reg
subi WL,low(@0) ;Subtract immediate low byte from WL
sbci WH,high(@0) ;Sub immediate high byte with carry from WH
.endmacro

;Example -> SUBWI REC_SIZE ;Decrease W by value REC_SIZE

;***************************************************************************
.macro ADDXI ;Add an immediate to the X-pointer
subi XL,low(-@0) ;Add immediate low byte to XL
sbci XH,high(-@0) ;Add immediate high byte with carry to XH
.endmacro

;Example -> ADDXI 750 ;Increase X-pointer by 750

;***************************************************************************
.macro SUBXI ;Subtract an immediate from the X-pointer
subi XL,low(@0) ;Subtract immediate low byte from XL
sbci XH,high(@0) ;Subtract immediate high byte with carry from XH
.endmacro

;Example -> SUBXI REC_SIZE ;Decrease X-pointer by value REC_SIZE

;***************************************************************************
.macro ADDYI ;Add an immediate to the Y-pointer
subi YL,low(-@0) ;Add immediate low byte to YL
sbci YH,high(-@0) ;Add immediate high byte with carry to YH
.endmacro

;***************************************************************************
.macro SUBYI ;Subtract an immediate from the Y-pointer
subi YL,low(@0) ;Subtract immediate low byte from YL
sbci YH,high(@0) ;Subtract immediate high byte with carry from YH
.endmacro

;***************************************************************************
.macro ADDZI ;Add an immediate to the Z-pointer
subi ZL,low(-@0) ;Add immediate low byte to ZL
sbci ZH,high(-@0) ;Add immediate high byte with carry to ZH
.endmacro

;***************************************************************************
.macro ADDZ8 ;Add an eight-bit register to the Z-pointer
add ZL,@0 ;Add register to ZL
.set _addz8_l0 = PC+2 ;
brcc _addz8_l0 ;
inc Zh ;Inc ZH if carry
.endmacro

;***************************************************************************
.macro SUBZI ;Subtract an immediate from the Z-pointer
subi ZL,low(@0) ;Subtract immediate low byte from ZL
sbci ZH,high(@0) ;Subtract immediate high byte with carry from ZH
.endmacro

;***************************************************************************
.macro INCW ;Increment the W-reg
adiw WL,1
.endmacro

;***************************************************************************
.macro INCX ;Increment the X-pointer
adiw XL,1
.endmacro

;***************************************************************************
.macro INCY ;Increment the Y-pointer
adiw YL,1
.endmacro

;***************************************************************************
.macro INCZ ;Increment the Z-pointer
adiw ZL,1
.endmacro

;***************************************************************************
.macro DECW ;Decrement the W-reg
subi WL,1
sbci WH,0
.endmacro

;***************************************************************************
.macro DECX ;Decrement the X-pointer
subi XL,1
sbci XH,0
.endmacro

;***************************************************************************
.macro DECY ;Decrement the Y-pointer
subi YL,1
sbci YH,0
.endmacro

;***************************************************************************
.macro DECZ ;Decrement the Z-pointer
subi ZL,1
sbci ZH,0
.endmacro

;***************************************************************************
.macro ASR16
asr @0 ;hi-byte's D7-1 down, D7 preserved, D0 to C
ror @1 ;C into bit 7, all else move down
.endmacro

;***************************************************************************
.macro SHFR16
lsr @0 ;hi-byte down, zero-fill, low bit to C
ror @1 ;C into bit 7, all else move down
.endmacro

;***************************************************************************
.macro SHFRZ
lsr ZH ;hi-byte down, zero-fill, low bit to C
ror ZL ;C into bit 7, all else move down
.endmacro

;***************************************************************************
.macro SHFRY
lsr YH ;hi-byte down, zero-fill, low bit to C
ror YL ;C into bit 7, all else move down
.endmacro


;***************************************************************************
.macro SHFRX
lsr XH ;hi-byte down, zero-fill, low bit to C
ror XL ;C into bit 7, all else move down
.endmacro

;***************************************************************************
.macro SHFRW
lsr WH ;hi-byte down, zero-fill, low bit to C
ror WL ;C into bit 7, all else move down
.endmacro

;***************************************************************************
.macro SHFL16
lsl @1 ;move low byte up one bit, zero fill, bit7->C
rol @0 ;move C into bit0, all else up one bit
.endmacro

;***************************************************************************
.macro SHFLZ
lsl ZL ;move low byte up one bit, zero fill, bit7->C
rol ZH ;move C into bit0, all else up one bit
.endmacro

;***************************************************************************
.macro SHFLY
lsl YL ;move low byte up one bit, zero fill, bit7->C
rol YH ;move C into bit0, all else up one bit
.endmacro

;***************************************************************************
.macro SHFLX
lsl XL ;move low byte up one bit, zero fill, bit7->C
rol XH ;move C into bit0, all else up one bit
.endmacro

;***************************************************************************
.macro SHFLW
lsl WL ;move low byte up one bit, zero fill, bit7->C
rol WH ;move C into bit0, all else up one bit
.endmacro

;**************************************************************************
.macro MUL8X8" - 'FAST' 8x8 Bit Unsigned Multiplication (non-looped)
;Multiplicand is in @0 register. Multiplier is @1 register. Low result
; ends up in @1 reg (overwrites multiplier), hi rslt in @2 register.
clr @2 ;clear result High byte
lsr @1 ;move bit0 to C flag

brcc skipd0 ;if no C, don't add
add @2,@0 ;add multiplicand to result High byte
skipd0: ror @2 ;shift right result High byte
ror @1 ;rotate right result L byte and multiplier

brcc skipd1
add @2,@0
skipd1: ror @2
ror @1

brcc skipd2
add @2,@0
skipd2: ror @2
ror @1

brcc skipd3
add @2,@0
skipd3: ror @2
ror @1

brcc skipd4
add @2,@0
skipd4: ror @2
ror @1

brcc skipd5
add @2,@0
skipd5: ror @2
ror @1

brcc skipd6
add @2,@0
skipd6: ror @2
ror @1

brcc skipd7
add @2,@0
skipd7: ror @2
ror @1
.endmacro

;***************************************************************************
;skip next instruction if equal to zero
.macro SKIPEQ
.set _skipeq = PC+2
breq _skipeq
.endmacro

;*****************************************************************************
;skip next instruction if not equal to zero
.macro SKIPNE
.set _skipne = PC+2
brne _skipne
.endmacro

;***************************************************************************
;skip next instruction if carry set
.macro SKIPCS
.set _skipcs = PC+2
brcs _skipcs
.endmacro

;***************************************************************************
;skip next instruction if carry clear
.macro SKIPCC
.set _skipcc = PC+2
brcc _skipcc
.endmacro

;***************************************************************************
;skip next instruction if lower
.macro SKIPLO
.set _skiplo = PC+2
brlo _skiplo
.endmacro

;***************************************************************************
;skip next instruction if same or higher
.macro SKIPSH
.set _skipsh = PC+2
brsh _skipsh
.endmacro

;***************************************************************************
;skip next instruction if minus
.macro SKIPMI
.set _skipmi = PC+2
brmi _skipmi
.endmacro

;***************************************************************************
;skip next instruction if plus
.macro SKIPPL
.set _skippl = PC+2
brpl _skippl
.endmacro

;***************************************************************************
;skip next instruction if no overflow
.macro SKIPVC
.set _skipvc = PC+2
brvc _skipvc
.endmacro

;***************************************************************************
;skip next instruction if overflow
.macro SKIPVS
.set _skipvs = PC+2
brvs _skipvs
.endmacro

;***************************************************************************
;skip next instruction if greater or equal
.macro SKIPGE
.set _skipge = PC+2
brge _skipge
.endmacro

;***************************************************************************
;skip next instruction if lower then
.macro SKIPLT
.set _skiplt = PC+2
brlt _skiplt
.endmacro

;***************************************************************************
;skip next instruction if T set
.macro SKIPTS
.set _skipts = PC+2
brts _skipts
.endmacro

;***************************************************************************
;skip next instruction if T cleared
.macro SKIPTC
.set _skiptc = PC+2
brtc _skiptc
.endmacro

;***************************************************************************
;skip next instruction unconditionally
.macro SKIP
.set _skip = PC+2
rjmp _skip
.endmacro

;***************************************************************************
;wait two cycles but waste only one instruction
.macro DOUBLENOP
.set _doublenop = PC+1
rjmp _doublenop
.endmacro


Составить ответ  |||  Конференция  |||  Архив

Ответы


Отправка ответа

Имя (обязательно): 
Пароль: 
E-mail: 

Тема (обязательно):
Сообщение:

Ссылка на URL: 
Название ссылки: 

URL изображения: 


Rambler's Top100 Рейтинг@Mail.ru
Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание