ARM Assembly Language uART0 Input Output, What am I doing wrong.

不想你离开。 提交于 2019-12-29 09:34:10

问题


Write two (2) ARM assembly language subroutines, called output_char and read_char. These subroutines will allow a user to enter a character and display the character in PuTTy via the UART. All user input should be echoed back to the display

I tried writing the code but it did not work.

U0LSR EQU 0x14          
register EQU 0xE000C000


    STMFD SP!,{lr}  

read_character
    LDR r0, =0xE000C014
    LDRB r1, [r0]
    BIC r1, r1, #0xFFFFFFFE
    CMP r1, #0
    BEQ read_character
    LDR r6, =register
    LDR r2, [r6]



output_character
    LDR r0, =0xE000C014
    LDRB r1, [r0]
    BIC  r1, r1, #0xFFFFFFEF
    MOV r1, r1, LSR #1
    CMP r1, #0
    BEQ output_character
    LDR r6, =register
    STR r2, [r6]

    LDMFD sp!, {lr}
    BX lr

回答1:


This looks like it is related

http://csserver.evansville.edu/~blandfor/EE311/ARMLecture/UARTNotes.pdf

Considering these are supposed to be two separate functions, the previous comments above apply. Also, I will assume since the problem does not refer to initializing the UART, that it does work successfully otherwise. The STMFD/LDMFD/BX triplex should be associated with both functions. Also, considering the ARM procedure call standard

http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf

you probably should limit yourself to R0-R3 in your procedures, if possible. If you need more, you need to add them to the STMFD/LDMFD instructions so you don't modify registers without returning them to their previous state.

The way the problem statement is written, the read_char function needs to call the write_char function to echo the character typed back to the screen. That is missing in your answer. It looks like the register holding the character is the same as the register sending the character, so that's good. Otherwise the read_character function looks OK.

Your write_character function doesn't look quite correct however, your BIC 0xFFFF FFEF doesn't look right. You want to be looking at the Transmitter Empty bit, you should be using 0xFFFF FFBF. As a point of style, I would recommend using AND with the bit set you want versus BIC and the inverse. Makes it easier to see. If you aren't seeing anything on your output, this is most likely the problem since the BI (break indicator) bit at LSR[4] is probably never going high, so your code is looping forever.

Lastly, the problem statement says to use read_char and output_char as your function names, so you need to add those labels to the STMFD instructions for each. Your BEQ is fine, it needs to loop back to the register read from the line status register, so it needs a separate target label.



来源:https://stackoverflow.com/questions/22026734/arm-assembly-language-uart0-input-output-what-am-i-doing-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!