You are on page 1of 11

TU856 Microprocessor Exam Paper 2021-22

Question 1 (33 marks)

(a) What output will be produced when a C program executes the following instructons:

a. printf(“%x”, 0xabcd1234 | 0x1234abcd);

| - bitwise or operator

Ans - fffffff

b. printf(“%x”, 0xabcd1234 ^ 0x1234abcd);

Ans - ffffffff

c. printf(“%x”, 0xabcd1234 & ~0x1234abcd); [6 marks]

12340000

(b) What is the unsigned numeric range of the following C types:

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?

int8_t X=125; X = X + 5; [5 marks]

130 – not 100% sure

(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.

The ASCII code for ‘1’ is 49. [4 marks]

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.

Address Table Ascii table


100 49
101 50
102 51
103 52

Address Table Ascii table


200 52
201 17

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

How many nanoseconds will it take to execute a function with 10 instructions?

(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]

The maximum value of 12 bits analogue digital converter is – 4096

3.3v/4096 - 0.0008057 V

1V – 1/0.0008057 - 1241

(h) What role do each of the following play in a computer system?

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.

Question 2 (33 marks)

An STM32L031 MCU is wired to a button and two LED’s as follows:

Green LED Port A, Bit 0

Red LED Port A, Bit 1

Button Port A, Bit 2

A ‘1’ in a port bit turns on an LED. When the button is pressed, the pin to which is

connected is pulled down to ‘0’ otherwise it defaults to ‘1’.

(a) What roles do the following registers play in the STM32L031 General

Purpose Input Output system:

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

GPIOA –> ODR = GPIOA –> ODR 1 (1 << 4)

[4 marks]

(c) Write C code that will turn off the Red LED without affecting the Green LED

GPIOA -> ODR = GPIOA -> ODR &~ (1 << 1)

[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

in an STM32L031 is shown below.

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

b. Write a C-function that uses eputchar to send a C-string.

void eputs(const char *str)

while (*str)

eputchar(*str);

str++;

} //

}// end void

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.

The eputs function can be called like this:

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)

while( (USART2->ISR & (1 << TX_COMPLETE)) == 0);

USART2->TDR = c;

[8 marks]
(f) The SysTick timer in Arm Cortex-M microcontrollers can be used to generate

a periodic interrupt it.

a. Outline how this timer operates

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.

b. What is meant by the phrase ‘interrupt’ in this context?

In the context of microcontrollers, an interrupt is a mechanism by which the normal flow of


execution of a program is temporarily suspended and control is transferred to a special routine
called an interrupt handler. Interrupts are typically triggered by external events, such as a timer
expiring or a character being received on a serial port.
c. A Systick timer has an input clock frequency of 32MHz. What value

should be placed in its Reload Value Register (RVR) to cause it to

generate an interrupt every millisecond?

[9 marks]

Question 3 (33 marks)

(a) The STM32L031’s CPU core is an Arm Cortex M0+. It does not allow data

transfers directly from one memory location to another. If a symbol ‘X’ is

declared as shown below, write the Arm-Thumb (assembler) instructions

necessary to read the value stored at X into register R0

AREA DATA

X DCD 10

[4 marks]
(b) The MOVS instruction provides an efficient way of loading a limited range of

values into a Cortex M0+ register. What range of values is allowed?

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

the source location (‘src’) to the destination location (‘dest’).

a. What happens when each line of this function is executed?

[10 marks]

; void memcpy(uint8_t *dest, uint8_t *src, uin32_t n);

; on entry R0 = dest, R1 = src, R2 = n

memcpy

PUSH {LR} ;It pushes the load register

memcpy_loop

CMP R2,#0 ; It compare the the value 0 to R2

BEQ memcpy_exit ;

LDRB R3,[R1] ; The R1 load byte register into R3

STRB R3,[R0] The R0 store the register into R3

ADDS R0,R0,#1 ; It adds 1 into R0

ADDS R1,R1,#1 ; It adds 1 into R1

SUBS R2,R2,#1 ;It subtract 1 into R2

B memcpy_loop

memcpy_exit

POP {PC} ;It pops out from the program counter

Listing Q3a

5
b. Identify an example of each of the following addressing modes in this

function:

i. Immediate

ii. Register indirect

[4 marks]

c. If the stack pointer contains 0x20002000 on entry to this function,

what address will the PUSH instruction save a copy of the link register

to?[2 marks]

d. You have a 32 byte block of data at memory address 0x20000100 that

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)

char src[32] = {0x20000100}; // Array to hold the source data

char dest[32] = {0x20000200}; // Array to hold the destination data

memcpy(dest, src, 32); // Copy the data from src to dest

return 0;

e. How would you modify this function so that it returns the address of

the destination buffer in R0.

[5 marks]
#include <stdint.h>

int main(void)

uint8_t *src = (uint8_t*) 0x20000100; // Pointer to the source data

uint8_t *dest = (uint8_t*) 0x20000200; // Pointer to the destination data

for (int i = 0; i < 32; i++)

*(dest + i) = *(src + i); // Copy one byte at a time

return 0;

; void memcpy(uint8_t *dest, uint8_t *src, uin32_t n);

; on entry R0 = dest, R1 = src, R2 = n

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

TU856 Supplemental Exams

Question 1 (33 marks) (a) What output will be produced when a C program executes the following
instructons:

a. printf(“%x”, 0xc39681e7 | 0x3d697e18); | - OR

ff01000000

b. printf(“%x”, 0xffffffff ^ 0x3d697e18); ^ - XOR

C29681e7

c. printf(“%x”, 0xc39681e7 & ~0x3d697e18); XNOR

FFFF FFFF 0000 0000

[6 marks]

(b) What is the unsigned numeric range of the following C types:

a. uint16_t - It can store values in the range of 0 to 65535.

b. uin32_t – It can store values in range of 0 to 4294967295.

[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?

1. First we convert 9600, into binary – 1000011


1 0 0 0 0 1 1

64 32 16 8 4 2 1

2. If there is even number of 1 then the parity would be 1

3. If there is odd number of 1 then the parity would be 0

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.

ABCD is stored at the memory address 100.

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

31.25 * 100 = 3125

(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]

output value = (input voltage / full scale range) * 2^12


output value = (1.5V / 3.3V) * 2^12 = 0.4545 * 4096 = 1843

(h) What role do each of the following play in a computer system?

a. Address bus

b. Data bus

You might also like