\ armasm.part2 of 4 v1.0

public:

HEX

\ various utility words for dealing 
\ with many doubles:

: D<>  D= 0=  ;

: 2NIP  2SWAP 2DROP  ;

: -ROT  ROT ROT  ;
: -2ROT  2ROT 2ROT ;  

: 3DUP  DUP 2OVER ROT ;

: UD<  ( u1. u2. -- flag ) 
  ROT SWAP 2DUP U< >R
  = -ROT U< AND R> OR ;

: UD>  ROT SWAP 2DUP U> >R
  = -ROT U> AND R> OR  ;

: UD. <# #S #> type space ;

: CODE, ( d. -- )  DSWAPENDS , , ; 

: >-<  SWAP - ;

: DLROTATE ( d n -- d )  3DUP DLSHIFT 
  2>R 20 >-< DRSHIFT 2R> DOR ;

: DRROTATE ( d n -- d )  3DUP DRSHIFT
   2>R 20 >-< DLSHIFT 2R> DOR ;

: BITCOUNT ( x -- #1s )   0 SWAP
   BEGIN  ?DUP WHILE  DUP 1- AND
   SWAP 1+ SWAP  REPEAT ;

: DBITCOUNT ( D. -- #1s ) 
  BITCOUNT SWAP BITCOUNT + ;

: ?INVERT ( x1. -- x2. f )  2DUP 
  DBITCOUNT 10 > DUP >R IF DINVERT  
  THEN R> ;

private:

\ holds the instruction being built up
2VARIABLE INST_MS
INST_MS  1 CELLS +
  CONSTANT INST_LS 

: INSTOR!   
  INST_MS TUCK @ OR SWAP ! 
  INST_LS TUCK @ OR SWAP ! ; 

\ Condition codes

: COND  CREATE , 
  DOES> @ 0C LSHIFT INST_MS @
  0FFF AND OR  INST_MS ! ; 

: CONDS  0F 0 DO  I COND   LOOP ;

public:

CONDS  EQ NE CS CC MI PL VS VC HI LS GE LT GT LE AL
3 COND LO  
2 COND HS

: REVERSE  INST_MS @ 1000 
  XOR  INST_MS ! ;

\ (re)initialise assembler:
: RESET   0. INST_MS 2!  AL ;   

private:

\ Registers

: REGS  10 0 DO  
  I 0 2CONSTANT  LOOP ; 

public:

REGS R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15
   R15 2CONSTANT PC 
   R14 2CONSTANT LR
   R13 2CONSTANT SP