0% found this document useful (0 votes)
46 views2 pages

Enhanced Embedded Systems Midterm Exam 2

Uploaded by

musmeh10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views2 pages

Enhanced Embedded Systems Midterm Exam 2

Uploaded by

musmeh10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Midterm Exam 2: Embedded Systems (Advanced ARM Assembly)

Instructions: Answer all questions. The questions test your ability to write efficient, correct ARM assembly code and

understand embedded system concepts. Be concise but clear.

Question 1:

Write an ARM assembly code that divides a number in R0 by 4 using only bitwise shift operations. Store the result in R1.

Question 2:

Convert the following C code snippet into ARM assembly, ensuring minimal instructions:

int x = 5;

int y = x * 3;

if (y > 10) y = 10;

Question 3:

Using only three instructions, implement a subtraction of 7 from a value in R0 and store the result in R1. Avoid using the

SUB instruction.

Question 4:

Analyze the following ARM assembly code and describe its purpose. Can you simplify it further?

MOV R2, #8

LDR R3, =0x20000020

STR R2, [R3]

Question 5:

Write an ARM assembly loop to decrement R4 from 50 to 0 by 5 on each iteration and stop when it reaches zero.

Answers (Place at the End of the Exam)


Answer 1:

MOV R1, R0, LSR #2 ; Logical shift right by 2 bits to divide by 4

Answer 2:

MOV R0, #5 ; x = 5

MUL R1, R0, #3 ; y = x * 3

CMP R1, #10 ; Compare y with 10

MOVGT R1, #10 ; If y > 10, set y to 10

Answer 3:

MVN R2, #6 ; NOT 6 gives -7 in two's complement

ADD R1, R0, R2 ; Add -7 to R0

NOP ; No operation (third instruction)

Answer 4:

*Purpose*: Stores the value 8 at memory address 0x20000020.

*Simplified*: LDR R3, =0x20000020

STR R2, [R3]

Answer 5:

MOV R4, #50 ; Initialize R4 to 50

Loop: SUBS R4, R4, #5 ; Decrement R4 by 5

BGT Loop ; Branch if R4 > 0

You might also like