Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//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

  
  
  
  
  
  
  
  
  
  
  
   

Part C: Modify LEDR.s 2. Modify a working copy of source module LEDRs from your Lab07/p2/src/ directory with the following specifications a. Create a new function called led put index which takes the normalized bits passed to it in RO and writes them to the Port D ODR bits 14:12 (3 LEDs). This is just a variation on LEDR Put B. b. Create a new function called led putt segments which takes the normalized bits passed to it in RO and merges them into the Port D ODR bits 6:0 (7 LEDs). This is just a variation on LEDR Put B.

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