ECE 3430 Exam #1 Solutions (Fall 2014)

Your Name: Matt Laubhan
(127 points possible)

You may use your calculator, pencil, and scratch paper if you need it. No phones! Datasheets are provided with this exam. For multiple-choice questions, circle the single correct answer to each question. For short answer questions, write your answer in the space provided on this exam paper. Remember to include the number base for any numerical answers—else it will get counted wrong!

1)Which of the following is an assembler directive and not processed by the MSP430 CPU? [2 points]

  1. mov
  2. ds
  3. sub
  4. xor

2)Which of the following is not one of the fundamental components of all microcomputers: [2 points]

  1. Input
  2. Output
  3. Control unit
  4. Memory
  5. Datapath
  6. Timers

3)mov.w @R5, 8(R4) exhibits which MSP430 addressing modes? [2 points]

  1. Register direct, register direct
  2. Absolute, indexed
  3. Register indirect, indexed
  4. Symbolic, register indirect

4)The MSP430 assembler recognizes instruction mnemonicsand assembler directives as the: [2 points]

  1. First field
  2. Second field
  3. Third field
  4. Forth field

5)A peripheral device that provides input to a microcontroller and reacts to changes in the environment is called a/an: [2 points]

  1. Sensor
  2. Actuator
  3. Signal conditioning circuit
  4. Device driver

6)Which of the following registers in the MSP430 controls the directionality of bi-directional pins in port 1: [2 points]

  1. P1OUT
  2. P1DIR
  3. P1IN
  4. P1REN

7)What is the minimum number of bus cycles required to move a 16-bit word of data in the MSP430? [2 points]

1 bus cycle (since the data bus is 16-bits wide)

8)The LaunchPad (housing the MSP430 microcontroller) communicates with the host PC in the laboratory: [2 points]

  1. Using a parallel cable and port 1
  2. Via a USB-based emulator chip
  3. Using the RS-232 transceiver and the MSP430 SCI subsystem
  4. Using a wireless adapter

9)A certain byte-addressable microprocessor has 20 address lines. How many bytes can be addressed by this microprocessor? [2 points]

1 MB or 1,048,576 bytes

10)The MSP430 “mov” instruction supports a total of ____destinationaddressing modes (only consider the 4 fundamental addressing modes): [2 points]

  1. 1
  2. 2
  3. 3
  4. 4

11)An MSP430 instruction using absolute addressing for both the source and destination operand occupies a total of ____ words of memory: [2 points]

  1. 1
  2. 2
  3. 3
  4. 4

12)The number prefix “#” identifies what to the MSP430 assembler? [2 points]

  1. A comment
  2. Absolute addressing
  3. A hex number
  4. A binary number
  5. Immediate addressing

13)DS is an: [2 points]

  1. MSP430 assembly language directive used to reserve initialized data memory
  2. MSP430 assembly language directive used to reserve uninitialized data memory
  3. MSP430 instruction used to reserve initialized data memory
  4. MSP430 instruction used to reserve uninitialized data memory

14)If R5 contained the number 0x1234, “mov @R5,R6” means what? [2 points]

  1. Initialize the register R6 to the number 0x1234
  2. Initialize the register R6 to the contents of memory location 0x1234
  3. Copy the contents of R5 into R6

15)The MSP430 instruction “mov.w R4, 0x0136” means which of the following to the CPU? [2 points]

  1. Store the upper part of R4 to memory location 0x0137 and the lower half of R4 to memory location 0x0136
  2. Store the upper part of R4 to memory location 0x0136 and the lower half of R4 to memory location 0x0137

`

16)Assume R7 contains the value 0x1273. The MSP430 instruction “mov.b 3(R7),R8” means which of the following to the CPU? [2 points]

  1. Load the byte stored in 0x1276 into the lower part of R8
  2. Load the byte stored in 0x1276 into the upper part of R8
  3. Load the value 0x12 into the lower part of R8 and 0x76 into the upper part of R8
  4. Load the value 0x76 into the lower part of R8 and 0x12 into the upper part of R8

17)Assembly language programs: [2 points]

  1. Allow the programmer to optimize space, power, and speed
  2. Must be executed via read-only memory
  3. Must be executed via read-write memory
  4. Use all of the available addressing modes while C/C++ programs only use extended and immediate addressing modes

18)The instruction “mov #45,0x5678” requires how many 16-bit operands? [2 points]

2 (45 and 0x5678)

19)Fill out the contents of the MSP430 registers for the given code segment. Your answers should reflect the content after each instruction has executed. If the contents are unknown, write a question mark (?) in the blank. All numbers should be given in hex! [10 points, 1 point each]

ORG0x0200

Florian:DS2

Ralf: DS2

ORG0xC000

main:mov.w#0x1234, R4PC = C004

mov.wR4, Florian M(Florian) = 1234

mov.w#Ralf, R6 R6 = 0202

mov.w #0x1230, R6 R6 = 1230

mov.w#0x1235, R7 R7 = 1235

add.wR6, R7R7 = 2465

sub.wR6, R7R7 = 1235

bis.w#00001111b, R4R4 = 123F

xor.wR7, R7R7 = 0000

and.w R4, R4 R4 = 123F

20)Hand assemble (or encode) the following assembly code into machine code. All answers should be in hex format! Write the instruction code (IC) as a 16-bit value and all operands as 16-bit values. [10 points, 2 points each]

ORG0xC000

main:and.b R10,0x0040IC = FAC0Operand(s) = 403E

mov.w R4,R13IC =440DOperand(s) = <none>

bis.w @R11,R12IC =DB2COperand(s) = <none>

add.w &0x0200, R5IC =5215Operand(s) =0200

xor.w #0x5678, R8IC =E038Operand(s) = 5678

21)Decode (or reverse-assemble or inverse-assemble) the following machine code back to the original assembly code. Each line decodes to a single instruction. Each instruction code and operand is provided as a 16-bit value. [8 points, 2 points each]

C000:47C90008 mov.b R7,8(R9)

C004:5429 add.w @R4,R9

C006:8E3A sub.w @R14+,R10

C008:E05F1234 xor.b0x1234(R0),R15orxor.b 0xD23E,R15

22)The MSP430 address bus is ___ bits wide and the data bus is ____ bits wide. [2 points]

16, 16

23)When using immediate addressing, the operand(s) provide: [2 points]

  1. The address of the data to work with
  2. The actual data to work with

24)Assume we want to set bit 4 and clear bit 2 (set bit 4 to a 1 and bit 2 to a 0) in an 8-bit control register mapped to memory location 0x0008simultaneously(in the control register) and without affecting the state of the other bits in that memory location. Show the assembly code required to pull this off. Use only R4 from the programming model. [4 points]

mov.b0x0008, R4 or mov.b &0x0008,R4

bis.b#00010000b,R4 or bis.b #0x10,R4

and.b#11111011b,R4 or and.b #0xFB,R4

mov.bR4, 0x0008 or mov.b R4,0x0008

25)Which of the following needs two 16-bit machine code operands? [2 points]

  1. xor #0x0040, R5
  2. mov 0x0234, 0x0456
  3. sub R5, 0x0056
  4. add @R7+,0x0078

26)Which of the following requires no machine code operands? [2 points]

  1. mov #0x0040, R5
  2. sub @R9+, R10
  3. add 4(R5), 0x0056
  4. bic @R7,0x0078

27)Which of the following is an illegal operation on the MSP430? [2 points]

  1. mov #0x0051, R5
  2. mov 0x0053, R11
  3. mov R5, 0x0086
  4. bis @R7+,0x0068

28)What the 4 significant status register flags controlled directly by the ALU and potentially modified by the completion of an instruction? [2 points]

N (negative),Z (zero), V (two’s complement overflow), and C (carry)

29)Approximately how long would it take the MSP430(if the MCLK frequency were 2 MHz) to execute the following code segment? [2 points]

Cycles:Words:

main: add.w0x1234,R732

xor.b#0x10,R822

-----

5cycles * 500 ns/cycle = 2.5us

30)How many words of memory are consumed by the above chunk of code (in question #29)? [2 points]

4words

31)Which two MSP430 registers have “constant generator” capabilities? [2 points]

R2/SR and R3

32)How many writes and reads are performed to and from memory on the MSP430 address/data bus for the given assembly instruction: [2 points]

sub.w&0x0200, R7Machine code: 0x8217 0x0200

Number of reads = 2 (to read in machine code) + 1 (to read source) = 3

Number of writes = 0(destination is in CPU)

33)How many writes and reads are performed to and from memory on the MSP430 address/data bus for the given assembly instruction: [2 points]

add.wR6, 3(R5)Machine code: 0x5685 0x0003

Number of reads = 2 (to read in machine code) + 1 (to read destination) = 3

Number of writes = 1 (to write back to the destination)

34)Name one thing that makes a microcontroller different from a microprocessor: [2 points]

Many answers are acceptable. Most notably, microcontrollers have on-chip peripheral devices (while microprocessors do not). A microcontroller is a “computer on a chip” (since it has all 5 classic components of a computer) and amicroprocessor (by itself) is not a computer.

35)Which of the following fundamental RAM technologies traditionally has a faster read access time and a faster write time—but takes up more silicon space? [2 points]

  1. SRAM
  2. DRAM

36)Show the optimized machine code for the following instruction—making use of the constant generators: [2 points]

add.w #-1, R10

0x533A (constant generator R3 is used with As = 11 to generate the constant -1 or 0xFFFF)

37)Show the optimized machine code for the following instruction—making use of the constant generators: [2 points]

mov.w #0, R11

0x430B (constant generator R3 is used with As = 00 to generate the constant 0)

38)Name one fundamental ROM technology discussed in lecture: [2 points]

MROM, PROM, EPROM, EEPROM, Flash (any are acceptable).

39)When doing a number base conversion from decimal to binary, what phenomenon terminates the consecutive divisions by 2 (when converting the whole number part)? [2 points]

  1. When overflow occurs
  2. Always after eight division operations
  3. The remainder becomes 0
  4. The quotient becomes 0

40)Give one reason (other than saving money) why saving power in a design (through efficient software and hardware design) is a good idea—even if your design does not run on a limited power supply (a battery). [2 points]

Consuming power leads to heat generation—which brings on a new problem—the need to dissipate the heat to keep from overheating the circuit. When circuits overheat, they first malfunction—then eventually burn up. Solutions to dissipate heat can become expensive and/or require large cooling fans that tend to be noisy.

41)Which of the following 16-bit operations will result in two’s complement overflow (all numbers are presented in decimal)? [2 points]

  1. -32 – 28
  2. 1270 – 12000
  3. -12760 – 20240 (-33000 is not in the signed range for 16-bit numbers)
  4. 32766 + 1

42)Show how the 16-bit value 0xABCD would be stored to memory location 0x0200 on both a big endian and little endian machine. Assume the CPU and memory architecture is byte addressable. Write a “?” in the blank if the contents are unknown. Write all answers in hex. [4 points]

Big Endian: M(0x01FF) = ?M(0x0200) = 0xABM(0x0201) = 0xCD

Little EndianM(0x01FF) = ?M(0x0200) = 0xCDM(0x0201) = 0xAB

43)Which of the bitwise logical instructions available on MSP430 can be used to flip all bits in a register to the opposite state and could also be used to compare two registers for equality? [2 points]

“xor” (exclusive OR)

44)What bitwise logical MSP430 instruction should be used to force selected bits to one within a byte without impacting other bits? [2 points]

“or” or “bis” (bit set)

45)State one good reason why an engineer would want to run an operating system on a microcontroller or a microprocessor: [2 points]

Many answers are acceptable. Threading, memory management, et cetera are all good reasons.

46)What does the following assembly code do? [2 points]

ORG0xC000

DW0xABCD

Initializes the contents of 0xC000 to 0xABCD. You could also say it initializes the contents of 0xC000 and 0xC001 to 0xCD and 0xAB respectively (on a little-endian architecture).

47)Why would using DB and DW within a section of memory mapped to RAM not be a good idea? [2 points]

The initialized memory (initialized at download-time) would be lost when power is lost. However, the program code memory (in flash) would persist. Following a power-cycle, the program would work on uninitialized data.

48)What does the following assembly code do? [2 points]

ORG 0xC000

DB“Hi”

Places the ASCII code for ‘H’ into memory location 0xC000 and the ASCII code for ‘i’ in memory location 0xC001. The double-quotes cause 0xC002 to be initialized to the ASCII NUL character (0). This terminates the string.

49)Give one good reason why a radix-2 multiplication algorithm involving shifts and adds (as discussed in lecture) would be preferable over just adding a value to itself n-1 times. [2 points]

Less operations, less time to execute, less memory consumption as numbers become large.

50)Show the 8-bit binary representation of -2 (decimal) using the following historical signed number encodings: [3 points]

Sign-Magnitude:1000 0010

Ones Complement:1111 1101

Twos Complement:1111 1110

1/7