RegisterAddress modesIntegerAMMXFPUSPRFUSING
STOREM

STORE MASK

 mnemonic: storem  a,m,(VEA)

 short: store a selection of bytes from a into destination

 graphic:
     input a
      -----------------------------------------
      | a0 | a1 | a2 | a3 | a4 | a5 | a6 | a7 |
      -----------------------------------------
        |    |            ...              |
        |    |                             |
     logical input: destination contents
      -----------------------------------------
      | d0 | d1 | d2 | d3 | d4 | d5 | d6 | d7 |
      -----------------------------------------
        |    |            ...              |
        |    |                             |
     input m: lower 8 bit of second argument
      -----------------------------------------
      |    |    |    |    |    |    |    |  m |
      -----------------------------------------
        \___  \____________     ...         \___
            \              \                    \
      -------------- -------------     ---------------- 
      | (m&128) ?  | | (m&64) ?  | ... |  (m&1) ?     | 
      | a0 : d0    | | a1 : d1   |     |  a7 : d7     |
      -------------- -------------     ---------------- 
         ___/  ____________/         ...     ___/
	|     /                             /
      -----------------------------------------
      | d0 | d1 | d2 | d3 | d4 | d5 | d6 | d7 |
      -----------------------------------------


 equivalent C Code:
   int i;
   unsigned char a[8];
   unsigned char m;
   unsigned char d[8];

   for( i = 0 ; i<8 ; i++ )
   {
	d[i] = ( m & (1<<(7-i)) ) ? a[i] : d[i];
   }


 typical application cases:

  It is usual in SIMD that you can write only the native amount of bytes at once.
  This instruction enables selective overwriting of memory, based on the contents
  of the mask register (lower 8 Bit).

  This instruction has several uses. Perhaps the most prominent application is for
  cookie-cut: selective writing of pixels from sprites to the screen. 

 examples:
  move.b #$ff,d0
  storem E0,d0,(a0)	;this example is the same as store E0,(a0)
  move.b #$f0,d0
  storem E0,d0,8(a0)     ;overwrite 4 bytes from 8(a0) with upper 32 bit of E0

  ; one way of color key (see also storeilm)
  pcmpeqw.w #$f81f,E0,E2 ;magenta HiColor RGB565 pixel(s) in E0 ?
  c2p       e2,e2        ;re-order: get bits from word mask into one byte
  peor.w    #$ffff,e2,e2 ;negate mask (logical: !magenta)
  storem    E0,E2,(a0)   ;store only words where the magenta check didn't match