Question: solve 1 and 2 with arm assembly ( not pseudocode or C ) : GLOBAL _ _ main AREA main, CODE, READONLY EXPORT _ _

solve 1 and 2 with arm assembly (not pseudocode or C):
GLOBAL __main
AREA main, CODE, READONLY
EXPORT __main
EXPORT __use_two_region_memory
__use_two_region_memory EQU 0
EXPORT SystemInit
EXPORT virtual_gpio_in
EXPORT virtual_gpio_out
ENTRY
GET BOARD.S
io_delay EQU 3
io_len_1 EQU 256
; System Init routine
SystemInit
BX LR
;
__main
;
LDR R0,=io_data_1
LDR R1,=virtual_gpio_in
LDR R2,=virtual_gpio_out
LDR R3,=0x8
LDR R4,=io_delay
LDR R5,=io_len_1
BL edge_detector_reset
playback_loop_1
LDR R6,[R0], #4
STR R6,[R1]
PUSH {R0-R6}
;
BL edge_detector
;
POP {R0-R6}
BL delay
SUBS R5, #1
BNE playback_loop_1
;
MOV R6, #0
LDR R5,=20
fill_01s
STR R6,[R1]
EOR R6, #0xffffffff
SUBS R5, #1
BNE fill_01s
MOV R6, #0
STR R6,[R1]
LDR R0,=io_data_1
LDR R3,=0x200
LDR R5,=io_len_1
BL edge_detector_reset
playback_loop_2
LDR R6,[R0], #4
STR R6,[R1]
PUSH {R0-R6}
;
BL edge_detector
;
POP {R0-R6}
BL delay
SUBS R5, #1
BNE playback_loop_2
;
; Test 'calc_pllcfg'
;
; Next 2 inputs must return R0=-1 and R1=0(wrong input parameter)
;
LDR R1,=10000000
BL calc_pllcfg
;
LDR R1,=200000000
BL calc_pllcfg
;
; Calculate M and P to run PLL at 36 MHz. Using PLLCFG_MSEL_xxx and PLLCFG_PSEL_xxx constants
; store P and M into R2.
; Use this number to check the output (R0) of your function.
;
; LDR R2,=(PLLCFG_MSEL_?:OR:PLLCFG_PSEL_?)
;
;
; For all 3 examples below, resulting actual CLK (R1) must be 36000000
;
LDR R1,=36000000
BL calc_pllcfg
;
LDR R1,=37000000
BL calc_pllcfg
;
LDR R1,=35000000
BL calc_pllcfg
;
; Calculate M and P to run PLL at 120 MHz. Using PLLCFG_MSEL_xxx and PLLCFG_PSEL_xxx constants
; store P and M into R2.
; Use this number to check the output (R0) of your function.
;
; LDR R2,=(PLLCFG_MSEL_?:OR:PLLCFG_PSEL_?)
;
;
; For the example below, resulting actual CLK (R1) must be 120000000
;
LDR R1,=120000000
BL calc_pllcfg
;
stop
B stop ; Loop forever!
delay
PUSH {R4, LR}
TEQ R4, #0
delay_loop
POPEQ {R4, PC}
SUBS R4, #1
B delay_loop
;
; 1. Edge detector. Write a function that outputs a short pulse on bit 7 of "virtual_gpio_out" when
; rising edge is detected on one of bit of "virtual_gpio_in". The bit to detect the rising edge
; (bit mask) is passed via R3. The 'rising edge' is changing bit from '0' to '1'.
;
; Parameters:
; R1- Address of "virtual_gpio_in"
; R2- Address of "virtual_gpio_out"
; R3- bit mask. The bit the 'rising edge' conditions should be detected for.
;
; Output:
; Bit 7 if "virtual_gpio_out" should be set to '1' when 'rising edge' is detected,
; Bit 7 should be '0' for all other conditions (falling edge, stable '1' or stable '0').
;
edge_detector
PUSH {LR} ; You may need to modify this command
; -- Instructions of your function is here
POP {PC} ; You may need to modify this command
;
; 1a. You may need one additional function to reset the 'edge detector'.
;
edge_detector_reset
PUSH {LR} ; You may need to modify this command
; -- Instructions of your function is here
POP {PC} ; You may need to modify this command
;
; 2. Write a function that calculates the PLLCFG register values (P and M PLL parameters)
; for a given PLL output frequency.
;
; Input clock Frequency -12 MHz (or 12000000 Hz)
;
; Valid values for the PLL frequency are 12 MHz -120 MHz. The function must check the
; validity of the required frequency.
;
; If the preset frequency cannot be obtained, the function must set the nearest possible
; PLL frequency.
;
; Parameters:
;
; R0= Output: PLLCFG value or -1(0xFFFFFFFF) if required output frequency is not correct.
; R1- Input: Required output PLL clock rate in Hz.(So,36000000 is 36 MHz)
; Output: Actual clock rate or 0 if required output frequency is not correct.
;
; Preserve the values of any registers you are using in your function.
;
calc_pllcfg
;
; 12MHz -120MHz
;
; R0= Output : PLLCFG value (-1(0xFFFFFFFF) if input is not correct)
; R1- Input - required clock rate, Output = actual clock rate. (0 if input is not correct)
;
; R2- constant 120MHz,12MHz,156 MHz
; R3- M
; R4- CLK %12 MHz, P*2
; R5- constant 6MHz,320 MHz
; R6- working (CLK *2* P)
;
; -- Put your instructions here...
stop_no_function
B stop_no_function ; Loop forever!
ALIGN
LTORG
io_data_1
DCD 38456,38456,38456,38456,38456,38456,38456,38456,38456,5031
DCD 5031,5031,5031,5031,5031,5031,5031,5031,45661,45661
DCD 45661,45661,45661,45661,45661,45661,45661,45661,45661,45661
DCD 45661,45661,45661,45661,45661,45661,45661,45661,24865,24865
DCD 24865,24865,24865,24865,24865,24865,24865,24865,24865,13349

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!