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: 8392 0x809e: 0200 0x80a0: 2005 0x80a2: 40B2 0x80a4: 03E8 0x80a6: 0200 0x80a8: E3E2 0x80aa: 0021 0x80ac: 9382 0x80ae: 0202 0x80b0: 240D 0x80b2: D3D2 0x80b4: 0021 0x80b6: E0F2 0x80b8: 0010 0x80ba: 001D 0x80bc: 8392 0x80be: 0202 0x80c0: 2005 0x80c2: C3D2 0x80c4: 0021 0x80c6: C0B1 0x80c8: 0010 0x80ca: 0000 0x80cc: 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

đề cuối kì vxl

Embed Size (px)

Citation preview

Page 1: đề cuối kì vxl

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: 83920x809e: 02000x80a0: 20050x80a2: 40B20x80a4: 03E80x80a6: 02000x80a8: E3E20x80aa: 00210x80ac: 93820x80ae: 02020x80b0: 240D0x80b2: D3D20x80b4: 00210x80b6: E0F20x80b8: 00100x80ba: 001D0x80bc: 83920x80be: 02020x80c0: 20050x80c2: C3D20x80c4: 00210x80c6: C0B10x80c8: 00100x80ca: 00000x80cc: 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 01010101 0101 0000 01010101 0101 0000 01010101 0100 0000 01010101 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 #0x01, &0x0021 ; turn off the LEDbis.b #0x01, &0x0021 ; turn on the LEDxor.b #0x01, &0x0021 ; toggle the LED

a. 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?

Page 2: đề cuối kì vxl

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,R42.0x8004: MOV.W &FOOEY,R43.0x8008: MOV.W FOOEY,R44.0x800c: MOV.W @R4,R45.0x800e: MOV.W @R4,R46.0x8010: MOV.W @R4+,R4

... 0x9000: FOOEY: .word 0xA000

... 0xA000: FOOBAR: .word 0x9000

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

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 mov.w TOM,BOB 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 sqrtFuncmov r0,result ;save…

result: .word 0

sqrtFun:push r4push r5… ; calculate square rootmov r6,r0 ; return results in R0

pop r4pop r5ret

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

Page 3: đề cuối kì vxl

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

x = ?y = ?z = ?

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

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

}

Answers:

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

getdata.next = &getdata;

Hint: Think about activation records and where each variable is stored in memory.

Answer:

Address Data0x02800x027E Return address SP0x027C 0x027A0x027A 0x02780x0278 0x000A0x0276

SUB.W #0x0006,SP ; { ; int x; ; int* y; ; int** z;

MOV.W SP,0x0002(SP) ; y = &x;MOV.W SP,R15 ; z = &y;INCD.W R15MOV.W R15,0x0004(SP)

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

ADD.W #0x0006,SP ; }RET

Main :0x8020: 8221 SUB.W #4,SP0x8020: 4381 0000 CLR.W 0x0000(SP)0x8024: missing instruction0x8028: 5221 ADD.W #4,SP0x802A: 4130 RET

struct node{ int count; struct node *next;};

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