Microprocessor Exam Paper
Microprocessor Exam Paper
(a) What output will be produced when a C program executes the following instructons:
| - bitwise or operator
Ans - fffffff
Ans - ffffffff
12340000
a. uint8_t - it represents 8 bit unsigned integer – minimum value 0 and maximum value 255
b. uin32_t it represents 32 bit unsigned integer – minimum value 0 and maximum value 4294967295
[4 marks]
(c) What value will the variable X have after the following code is executed?
(d) A serial communications link operates at a speed of 115200 bits per second and uses odd parity
checking.
a. What parity bit will be sent when a byte with a value of 65 (decimal) is transmitted?
b. This serial link sends a parity bit, a stop bit and a start bit for each byte transmitted. In other words
it takes 11 bits to send a byte. How long will it take to send 1024 bytes of data over this link? [4
marks]
11*1024 - 11264
(e) A little-endian computer system stores the C-string “1234” in memory starting at address 100. It
also stores the 16 bit integer value 0x1234 starting at address 200.
What values are stored in memory addresses 100 to 104 and memory addresses 200 to 201.
In a little-endian system, the least significant byte (LSB) of a multi-byte value is stored at the
lowest memory address. Therefore, in the case of the C-string "1234", the characters '1', '2', '3',
and '4' would be stored in memory starting at address 100 and going up from there, with the
character '1' being stored at address 100 and the character '4' being stored at address 103.
(f) The Arm Cortex M0+ executes most instructions in a single clock cycle.
If the clock speed is 16MHz, how many nanoseconds will it take to execute a function with 10
instructions? [2 marks]
16 Mzh – 1/16000000 -
(1/16000000) * 10 – 6.25e -7
(g) An STM32L031 has a 12 bit analogue to digital converter with an input voltage range of 0 to 3.3V.
What number will it output if the input voltage is 1V? [4 marks]
3.3v/4096 - 0.0008057 V
1V – 1/0.0008057 - 1241
a. Address bus – The address bus is a communication channel in a computer central processing unit
(CPU) that is used to transmit memory address to the main memory. It is a group of wires that carries
data that identifies a specific location in the memory where the data will be stored or retrieved.
b. Data bus - is a communication pathway in a computer that is used to transmit the data between
different component systems. It is a group of wires or conductors that carry data from one part of a
system to another allowing various components to communicate with each other and exchange
information. The data bus is typically used to transfer data between the CPU, memory and peripherals
such as hard drive, keyboard and monitor.
A ‘1’ in a port bit turns on an LED. When the button is pressed, the pin to which is
(a) What roles do the following registers play in the STM32L031 General
a. ODR - The ODR (Output Data Register) is a register in the STM32L031 microcontroller that is used to store
the values that will be output on the corresponding GPIO (General Purpose Input/Output) pins. When the
value of a bit in the ODR is set to 1, the corresponding GPIO pin will be driven to a high level, and when the
value of a bit in the ODR is set to 0, the corresponding GPIO pin will be driven to a low level. The ODR is used
to control the state of the GPIO pins in output mode.
b. IDR - The IDR (Input Data Register) is a register in the STM32L031 microcontroller that is used
to store the values that are input on the corresponding GPIO (General Purpose Input/Output)
pins. The IDR is used to read the state of the GPIO pins in input mode. The IDR is a read-only
register, which means that its value can only be read and not written to. When a GPIO pin is
configured as an input, the value of the corresponding bit in the IDR reflects the state of the
pin. If the pin is driven to a high level, the corresponding bit in the IDR will be set to 1, and if the
pin is driven to a low level, the corresponding bit in the IDR will be set to 0. The IDR can be used
to detect the state of the GPIO pins and to determine if a particular input signal has changed.
[4 marks]
(b) Write C code that will turn on the Green LED without affecting the Red LED
[4 marks]
(c) Write C code that will turn off the Red LED without affecting the Green LED
[4 marks]
(d) Write C code that will wait for the button to be pressed.
While GPIOA -> IDR & ( 1 << 3) != 0)
[4 marks]
(e) A C-function called eputchar that outputs a single character over the USART
a. What is the purpose of the line starting with the while keyword?
It will run in the continuous while loop until it terminates the program
while (*str)
eputchar(*str);
str++;
} //
This function takes a pointer to a C-string as an argument and sends each character in the string to the
eputchar function until it reaches the null character at the end of the string.
eputs("Hello, world!\n");
This will send the string "Hello, world!" followed by a newline character to the eputchar function.
#define TX_COMPLETE 6
void eputchar(char c)
USART2->TDR = c;
[8 marks]
(f) The SysTick timer in Arm Cortex-M microcontrollers can be used to generate
The SysTick timer is a timer provided by the Cortex-M processor that can be used to generate
periodic interrupts. It operates by counting down from a value that you set to zero at a fixed
rate. When the count reaches zero, the SysTick timer generates an interrupt and reloads the
count value from the reload register.
You can control the frequency at which the SysTick timer generates interrupts by setting the
reload value and the clock source. The reload value is the value that the SysTick timer counts
down from, and the clock source is the clock signal that the timer uses to decrement the
counter.
[9 marks]
(a) The STM32L031’s CPU core is an Arm Cortex M0+. It does not allow data
AREA DATA
X DCD 10
[4 marks]
(b) The MOVS instruction provides an efficient way of loading a limited range of
0-255
[2 marks]
(c) Listing Q3a is the assembly language code for a version of the memcpy
function commonly used in C programs. The function copies ‘n’ bytes from
[10 marks]
memcpy
memcpy_loop
BEQ memcpy_exit ;
B memcpy_loop
memcpy_exit
Listing Q3a
5
b. Identify an example of each of the following addressing modes in this
function:
i. Immediate
[4 marks]
what address will the PUSH instruction save a copy of the link register
to?[2 marks]
you would like to copy to address 0x20000200. How would you set up
the registers and call upon this function to do this for you.
[6 marks]
#include <string.h>
int main(void)
return 0;
e. How would you modify this function so that it returns the address of
[5 marks]
#include <stdint.h>
int main(void)
return 0;
memcpy
PUSH {LR}
memcpy_loop
CMP R2,#0
BEQ memcpy_exit
LDRB R3,[R1]
STRB R3,[R0]
ADDS R0,R0,#1
ADDS R1,R1,#1
SUBS R2,R2,#1
B memcpy_loop
memcpy_exit
POP {PC}
Listing Q3a
Question 1 (33 marks) (a) What output will be produced when a C program executes the following
instructons:
ff01000000
C29681e7
[6 marks]
[4 marks]
(c) What value will the variable X have after the following code is executed?
int8_t
X= -127;
X = X - 4; [5 marks]
(d) A serial communications link operates at a speed of 9600 bits per second and uses even parity
checking.
a. What parity bit will be sent when a byte with a value of 67 (decimal) is transmitted?
64 32 16 8 4 2 1
In this case, the parity would be 0, because we have odd number of 1’s.
b. This serial link sends a parity bit, a stop bit and a start bit for each byte transmitted. In other words
it takes 11 bits to send a byte. How long will it take to send 4096 bytes of data over this link? [4
marks]
4096*11 = 45056
To find how long it takes to send 4096 bytes – 4096 / 9600 = 4.69 seconds
(e) A little-endian computer system stores the C-string “ABCD” in memory starting at address 100. It
also stores the 16 bit integer value 0xABCD starting at address 200. What values are stored in memory
addresses 100 to 104 and memory addresses 200 to 201. The ASCII code for ‘A’ is 65. [4 marks]
The Least Significant Byte (LSB) is stored at the lowest memory address. The Most Significant Byte
(MSB) is stored at the highest memory address.
The ASCI code for A is 65 which represent 8 bits – 01000001 (65). The value stored at the memory
address will be 101.
The ASCI code for B is 66 which represent 8 bits 01000010 (66). The value stored at the memory
address will be 102.
The ASCI code for C IS 67 which represents 8 bits 01000011 (67). The value stored at the
memory address will be 103.
The ASCI code for D is 68 which represents 8 bits 01000100 (68). The value stored at the
memory address will be 104.
The value stored at memory address 200 will be the LSB of 0xABCD, which is CD
(hexadecimal). The value stored at memory address 201 will be the MSB of 0xABCD, which is
AB (hexadecimal).
(f) The Arm Cortex M0+ executes most instructions in a single clock cycle. If the clock speed is 32MHz,
how many nanoseconds will it take to execute a function with 100 instructions? [2 marks]
1/32000000 = 31.25 nanoseconds
(g) An STM32L031 has a 12 bit analogue to digital converter with an input voltage range of 0 to 3.3V.
What number will it output if the input voltage is 1.5V? [4 marks]
a. Address bus
b. Data bus