//file: LEDR.s //author: .include \"macros.inc\" SET_TARGET .text FUNCTION LEDR_
ID: 3831837 • Letter: #
Question
//file: LEDR.s
//author:
.include "macros.inc"
SET_TARGET
.text
FUNCTION LEDR_Init,global //C prototype: void LEDR_Init(void)
//layer of abstraction, calls gpio_d_init
push {lr}
bl gpio_d_init //call gpio_d_init
pop {lr}
bx lr
ENDFUNC LEDR_Init
FUNCTION LEDR_Put_A,global //C prototype: void LEDR_Put_A(unsigned int bit)
//Write normalized passed (r0) value to bit 8 of ODR
push {lr}
mov r2,r0 //save value in r0
lsl r2,#8 //de-normalize passed value
bl gpio_d_get_current //call gpio_d_get_current to read ODR
ldr r3,=((~0<<1)<<8) //create mask
and r0,r3 //apply mask to clear field
orr r0,r2 //merge
bl gpio_d_put //call gpio_d_put to write r0 to ODR
pop {lr}
bx lr
ENDFUNC LEDR_Put_A
FUNCTION LEDR_Put_B,global //C prototype: void LEDR_Put_B(unsigned int bits)
//writes normalized passed (r0) value to bits[5:2] of ODR
push {lr}
mov r2,r0 //save contents of r0
lsl r2,#2 //de-normalize r2
bl gpio_d_get_current //call gpio_d_get_current
ldr r3,=((~0<<4)<<2) //create mask
and r0,r3 //apply mask
orr r0,r2 //merge
bl gpio_d_put //call gpio_d_put to write r0 to ODR
pop {lr}
bx lr
ENDFUNC LEDR_Put_B
.end
Explanation / Answer
.include "macros.inc"
SET_TARGET
.text
FUNCTION LEDR_Init,global //C prototype: void LEDR_Init(void)
//layer of abstraction, calls gpio_d_init
push {lr}
bl gpio_d_init //call gpio_d_init
pop {lr}
bx lr
ENDFUNC LEDR_Init
FUNCTION LEDR_Put_A,global //C prototype: void LEDR_Put_A(unsigned int bit)
//Write normalized passed (r0) value to bit 8 of ODR
push {lr}
mov r2,r0 //save value in r0
lsl r2,#8 //de-normalize passed value
bl gpio_d_get_current //call gpio_d_get_current to read ODR
ldr r3,=((~0<<1)<<8) //create mask
and r0,r3 //apply mask to clear field
orr r0,r2 //merge
bl gpio_d_put //call gpio_d_put to write r0 to ODR
pop {lr}
bx lr
ENDFUNC LEDR_Put_A
FUNCTION LEDR_Put_B,global //C prototype: void LEDR_Put_B(unsigned int bits)
//writes normalized passed (r0) value to bits[5:2] of ODR
push {lr}
mov r2,r0 //save contents of r0
lsl r2,#2 //de-normalize r2
bl gpio_d_get_current //call gpio_d_get_current
ldr r3,=((~0<<4)<<2) //create mask
and r0,r3 //apply mask
orr r0,r2 //merge
bl gpio_d_put //call gpio_d_put to write r0 to ODR
pop {lr}
bx lr
ENDFUNC LEDR_Put_B
.end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.