Autres articles / Other articles

Assembly words for FlashForth

published: 30 March 2021 / updated 1 April 2021

Lire cette page en français

 


FlashForth assembler for Atmega is available in this file asm.fr

Conditions for structured flow control

Control structures in assembler use a control condition marked cc and matches one of these instructions:

cs,    \ carry set ( -- cc ) 
eq,    \ zero ( -- cc ) 
hs,    \ half carry set ( -- cc ) 
ie,    \ interrupt enabled ( -- cc ) 
lo,    \ lower ( -- cc ) 
lt,    \ less than ( -- cc ) 
mi,    \ negative ( -- cc ) 
ts,    \ T flag set ( -- cc ) 
vs,    \ no overflow ( -- cc ) 
not,   \ invert condition ( cc -- not-cc ) 

Example:

\ Increment 24 bit value until result is zero 
: testuntil 
  [ #16 #0 ldi, ] 
  [ #17 #0 ldi, ] 
  [ #18 #1 ldi, ] 
  [ begin, ] 
  [   #16 #6 add, ] \ R6 contains 1 
  [   #17 #5 adc, ] \ R5 contains 0 
  [   #18 #5 adc, ] 
  [ eq, until, ]    \ until R18 is zero 
; 

Assembler words for AVR8

For the ATmega instructions

adc,    \ Rd Rr -- 
add,    \ Rd Rr -- 
adiw,   \ Rw k6 --  \ 3 3F adiw, ZLH=ZLH+#3F 
and,    \ Rd Rr -- 
andi,   \ Rd k -- 
asr,    \ Rd -- 
bclr,   \ Rd -- 
bld,    \ Rd b -- 
break,  \ -- 
bset,   \ Rd -- 
bst,    \ Rd b -- 
call,   \ k16 k6 --  \ k6=0 for 16b addr 
cbi,    \ P b -- 
cbr,    \ Rd k -- 
clc,    \ -- 
clh,    \ -- 
cli,    \ -- 
cln,    \ -- 
clr,    \ Rd -- 
cls,    \ -- 
clt,    \ -- 
clv,    \ -- 
clz,    \ --  
com,    \ Rd -- 
cp,     \ Rd Rr -- 
cpc,    \ Rd Rr -- 
cpi,    \ Rd k -- 
cpse,   \ Rd Rr -- 
dec,    \ Rd -- 
eijmp,  \ -- 
eicall, \ -- 
elpm,   \ Rd Rr --      \ Rr={Z,Z+} 
eor,    \ Rd Rr -- 
fmul,   \ Rd Rr -- 
fmuls,  \ Rd Rr -- 
fmulsu, \ Rd Rr -- 
icall,  \ -- 
ijmp,   \ -- 
inc,    \ Rd -- 
inn,    \ Rd P -- 
jmp,    \ k16 k6 --  \ k6=0 for 16b addr 
ld,     \ Rd Rr -- 
ldd,    \ Rd Rr q -- 
ldi, 
lds,    \ Rd k16 -- 
lpm,    \ Rd Rr --      \ Rr={Z,Z+}, 2 Z+ lpm, 
lsl,    \ Rd -- 
lsr,    \ Rd -- 
mov,    \ Rd Rr -- 
mul,    \ Rd Rr -- 
muls,   \ Rd Rr -- 
mulsu,  \ Rd Rr -- 
neg,    \ Rd -- 
nop,    \ -- 
or,     \ Rd Rr -- 
ori,    \ Rd k -- 
out,    \ Rr P -- 
ovw,    \ Rd Rr -- 
pop,    \ Rd -- 
push,   \ Rd -- 
rcall,  \ k12 -- 
ret,    \ -- 
reti,   \ -- 
rjmp,   \ k12 --  
rol,    \ Rd -- 
ror,    \ Rd -- 
sleep,  \ -- 
sbc,    \ Rd Rr -- 
sbci,   \ Rd k -- 
sbi,    \ P b -- 
sbic,   \ P b -- 
sbis,   \ P b -- 
sbiw, 
sbr,    \ Rd k -- 
sbrc,   \ Rd b -- 
sbrs,   \ Rd b -- 
sec,    \ -- 
seh,    \ -- 
sei,    \ -- 
sen,    \ -- 
ser,    \ Rd -- 
ses,    \ -- 
set,    \ -- 
sev,    \ -- 
sez,    \ -- 
st,     \ Rr Rd --      \ Rd={Z+,-Z,Y+,-Y,X+,-X,X,Y,Z} 
std,    \ Rr Rd q -- 
sts,    \ k16 Rd --     \ FFFF 2 sts, adr(FFFF)<--R2 
sub,    \ Rd Rr -- 
subi,   \ Rd k -- 
swap,   \ Rd -- 
tst,    \ Rd -- 
wdr,    \ -- 

Les registres

R0 
R1 
R2 
R3 
R4 
R5 
R6 
R7 
R8 
R9 
R10 
R11 
R12 
R13 
R14 
R15 
R16 
R17 
R18 
R19 
R20 
R21 
R22 
R23 
R24 
R25 
R26 
R27 
R28 
R29 
R30 
R31 
 
XL 
XH 
YL 
YH 
ZL 
ZH 
XH:XL   
YH:YL 
ZH:ZL