Вы находитесь на странице: 1из 4

1.

(1 points) Disassemble the following 25


memory words: (Hint: There are 13 instructions.
Make up your own labels. Use hexadecimal
notation for constants and absolute locations.)
0x809c:
0x809e:
0x80a0:
0x80a2:
0x80a4:
0x80a6:
0x80a8:
0x80aa:
0x80ac:
0x80ae:
0x80b0:
0x80b2:
0x80b4:
0x80b6:
0x80b8:
0x80ba:
0x80bc:
0x80be:
0x80c0:
0x80c2:
0x80c4:
0x80c6:
0x80c8:
0x80ca:
0x80cc:

8392
0200
2005
40B2
03E8
0200
E3E2
0021
9382
0202
240D
D3D2
0021
E0F2
0010
001D
8392
0202
2005
C3D2
0021
C0B1
0010
0000
1300

2. (1 points) If the value in R4 is 0x0008, what


will the value be in R5 after executing the
following 5 lines of binary code? What does the
binary program do?
0100 0100 0000 0101
0101 0101 0000 0101
0101 0101 0000 0101
0101 0100 0000 0101
0101 0101 0000 0101
3.(3 points)
A digital output port (8 bits) of an MSP430 processor is
assigned to memory location 0x0021. This output port controls 8 LEDs that are
connected to Pins 0-7. Three MSP430 assembly instructions can be used to turn
ON and OFF and TOGGLE these LEDs. For example, to control the LED
connected to Pin 0, we can use
bic.b
bis.b
xor.b

#0x01, &0x0021
#0x01, &0x0021
#0x01, &0x0021

; turn off the LED


; turn on the LED
; toggle the LED

What assembly instruction turns on LEDs connected to Pins 3 and 4 at the


same time?
b. What assembly instruction turns off all 8 LEDs at the same time?
a.

c. What assembly instruction toggles LEDs connected to Pins 1 and 7?

4. (6 points) For the following assembly code, give contents of R4 after each line
is executed.
1.0x8000:
MOV.W
#FOOEY,R4
2.0x8004:
MOV.W
&FOOEY,R4
3.0x8008:
MOV.W
FOOEY,R4
4.0x800c:
MOV.W
5.0x800e:
MOV.W
6.0x8010:
MOV.W
...
0x9000: FOOEY: .word
...
0xA000: FOOBAR: .word

Answer
Answer
Answer
Answer
Answer
Answer

1:
2:
3:
4:
5:
6:

@R4,R4
@R4,R4
@R4+,R4
0xA000
0x9000

5.(6 points)
Assemble the following MSP430 assembly instructions. The
label TOM is located at address 0x8014. After assembly is completed, what is in
memory locations 0x8014, 0x8016, and 0x8018? (Give
your answer in hexadecimal with 0x.)
0x8014: TOM
BOB

mov.w TOM,BOB

6.(8 points)
Identify four problems in the following assembly program.
How would you fix the problems? (Identify the problems and change or add
instructions to fix them.)
call
mov

sqrtFunc
r0,result

;save

result: .word 0
sqrtFun:
push
push

mov
pop
pop
ret

r4
r5
r6,r0

; calculate square root


; return results in R0

r4
r5

1. (9 points) Compile the following C statements into MSP430 assembly code.


(Variables are to be defined on the stack (SP) and referenced from the top of the
stack.)
Assuming the stack pointer has 0x027E before the instruction SUB.W

#0x0006,SP

What are the stack assignments (shown below) and values for variables x, y, and z
just before the final brace?
x = ?
y = ?
z = ?

SUB.W

#0x0006,SP

MOV.W
MOV.W
INCD.W
MOV.W

SP,0x0002(SP)
SP,R15
R15
R15,0x0004(SP)

MOV.W
MOV.W

@R15,R15
; **z = 10;
#0x000a,0x0000(R15)

ADD.W
RET

#0x0006,SP

; {
; int x;
; int* y;
; int** z;

int x;
int* y;
int** z;

y = &x;
z = &y;
**z = 10;

Answers:

Address
0x0280
0x027E
0x027C
0x027A
0x0278
0x0276

; y = &x;
; z = &y;

; }

Data
Return address
0x027A
0x0278
0x000A

SP

2. (2 points) Given the C program on the right, what is the missing MSP430
assembly instruction generated by the compiler for the
struct node
line:
{

int count;
struct node *next;

getdata.next = &getdata;

Hint: Think about activation records and where each


variable is stored in memory.
Main :
0x8020:
8221
0x8020:
4381 0000
0x8024:
0x8028:
5221
0x802A:
4130

Answer:

SUB.W
CLR.W
missing
ADD.W
RET

#4,SP
0x0000(SP)
instruction
#4,SP

};

int main(void)
{
struct node getdata;
getdata.count = 0;
getdata.next = &getdata;
return 0;
}

Вам также может понравиться