📄 cruntime.s90
字号:
;************************************************************
; CRUN.S90
;
; Initial run time library for sccavr.
;
; Rev 1 compiler C support only
; Rev 2 all labels use underscore
; Rev 3 allowed 16-bit structure sizes
;
;
;
; Ron Kreymborg
;************************************************************
;------------------------------------------------------------
module add_l
rseg scode
public _add_l
; Long add primary = primary + secondary
_add_l add r26,r22
adc r27,r23
adc r30,r24
adc r31,r25
ret
endmod
;------------------------------------------------------------
module sub_l
rseg scode
public _sub_l
; Long subtract - primary = secondary - primary
_sub_l sub r22,r26
sbc r23,r27
sbc r24,r30
sbc r25,r31
mov r31,r25
mov r30,r24
mov r27,r23
mov r26,r22
ret
endmod
;------------------------------------------------------------
module sub_i
rseg scode
public _sub_i
; Integer subtract primary = secondary - primary
_sub_i sub r26,r30
sbc r27,r31
mov r31,r27
mov r30,r26
ret
endmod
;------------------------------------------------------------
module loadc_i
rseg scode
public _loadc_i
; Load a constant integer
_loadc_i
lpm
mov r1,r0
adiw r30,1
lpm
mov r31,r0
mov r30,r1
ret
endmod
;------------------------------------------------------------
module loadc_l
rseg scode
public _loadc_l
; Load a constant long
_loadc_l
adiw r30,3
lpm
mov r26,r0
sbiw r30,1
lpm
mov r27,r0
sbiw r30,1
lpm
mov r1,r0
sbiw r30,1
lpm
mov r31,r0
mov r30,r1
ret
endmod
;------------------------------------------------------------
module push_l
rseg scode
public _push_l
; Push a long primary
_push_l
st -y,r26
st -y,r27
st -y,r30
st -y,r31
ret
endmod
;------------------------------------------------------------
module pop_l
rseg scode
public _pop_l
; Pop TOS into long secondary register
_pop_l ld r25,y+
ld r24,y+
ld r23,y+
ld r22,y+
ret
endmod
;------------------------------------------------------------
module pop_l_p
rseg scode
public _pop_l_p
; Pop TOS into long primary register
_pop_l_p
ld r31,y+
ld r30,y+
ld r27,y+
ld r26,y+
ret
endmod
;------------------------------------------------------------
module glpp
rseg scode
public _glpp
; Fetch long through Y
_glpp ldd r26,z+3
ldd r27,z+2
ldd r20,z+1
ldd r31,z+0
mov r30,r20
ret
endmod
;------------------------------------------------------------
module putstk_i_z
rseg scode
public _putstk_i_z
; Store from int primary to TOS via int secondary
_putstk_i_z
ld r27,y+
ld r26,y+
st x+,r31
st x+,r30
ret
endmod
;------------------------------------------------------------
module putstk_i_x
rseg scode
public _putstk_i_x
; Store from int primary to TOS via int secondary
_putstk_i_x
ld r31,y+
ld r30,y+
st z+,r27
st z+,r26
ret
endmod
;------------------------------------------------------------
module putstk_l
rseg scode
public _putstk_l
; Store from long primary to TOS via int secondary
_putstk_l
mov r21,r27
mov r20,r26
ld r27,y+
ld r26,y+
st x+,r31
st x+,r30
st x+,r21
st x+,r20
mov r26,r20
mov r27,r21
ret
endmod
;------------------------------------------------------------
module structoffset
rseg scode
public _structoffset
; Compute a structure offset. Enter with structure size in r25,r26,
; structure base address in X, and any structure index in Z.
; Returns destination address in Z.
_structoffset
tst r30 ; check Z is non-zero
brne _str1
tst r31
breq _str3
_str1 push r25 ; save structure size
push r24 ; lsb
mov r24,r30 ; index to r25,r24
mov r25,r31
pop r30 ; size to r31,r30
pop r31
mov r22,r30
mov r23,r31
_str2 sbiw r24,1 ; decrement index
breq _str3 ; done
add r30,r22 ; step to next entry
adc r31,r23
rjmp _str2
_str3 add r30,r26 ; add entire offset to base
adc r31,r27
ret ; offset in Z
endmod
;------------------------------------------------------------
module sextx
rseg scode
public _sextx
; Sign extend a char in X
_sextx
clr r27
sbrc r26,7
dec r27
ret
endmod
;------------------------------------------------------------
module sextz
rseg scode
public _sextz
; Sign extend a char in Z
_sextz
clr r31
sbrc r30,7
dec r31
ret
endmod
;------------------------------------------------------------
module intlong_ext
rseg scode
public _intlong_ext
; Sign extend an int in X
_intlong_ext
clr r30
clr r31
sbrs r27,7
ret
sbiw r30,1
ret
endmod
;------------------------------------------------------------
module charlong_ext
rseg scode
public _charlong_ext
; Sign extend a char in X
_charlong_ext
clr r27
clr r30
clr r31
sbrs r26,7
ret
subi r27,1
sbiw r30,1
ret
endmod
;------------------------------------------------------------
module uintlong_ext
rseg scode
public _uintlong_ext
; extend an int in X
_uintlong_ext
clr r30
clr r31
ret
endmod
;------------------------------------------------------------
module ucharlong_ext
rseg scode
public _ucharlong_ext
; extend a char in X
_ucharlong_ext
clr r27
clr r30
clr r31
ret
endmod
;------------------------------------------------------------
module bool
rseg scode
public _bool,_bool_l
; Convert primary to boolean 0 if 0, 1 otherwise
_bool_l
or r31,r26
or r31,r27
_bool or r31,r30
breq _bool1
clr r30
rjmp _bool2
_bool1 ldi r30,1
_bool2 clr r31
ret
endmod
;------------------------------------------------------------
module neg
rseg scode
public _neg
; Negate primary
_neg: com r30
com r31
adiw r30,1
ret
endmod
;------------------------------------------------------------
module neg_l
rseg scode
public _neg_l
extern _com_l
; Negate long primary
_neg_l rcall _com_l
adiw r26,1
brcc _neg_l1
adiw r30,1
_neg_l1 ret
endmod
;------------------------------------------------------------
module com
rseg scode
public _com,_com_l
; Complement primary
_com_l com r26
com r27
_com com r30
com r31
ret
endmod
;------------------------------------------------------------
module ortr
rseg scode
public _or
; OR primary with secondary
_or or r30,r26
or r31,r27
ret
endmod
;------------------------------------------------------------
module or_l
rseg scode
public _or_l
; long OR primary with secondary
_or_l or r26,r22
or r27,r23
or r30,r24
or r31,r25
ret
endmod
;------------------------------------------------------------
module xor
rseg scode
public _xor
; XOR primary with secondary
_xor eor r30,r26
eor r31,r27
ret
endmod
;------------------------------------------------------------
module xor_l
rseg scode
public _xor_l
; long OR primary with secondary
_xor_l eor r26,r22
eor r27,r23
eor r30,r24
eor r31,r25
ret
endmod
;------------------------------------------------------------
module andtr
rseg scode
public _and
; AND primary with secondary
_and and r30,r26
and r31,r27
ret
endmod
;------------------------------------------------------------
module and_l
rseg scode
public _and_l
; AND primary with secondary
_and_l and r26,r22
and r27,r23
and r30,r24
and r31,r25
ret
endmod
;------------------------------------------------------------
module lsr
rseg scode
public _lsr
; Logical shift right secondary times by primary
_lsr cp r31,r30
brne _lsr1
ret
_lsr1 lsr r27
ror r26
sbiw r30,1
rjmp _lsr
endmod
;------------------------------------------------------------
module lsr_l
rseg scode
public _lsr_l
; Logical shift right long secondary times by primary
_lsr_l cp r25,r24
brne _lsrl1
ret
_lsrl1 lsr r31
ror r30
ror r27
ror r26
sbiw r24,1
rjmp _lsr_l
endmod
;------------------------------------------------------------
module lsl
rseg scode
public _lsl
; Logical shift left secondary times by primary
_lsl cp r31,r30
brne _lsl1
ret
_lsl1 lsl r26
rol r27
sbiw r30,1
rjmp _lsl
endmod
;------------------------------------------------------------
module asl_l
rseg scode
public _asl_l
; Logical shift left long secondary times by primary
_asl_l cp r25,r24
brne _asll1
ret
_asll1 lsl r26
rol r27
rol r30
rol r31
sbiw r24,1
rjmp _asl_l
endmod
;------------------------------------------------------------
module lneg
rseg scode
public _lneg
_lneg or r30,r31
breq _lneg1
clr r30
clr r31
ret
_lneg1 inc r30
ret
endmod
;------------------------------------------------------------
; Integer conditionals
module conditionals
rseg scode
extern ?cmp,_true,_false
public _ne,_eq,_lt,_le,_gt,_ge
; Integer not equal
_ne rcall ?cmp
brne _true
rjmp _false
; Integer equal
_eq rcall ?cmp
breq _true
rjmp _false
; Integer less than
_lt rcall ?cmp
brcc _false
rjmp _true
; Integer less than or equal
_le rcall ?cmp
brcs _true
breq _true
rjmp _false
; Integer greater than
_gt rcall ?cmp
brmi _false
rjmp _true
; Integer greater than or equal
_ge rcall ?cmp
brge _true
rjmp _false
endmod
;------------------------------------------------------------
module uconditionals
rseg scode
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -