title: Bitwise Logic on a Microcontroller
body: <p>Given the short example below, is there any way to reduce the amount of registers used in the code between [x1] and [x2]?</p>
  
  <p>I read Input from PINA and generate output for PORTB according to some logic table. 
  This is the most straightforward way to do this for me, but it seems kind of roundabout. Is there a more elegant way that I am not aware of?</p>
  
  <pre><code>loop:
  ;Set Masks for Inputpins [x1]
  ldi r17, 0b00000010
  ldi r18, 0b00000100
  ;Read Input from PINA
  in r16, PINA
  ;Apply Masks and normalize
  and r17, r16
  lsl r17
  and r18, r16
  lsl r18
  lsl r18
  ;Start with actual bitwise operations e.g [x2]
  mov r16, r17
  xor r16, r18
  and r16, r17
  ...
  ...
  out PORTB, r16
  rjmp loop
  </code></pre>
  
  <p>Note that I am not as much interested in perfomance (space, speed) as in reducing the amount of mask and shift operations which introduce (sloppy / nasty) errors easily on a bigger scale.</p>
  
  <p>Also Note that I am not sure if <a href="https://codereview.stackexchange.com/">Codereview.Stackechange</a> is the more appropiate place for this question.</p>