19CCE211 - P2 Answers
19CCE211 - P2 Answers
Consider the following registers R0, R1, R2, R3, and R4 are holding the values 0x10, 0x08,
0x04, 0x02, and 0x01 respectively. Find what would be the register values after executing
each instruction.
(i) ADD R6, R3, R2, LSR #2
R6 – 0x00000003
(ii) MLS R7, R2, R3, R0
R7 – 0x00000008
(iii) SUB R8, R0, R2, LSL #2
R8 – 0x00000000
(iv) BIC R9, R1, #0x08
R9 – 0x00000000
(v) REV16 R10, R0
R10 – 0x00001000
2. Write an assembly language program to calculate the Amusement Park Ticket Fare based
on the age of the person and height of the person if the age is 10 and below. Consider the
following conditions:
(I) If the age is 10 and below and
(i) If height is 140 cm and below the fare is Rs. 500
(ii) If height is greater than 140 cm the fare is Rs. 600
(II) If the age is between 10 and 50 the fare is Rs. 750
(III) If the age is 50 and above the fare is Rs. 650
Page 1 of 3
3. Write a program to receive a character from UART1 receiver and transmit it back through
UART2 of MSP432 microcontroller.
#include "msp.h"
void UART1_init(void)
{
EUSCI_A1->CTLW0 |= 1;
EUSCI_A1->MCTLW = 0;
EUSCI_A1->CTLW0 = 0x0081;
/* 1 stop bit, no parity, SMCLK, 8-bit data */
EUSCI_A1->BRW = 26;
P2->SEL0 |= 0x0C; /* P2.3, P2.2 for UART */
P2->SEL1 &= ~0x0C;
EUSCI_A1->CTLW0 &= ~1;
}
void UART2_init(void)
{
EUSCI_A2->CTLW0 |= 1;
EUSCI_A2->MCTLW = 0;
EUSCI_A2->CTLW0 = 0x0081;
/* 1 stop bit, no parity, SMCLK, 8-bit data */
EUSCI_A2->BRW = 26;
P3->SEL0 |= 0x0C; /* P3.3, P3.2 for UART */
P3->SEL1 &= ~0x0C;
EUSCI_A2->CTLW0 &= ~1;
}
int main(void)
{
char c;
UART1_init();
UART2_init();
while (1)
{
while(!(EUSCI_A1->IFG&0x01));
c = EUSCI_A1->RXBUF;
while(!(EUSCI_A2->IFG&0x02));
EUSCI_A2->TXBUF = c;
}
}
4. Represent the value 135.2510 in both 32-bit and 64-bit floating point IEEE 754 standard.
135 = 10000111
0.25 = 01
135.25 = 10000111.01
=1.000011101 x 2^7
Page 2 of 3
Single precision (32 bit):
Exponent = 127+7 = 134 = 10000110
Mantissa = 000011101
2. Double precision:
Exponent = 1023+7 = 1030 = 10000000110
Mantissa = 000011101
5. Consider a room with attractive led lightings (3 red led lights and 3 blue led lights). Write
a program to generate 5 second time delay by using Timer32 of MSP432 microcontroller
to toggle between the different color LEDs. Consider 3 red LEDs are connected with P2.0
to P2.2 and 3 blue LEDs are connected with P2.3 to P2.5. Also, consider the master clock
is running at 3 MHz and Timer32 is configured in wrapping mode.
#include "msp.h"
int main(void)
{
P2->SEL1 &= ~0x3F;
P2->SEL0 &= ~0x3F;
P2->DIR |= 0x3F;
while (1) {
while((TIMER32_1->RIS & 1) == 0); /* wait until the RAW_IFG is set */
TIMER32_1->INTCLR = 0;
P2->OUT = 0x07; /* toggle LED */
while((TIMER32_1->RIS & 1) == 0); /* wait until the RAW_IFG is set */
TIMER32_1->INTCLR = 0;
P2->OUT = 0x38; /* toggle LED */
}
}
*****
Page 3 of 3