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

Modify a working copy of source module LEDR.s from your Lab07/p2/src/ directory

ID: 3676005 • Letter: M

Question

Modify a working copy of source module LEDR.s from your Lab07/p2/src/ directory with the following specifications:

Create a new function called led_put_index which takes the normalized bits passed to it in R0 and writes them to the Port D ODR bits 14:12 (3 LEDs). This is just a variation on LEDR_Put_B.

Create a new function called led_put_segments which takes the normalized bits passed to it in R0 and merges them into the Port D ODR bits 6:0 (7 LEDs). This is just a variation on LEDR_Put_B.

# file: LEDR.s

.include "macros.inc"

SET_TARGET

.text

FUNCTION LEDR,global

LEDR_Init: .global LEDR_Init //calls the gpio_d_init function

push {lr}

bl gpio_d_init

pop {lr}

bx lr

LEDR_Put_A: .global LEDR_Put_A       // takes the value from SW3 and puts that value in LED 8

push {lr}

mov r1,r0

bl gpio_d_get_current

ldr r2,=#(~(~0<<1))

and r1,r2

lsl r1,#8

lsl r2,#8

mvn r2,r2

and r0,r2

orr r0,r1

bl gpio_d_put

pop {lr}

bx lr

LEDR_Put_B: .global LEDR_Put_B // takes the value from SW8 through 11 and puts that value in LED 2

push {lr}               // through 5

mov r1,r0

bl gpio_d_get_current

ldr r2,=#(~(~0<<4))

and r1,r2

lsl r1,#2

lsl r2,#2

mvn r2,r2

and r0,r2

orr r0,r1

bl gpio_d_put

pop {lr}

bx lr

ENDFUNC LEDR

.end

Explanation / Answer

THE QUESTION IS RELATED TO MACRO :

DEFINITION OF A MACRO :

--->A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro.

--->There are two kinds of macros.

--->They differ mostly in what they look like when they are used. Object-like macros resemble data objects when used, function-like macros resemble function calls.

--->You may define any valid identifier as a macro, even if it is a C keyword. The preprocessor does not know anything about keywords.

This can be useful if you wish to hide a keyword such as const from an older compiler that does not understand it.

However, the preprocessor operator defined can never be defined as a macro, and C++'s named operators cannot be macros when you are compiling C++.

Modify a working copy of source module LEDR.s from your Lab07/p2/src/ directory with the following specifications:

<ac:structured-macro ac:name="code">
<ac:parameter ac:name="title">This is my title</ac:parameter>
<ac:parameter ac:name="theme">FadeToGrey</ac:parameter>
<ac:parameter ac:name="linenumbers">true</ac:parameter>
<ac:parameter ac:name="language">xml</ac:parameter>
<ac:parameter ac:name="firstline">0001</ac:parameter>
<ac:parameter ac:name="collapse">true</ac:parameter>
<ac:plain-text-body><![CDATA[<b>This is my code]]</b>></ac:plain-text-body>
</ac:structured-macro>

Code block macro with a body and no optional parameters :

<ac:structured-macro ac:name="code">
<ac:plain-text-body><![CDATA[this is my code]]></ac:plain-text-body

Code block macro with a body and the optional language parameter defined :

<ac:structured-macro ac:name="code">
<ac:parameter ac:name="language">html/xml</ac:parameter>
<ac:plain-text-body><![CDATA[this is my code]]></ac:plain-text-body>
</ac:structured-macro>

Code block macro with a body and optional title, line numbers and languageparameters defined :

<ac:structured-macro ac:name="code">
<ac:parameter ac:name="title">This is my title</ac:parameter>
<ac:parameter ac:name="linenumbers">true</ac:parameter>
<ac:parameter ac:name="language">html/xml</ac:parameter>
<ac:plain-text-body><![CDATA[this is my code]]></ac:plain-text-body>
</ac:structured-macro>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote