title: ARM Cortex-M4, Read/Write using UART_DR and FIFO
body: <p>So I am learning ASM, and have an LM4F120XL ARM Cortex-M4 MCU.
  I am using Keil uVision V4.54.</p>
  
  <p>I am familiar with setting up ports etc, initialising GPIO and UART.</p>
  
  <p>What I am stuck on is reading and writing, to TeraTerm/Putty via serial, for example.</p>
  
  <p>I understand RxFE = 0, FIFO is not empty - read from it;
           and TxFF = 0, FIFO is not full - write to it..</p>
  
  <p>But after comparing and satisfying these conditions, what data am I actually writing to UART_DR, the data-register..? Is it simply a matter of loading the data-register into a register, loading the value at this address into another register, then ... im lost as im not changing bits I'm adding new data - then you'd store it from this register back into the data-register register..</p>
  
  <p>So if data exists in the data-register, then in time it will be passed out..?
  I can connect to TeraTerm using the correct COM port, adjust BAUD and PARITY settings.. But once again, if data exists in the data-register, after due cycles will it be sent automatically..?</p>
  
  <p>Also, what about reading characters from keyboard..? Or other computer peripherals.. Is it a matter of - knowing the address, loading the value into a register, then storing it into the data-register? If the Data-Register holds data, then this would need to be done non-destructively..</p>
  
  <p>Why the hell is every article on MCU coding written in C++ and not in ASM?
  Im also learning C++ but dont know why no-one uses assembly/machine code..</p>
  
  <p>;-------       </p>
  
  <p>ReadChar</p>
  
  <pre><code>    PUSH {R0, R1}
  </code></pre>
  
  <p>inloop  LDR R0, =UART_FR
          LDR R1, [R0]
          AND R1, #0x10 
          CMP R1, #0x0 
          BNE inloop</p>
  
  <pre><code>    LDR R0, =UART_DR
      LDR R1, [R0]
      ************??
      STR R1, [R0]
  
      POP {R0, R1}
  
      BX LR  
  </code></pre>
  
  <p>;-------       </p>
  
  <p>OutputChar</p>
  
  <pre><code>    PUSH {R0, R1}
  </code></pre>
  
  <p>outloop LDR R0, =UART_FR
          LDR R1, [R0]
          AND R1, #0x20
          CMP R1, #0x0 
          BNE outloop</p>
  
  <pre><code>    LDR R0, =UART_DR
      LDR R1, [R0]
      ************??
      STR R1, [R0]
  
      POP {R0, R1}
  
      BX LR
  </code></pre>
  
  <p>;-------    </p>