ARM Assembly String read and output subroutine

0

so I created two subroutines called read_character and output_character which just basically outputs whatever you type on screen on PuTTy through the uART. These two subroutines go on looping continuously to show on screen whatever you type. Basically input and output.

I need help creating two more subroutines called read_string and output_string , which would make use of the above two functions (read_character and output_character), to display a string after a user types it. As in once the user types the string and hits ENTER, my display should return the string back to the user.

The following are the subroutines I created:

U0LSR EQU 0x14          ; UART0 Line Status Register
register EQU 0xE000C000

read_character
        LDR r0, =0xE000C014                            ;load the flag register to r0
        LDRB r1, [r0]                                  ;load byte from r0 to r1
        BIC r1, r1, #0xFFFFFFFE                        ; bit clear and keep the first bit to check RDR
        CMP r1, #0                                     ;compare to 0
        BEQ read_character                             ;if 0 go back to read_character
        LDR r6, =register                              ;if not 0, then continue and save what is in 0xE000C000 in r6
        LDR r2, [r6]

        ;if 1 => read the byte from recieve register
        ;stop

    output_character
        LDR r0, =0xE000C014                             ;load the flag register to r0
        LDRB r1, [r0]                                   ;load the byte
        BIC r1, r1, #0xFFFFFFDF                         ;bit clear and keep the 5th bit, which is the THRE bit
        MOV r1, r1, LSR #4                              ;right shift to set the fifth bit as first
        CMP r1, #0                                      ;compare to 0
        BEQ output_character
        LDR r6, =register
        STR r2, [r6]
        B read_character                                 ;branch back to read_character to read and transmit next character

        LDMFD sp!, {lr}
        BX lr
string
assembly
input
arm
output
asked on Stack Overflow Feb 28, 2014 by user3353118

1 Answer

0

I am guessing your current program is a simple infinite loop of just taking the input character and placing it on the output FIFO for the UART.

What you want to do with your new program will require a couple of things.

read_character needs to loop itself until ENTER is detected. Look at an ASCII table for how ENTER is encoded.

Also, read_character now has to store its data somewhere until the ENTER key is pressed. A possible way to do this would be to write to a specific memory location, incrementing each write. How do you choose such a memory location? What are the requirements for that location?

However, you now need a way to communicate to output_character either the end of the list of characters or a count of how many characters you have received.

  • End of a list of characters - think about how C does this (or look it up). What does your program need to do to follow this method?
  • Count of how many characters received - How else can you use this number? It's more than just a count of how many you have received, it could also represent a pointer offset to the current empty byte. How could that be used in your program?

When should you break out of the loop and proceed to output_character? What side-effects will that have?

output_character will need to be modified to read from the scratch pad location one character and advance one byte, until it either hits the end of the list, or you have sent a number of characters equal to your received count. How can you easily do that? Look at ARM addressing modes for hints.

Looping back to read_character, what values need to be reset, and why?

answered on Stack Overflow Mar 4, 2014 by Rich Hendricks

User contributions licensed under CC BY-SA 3.0