there are 3 questions in file that I attached.
3/20/2020 Lctr 18 for CEC 320 p. 1
4.1.4 The if-then-else construct
Note: due to the existence of the compound OR expression, the conditional execution
approach (Asm Prog 2 above) is not so advantageous. Hence, we will only use the
conditional branch approach.
The if-then-else construct with compound OR expression
3/20/2020 Lctr 18 for CEC 320 p. 2
4.2 The for loop to master in both C and assembly
Note:
1. The condition_expression is tested before the block of the intended code is executed,
which means that the block of code may not have a chance to run. We need to
update the loop-counting variable in each pass after executing the block of code.
2. We prefer to use Approach 2 due to its clean structure. Yet, Approach 1 is slightly
more efficient.
3. Approach 1 is similar to the do-while loop we will see soon.
3/20/2020 Lctr 18 for CEC 320 p. 3
4.3 The while loop to master in both C and assembly
Note: the condition_expression for the while loop is also tested before executing the
block of intended code, in the same way as the for loop. We also need to update the
loop-counting variable in each pass after executing the block of the intended code.
We can see from Tasks 5 and 7 of 170_conditional_execution that the implementation of
for loop and a while loop can be exactly the same in assembly.
3/20/2020 Lctr 18 for CEC 320 p. 4
4.4 The do-while loop to master in both C and assembly
Note: the condition_expression is tested after executing the block of intended code, which
means that the block of code will be executed at least once.
The do-while loop
The while loop
Note that the assembly code for the do-while loop is slightly more compact/efficient than that
of the while loop.
3/20/2020 Lctr 18 for CEC 320 p. 5
4.5 The continue and break statements to master in C and to know in assembly
The continue and break statements affect the flow of a loop in different ways:
• Continue = jump to the end of the loop and continue the next pass of the loop
• Break = break (jump out of) the loop
3/20/2020 Lctr 18 for CEC 320 p. 6
3/20/2020 Lctr 18 for CEC 320 p. 7
4.6 The switch statement to master in C
The switch statement can be seen as a special case of the if-then-else statement, with
the following caution:
The ARM Cortex-M processors use a special Branch Table to handle the addresses of the case blocks.
See the textbook for details. We just need to be informed of the BranchTable approach; no need to
master them at this stage of learning. As will be seen in a later chapter, we can always call C code,
such as the switch statement, in the assembly code.
3/20/2020 Lctr 18 for CEC 320 p. 8
4.7 The IT (If-Then) instruction to know in assembly
The IT instruction can handle a block of code of “then” and “else”. The number of
instructions in the block is at most 4 using the following syntax:
Notes:
* While the IT construct is important for the GNU assembly, it is not as important for the ARM
assembly—the latter can add this construct automatically.
* The IT version of the instructions may be more compact than the non-IT version. See the example
of ADD in line 196 and ADDEQ in line 202 above.
1. (30 points total, 5 points each) We have learned in the class (see lecture 18) that using the barrel shifter, we can implement
multiplication/division of a number for some special cases with addition, subtraction, and reversed subtraction. Write the
assembly code to perform the following calculations using this approach assuming signed integers A and B are saved in r0 and
r1, respectively.
a. A=16*B
b. A=17*B
c. A=15*B
d. A=B/16
e. A=17*B/16
f. A=15*B/16
2. (70 points) We have learned the following in the class:
1. LDR with immediate offset:
2. LDR with pre-indexed offset:
3. LDR with post-indexed offset:
4. LDR with register offset:
LDR Rt, [Rn, #offset]
LDR Rt, [Rn, #offset]!
LDR Rt, [Rn], #offset
LDR Rt, [Rn, Rm, shift]
Now, we practice these instructions here with the given program snippets below: Part A: C code:
// Functions defined in a .s file
extern void task1(uint8_t *pIpt, uint32_t *pOup);
extern void task2(uint8_t *pIpt, uint32_t *pOup);
extern void task3(uint8_t *pIpt, uint32_t *pOup);
extern void task4(uint8_t *pIpt, uint32_t *pOup, int i);
// Global variable
uint8_t ipt[16]; // Input data
uint32_t opt[4]; // Output data
int main(void) {
for (int i = 0; i < 16; i++) {
ipt[i] = i<<4;
}
// Task 1.
task1(ipt, opt);
printf(“Out1 = 0x%X, Out2 = 0x%X\n”, opt[0], opt[1]);
// Task 2.
task2(ipt, opt);
printf(“Out1 = 0x%X, Out2 = 0x%X\n”, opt[0], opt[1]);
// Task 3.
task3(ipt, opt);
printf(“Out1 = 0x%X, Out2 = 0x%X\n”, opt[0], opt[1]);
// Task 4.
task4(ipt, opt, 1);
printf(“Out1 = 0x%X, Out2 = 0x%X\n”, opt[0], opt[1]);
while (1);
}
Part B: asm code
EXPORT task1
EXPORT task2
EXPORT task3
EXPORT task4
ALIGN ; Align the data in the boundary of 4 bytes.
task1 PROC
LDR r2, [r0, #4]
STR r2, [r1, #0]
LDR r2, [r0, #0xC]
STR r2, [r1, #4]
BX lr
ENDP
task2 PROC
LDR r2, [r0, #4]!
STR r2, [r1, #0]
LDR r2, [r0, #4]!
STR r2, [r1, #4]
BX lr
ENDP
task3 PROC
LDR r2, [r0], #4
STR r2, [r1, #0]
LDR r2, [r0], #4
STR r2, [r1, #4]
BX lr
ENDP
task4 PROC
LDR r3, [r0, r2, LSL #2]
STR r3, [r1, #0]
ADD r2, #1
LDR r3, [r0, r2, LSL #2]
STR r3, [r1, #4]
ADD r2, #1
BX lr
ENDP
Answer the following questions (without running the program first):
a. (10 points) What will be the print out after Task 1?
b. (15 points) What will be the print out after Task 2 and what will be the values in r0 and r1 in hexadecimal after running
Task 2 assuming their values are 0x20001010 and 0x20001040, respectively when the function is called?
c. (15 points) What will be the print out after Task 3 and what will be the values in r0 and r1 in hexadecimal after
running Task 3 assuming their values are 0x20001010 and 0x20001040, respectively when the function is called?
d. (15 points) What will be the print out after Task 4 and what will be the values in r2 and r3 in hexadecimal after running
Task 4?
e. (15 points) What will be the corresponding C code for each task?
3. (20 points) We have learned in the class that for signed numbers, we have the following mapping between the
relationship testing and condition flags (page 5 in lecture notes for lctr160) :
Determine the mapping between the relationship testing and condition flags for unsigned numbers.
We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.
Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.
Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.
Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.
Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.
Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.
We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.
Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.
You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.
Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.
Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.
You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.
You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.
Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.
We create perfect papers according to the guidelines.
We seamlessly edit out errors from your papers.
We thoroughly read your final draft to identify errors.
Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!
Dedication. Quality. Commitment. Punctuality
Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.
We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.
We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.
We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.
We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.