Arm/uartread

From ASMBits

Write a function to read a string (terminated with character '\n', or 0x0d) from a UART device and writes that string into memory. You will need to poll the UART device to read each character as it becomes available. Replace the \n character with a null character in the output string. Return the length of the string.

unsigned int uartgets (char *output);


You are provided a function to read the status of the UART:
unsigned int read_uart();

The 32-bit word includes information about the state of the UART and the received character, if available:

  • bit [15]: 1 if the character in bits [7:0] is valid. If valid, the character is also dequeued from the UART so that the next read will return the next character, if available. If not valid, bits [7:0] in the word are undefined. You need to poll the device to read each character in the string.
  • bits [7:0]: The character received from the UART, if there was a character available.

To make this problem easier, read_uart only clobbers r0 (the return value) (and lr, of course).


Expected solution length: Around 20 lines.

Sample Input

"Hello world"

Sample Output

r0=11

The definition of the UART device in this problem is compatible with the UART used in the Altera computer systems. In the CPUlator simulator, look for the UART device. You can test your program by focusing on (clicking on) the UART device, then typing. The sample read_uart function reads from this UART and can be used for debugging, but remove it before submitting because the judge uses a different implementation.

Write your solution here

Upload a source file...