Tải bản đầy đủ (.doc) (2 trang)

Bài tập Kỹ thuật vi xử lý - DTVT - BKDN (bài07)

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (67.72 KB, 2 trang )

Homework #7
C Language (Ch. 12) and Types, Operators, and Expression (Ch. 13)

In order to automate the grading process, please follow the exact instructions for each
questions and don’t use extra or unnecessary words.
1. (8 points) Create a C project in Code Composer Essentials using the eZ430X board
(MSP430F2274 device). Compile the C code below and check the disassembly list, registers,
and memory contents to answer the following questions. Use Code Composer Essentials’
debugging tool if needed. (Give your answers in hexadecimal with “0x”.)
a. What is the initial value loaded in the stack pointer (R1) when main() starts ?
b. In which memory location is the return address of the main() function stored?
c. Where (memory address) on the stack is the variable a stored ?
d. Where (memory address) on the stack is the variable b stored ?
e. Where (memory address) on the stack is the variable c stored ?
f. Where (memory address) in the memory is the global variable g stored ?
g. What address mode is used to access the local variables a, b, and c?
h. What address mode is used to access the global variable g?
#include "msp430x22x4.h"
int g;
void main(void)
{
int a, b, c;

}

a
b
g
c

=


=
=
=

2;
3;
5;
a + b + g;

2. (2 points)
a. If x = 8 and y = 2, what is assigned to the variable x when the statement x <<= y+1; is
executed?
b. If x = -8 and y = 2, what is assigned to the variable x when the statement x >>= y; is
executed?
3. (2 points)
a. What is the statement to reset bits 0 and 2 of a variable x to 0? (Use a 4-digit
hexadecimal number to represent the mask)
b. What is the statement to set bits 0 and 2 of a variable x to 1? (Use a 4-digit hexadecimal
number to represent the mask)
4. (4 points)
a. If x=10, y=2, and z=3, what is assigned to the variable x when the statement
x *= y + 1; is executed?
b. If x=10, y=2, and z=3, what is assigned to the variable x when the statement
x *= ++y * z-- + 2 is executed?
c. What is assigned to the variable y in part b?
d. What is assigned to the variable z in part b?
BYU, ECEn/CS 124

Homework #7


Page 1/2


5.

(4 points) The following C code has 4 syntax errors. Use Code Composer Essentials to
compile this code if you cannot find all errors. Give the line numbers where these errors
locate.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

/************************************
blinky.c: Software Toggle P1.0
************************************
#include "msp430x22x4.h"

#define MAX_LENGTH 80;
void main(void)
{
int i = 0
for (i=0; i{
if (i%2) P1OUT ^= 0x01;
}
return;

// loop
// toggle P1.0

}

Answer:
6.

(4 points) What will be the output in each of the following printf statements?
int a = 0;
int main()
{
{
int a = 5;
printf("%d\n", a);
{
printf("%d\n", a);
a = 1;
}
printf("%d\n", a);

}
{
printf("%d\n", a);
}
}

(1) ?
(2) ?
// (1)

(3) ?
(4) ?

// (2)
// (3)
// (4)

7. (6 points) Answer these questions exactly the same as how the printf statements will print.
int a = 5;
Int b = 4;
int c = 3;
main()
{
if (--a > b--){
printf(“%d %d\n”, a++, b--);
} else {
printf(“%d %d\n”, c--, ++b);
}
if (a-- <= ++b){
printf(“%d\n”, a/c);

} else {
printf(“%d\n”, a%b);
}
}
BYU, ECEn/CS 124

a. What will be printed first?
b. What will be printed next?

Homework #7

Page 2/2



×