Please complete the char_out and char_in functions in this assembly code. When w
ID: 3826229 • Letter: P
Question
Please complete the char_out and char_in functions in this assembly code.
When writing the char_out and char_in routines, only use registers R0 to R3 and R12 as using any other registers requires the values to be saved and restored in the function. The char_out and char_in routines should implement the logic shown in Figure 27 below. Note that the char_in routine needs to verify that the OR, NF, FE and PF bits are not set. If they are set, they can be cleared by writing a one to the specific bit location or by simply writing 0x0F to clear any that are set.
SIM_SOPT2 EQU 0x40048004
SIM_SCGC4 EQU 0x40048034
SIM_SCGC5 EQU 0x40048038
PORTA_PCR1 EQU 0x40049000 + 4 * 1
PORTA_PCR2 EQU 0x40049000 + 4 * 2
PORTE_PCR20 EQU 0x4004D000 + 4 * 20
PORTE_PCR21 EQU 0x4004D000 + 4 * 21
UART0_BDH EQU 0x4006A000
UART0_BDL EQU 0x4006A001
UART0_C1 EQU 0x4006A002
UART0_C2 EQU 0x4006A003
UART0_S1 EQU 0x4006A004
UART0_S2 EQU 0x4006A005
UART0_C3 EQU 0x4006A006
UART0_D EQU 0x4006A007
UART0_MA1 EQU 0x4006A008
UART0_MA2 EQU 0x4006A009
UART0_C4 EQU 0x4006A00A
UART0_C5 EQU 0x4006A00B
AREA asm_area, CODE, READONLY
EXPORT asm_main
EXPORT UART0Init
EXPORT char_in
EXPORT char_out
asm_main FUNCTION ;assembly entry point for C function
; Add program code here
BL UART0Init
loop
BL char_in ; read char from UART, char in R0
BL char_out ; send char in R0 to UART
b loop
ENDFUNC
; When char_out is called, R0 contains
; the char to be sent out the UART
char_out FUNCTION
BX LR
ENDFUNC
; When char_in returns, R0 contains
; the char that was received
char_in FUNCTION
BX LR
ENDFUNC
UART0Init FUNCTION
; SIM_SOPT2[UART0SRC] = 01b (MCGFLLCLK or MCGPLLCLK/2 clock)
; and SIM_SOPT2[PLLFLLSEL] = 1b for MGCPLLCLK/2
LDR R0,=SIM_SOPT2 ;Load address of SIM_SOPT2 to R0
LDR R1,[R0] ;Put present value of SIM_SOPT2 into
R1
LDR R2,=0xF3FEFFFF ;Load bits to clear
ANDS R1,R2 ;AND values to clear bits
LDR R2,=0x04010000 ;Load bits to set
ORRS R1,R2 ;OR values to set bits
STR R1,[R0] ;Put value back into SIM_SOPT2
; SIM_SCGC4[UART0] = 1
LDR R0,=SIM_SCGC4
LDR R1,[R0]
LDR R2,=0x00000400
ORRS R1,R2
STR R1,[R0]
; SIM_SCGC5[PORTE thru A] = 1, turn on clock for all ports
LDR R0,=SIM_SCGC5 ;Load address of SIM_SCGC5 to R0
LDR R1,[R0] ;Put value of SIM_SCGC5 into R1
LDR R2,=0x00003E00 ;Load value to turn on all port
;clocks into R2
ORRS R1,R2 ;OR R2 into R1
STR R1,[R0] ;Put value back into SIM_SCGC5
; PORTA_PCR1 , Clear ISF and set MUX = 2
LDR R0,=PORTA_PCR1
LDR R1,[R0]
LDR R2,=0x01000200
ORRS R1,R2
STR R1,[R0]
; PORTA_PCR2 , Clear ISF and set MUX = 2
LDR R0,=PORTA_PCR2
LDR R1,[R0]
LDR R2,=0x01000200
ORRS R1,R2
STR R1,[R0]
; UART0_C4[OSR]= 0x07 (for osr = x8)
LDR R0,=UART0_C4
MOVS R1,#0x07
STRB R1,[R0]
; 9600 baud
; uart0_baud_clk = MGCPLLCLK/2 = 96MHz/2 = 48MHz
; SBR = uart0_baud_clk/(baud*osr)
; SBR = 48MHz/(9600 * 8)
; SBR = 625 = (0x0271)
; UART0_BDH = 0x02
LDR R0,=UART0_BDH
MOVS R1,#0x02
STRB R1,[R0]
; UART0_BDL = 0x71
LDR R0,=UART0_BDL
MOVS R1,#0x71
STRB R1,[R0]
; UART0_C2 = 0x02 (TE and RE = 1)
LDR R0,=UART0_C2
MOVS R1,#0x0C
STRB R1,[R0]
BX LR
ENDFUNC
; Put constants here
AREA data_area, DATA, READWRITE
; Put variables here
END
No char out char in (char in RO) Read Read UARTO S1 UARTO S1 Write 0x0F to UARTO S1 Yes Does OR or NF or FE or PFa 1 No No Does Does RDRF 1 TDRE 1 Yes Yes Write RO to Read UARTO D To RO UARTO D Return Return (char in RO) Figure 27 char out and char in diagramsExplanation / Answer
UART0Init FUNCTION
; SIM_SOPT2[UART0SRC] = 01b (MCGFLLCLK or MCGPLLCLK/2 clock)
; and SIM_SOPT2[PLLFLLSEL] = 1b for MGCPLLCLK/2
LDR R0,=SIM_SOPT2 ;Load address of SIM_SOPT2 to R0
LDR R1,[R0] ;Put present value of SIM_SOPT2 into
R1
LDR R2,=0xF3FEFFFF ;Load bits to clear
ANDS R1,R2 ;AND values to clear bits
LDR R2,=0x04010000 ;Load bits to set
ORRS R1,R2 ;OR values to set bits
STR R1,[R0] ;Put value back into SIM_SOPT2
; SIM_SCGC4[UART0] = 1
LDR R0,=SIM_SCGC4
LDR R1,[R0]
LDR R2,=0x00000400
ORRS R1,R2
STR R1,[R0]
; SIM_SCGC5[PORTE thru A] = 1, turn on clock for all ports
LDR R0,=SIM_SCGC5 ;Load address of SIM_SCGC5 to R0
LDR R1,[R0] ;Put value of SIM_SCGC5 into R1
LDR R2,=0x00003E00 ;Load value to turn on all port
;clocks into R2
ORRS R1,R2 ;OR R2 into R1
STR R1,[R0] ;Put value back into SIM_SCGC5
; PORTA_PCR1 , Clear ISF and set MUX = 2
LDR R0,=PORTA_PCR1
LDR R1,[R0]
LDR R2,=0x01000200
ORRS R1,R2
STR R1,[R0]
;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.