xuebaunion@vip.163.com
3551 Trousdale Rkwy, University Park, Los Angeles, CA
留学生论文指导和课程辅导
无忧GPA:https://www.essaygpa.com
工作时间:全年无休-早上8点到凌晨3点

微信客服:xiaoxionga100

微信客服:ITCS521
M3H623544 Digital and Programmable Systems 2 M Mata page 1 Tutorial 2 – MSP430 Architecture - SOLUTIONS 1. Use a diagram to help you describing VonNeumann and Hardvare architecture. Explain why the VonNeumann bottleneck happens. 2. A certain 32-bit computer uses 16bit in its MAB. How many memory addresses may it handle? What’s the maximum amount of memory (in MB) it can support? With 16 address bits it can handle 216=65536 memory addresses (64K). As the computer is 32-bit it means that the memory width is 32-bit (4-Byte), so the total amount of memory is 64K x 4Bytes = 256KB 3. What does “single, contiguous memory space” means? It means that all CPU registers, peripheral devices configuration and data registers, and memories (RAM, flash) even if physically separated, are connected in a way that they can be accessed using a single MAB (it is shared), covering all addresses from 0 to 2MABbits-1. In the MSP430, CPu registers are in the lowest memory addresses, then peripheral registers, then code memory, then RAM data memory, some more code memory, and finally the interrupt vector table in the higher memory addresses. Digital and Programmable Systems 2 M Mata page 2 4. What are the differences between General Purpose Registers and RAM positions? Registers are placed inside the CPU itself with direct connection to the ALU so using them is the fastest option: from 2 to 10 times faster in a MCU, up to 100 times faster in a computer using DRAM instead of SRAM technology for the RAM memory. Machine instructions work directly on CPU registers, but not all of them can access the RAM. The number of registers is very limited (only a few variables), while the RAM is relatively large. 5. Briefly describe the 4 special function registers in the MSP430 (R0=PC, R1=SP, R2=SR/CG1, R3=CG2) - R0 is the Program Counter. It holds the address of the next instruction to be executed. Overwriting it creates a jump in the execution sequence. - R1 is the Stack Pointer. It always points to the top of the Stack. The Stack is a RAM region ued in a special way by some instructions to: a)temporally save values, b)passing parameters to/from subroutines, c)handle the return address from subroutines, d)handling the return address from Interrupt Service Routines - R2 has two functions: a) holding the System flags and b)as Constant Generator 1 (CG1) - R3 is Constant Generator 2 (CG2). Some bits into instructions requiring a constant operand are used to select which constant to produce into R3 (or R2) 6. What are the differences between RISC and CISC CPUs? RISC: small number of simplistic instructions (simple electronics to implement them, fast instructions requiring 1 to 5 CPU clock ticks to execute). Doing some task always needs many of these instructions CISC: many instructions trying to cover many tasks with a single instruction, some of them quite specific (complex electronics to implement them all, slow instructions requiring many CPU clock ticks to execute). Doing some task usually requires a relatively small number of instructions Digital and Programmable Systems 2 M Mata page 3 7. How many instructions are there in the MSP430 instruction set? There are 27 core instructions to do everything. There are also another 24 emulated instructions that exist only in assembly to make programming easier (they do not have their own OpCode, but are replaced by equivalent core instructions) 8. What is machine code? What is Assembly language? All instructions into any CPU must be in binary (1s and 0s). Machine Code instructions are binary instructions from the core instruction set. That’s why files containing executable programs are called “binaries” in some operating systems. Assembly language is a set of mnemonics names, labels and constants definitions that are used by humans as proxies for the binary instructions and memory addresses. The assembler program just translates the human labels (assembly) to the binary instructions (machine code). 9. When you write a program in C language, how is it converted to machine code? A compiler program analyses the C code and then generates assembly code implementingit. Usually each C instructon will require a few (or many) assembly instructions to be implemented. Then, the assembly is translated to machine code by an assembler program. Sometimes, the C compiler can produce the machine code straight away. 10. IMPORTANT EXERCISE. Write the required operations on Port3 to: a. Configure bits 1, 3 and 5 outputs, remaining bits as inputs P3SEL = 0x00; //configure all bits as GPIO P3DIR = 0b00101010; //0=input, 1=output b. Configure bit 0 as input with pull-up resistor (do not modify other bits) P3DIR= P3DIR & 0b11111110; //input direction for bit 0 P3REN=P3REN | 0b00000001; //enable internal pull resistor P3OUT=P3OUT | 0b00000001; //select pull-up resistor c. Output a logic “1” in pin 5 (do not modify other bits) From the configuration in a), then do: P3OUT = P3OUT | 0b00100000; //output a 1 in pin 5 (bit 5) d. Output a logic “0” in pin 1 (do not modify other bits) From the configuration in a), then do: P3OUT = P3OUT & 0b11011111; //output a 0 in pin 5 (bit 5) e. Invert the value that is currently present in pin 3 (so not modify other bits) From the configuration in a), then do: P3OUT = P3OUT ^ 0b00001000; //invert pin 3 (bit 3) Notice that binary masks (constants) are often not allowed by compilers because it’s easy to make mistakes, hex version is preferred (i.e. 0x08 instead of 0b00001000). Often pre- defined constants are used (like BIT3 for 0x08, having a 1 only in bit 3). These pre- Digital and Programmable Systems 2 M Mata page 4 defined masks can be added to produce a mask affecting several bits. i.e. (BIT0 + BIT1) is actually (0x01 + 0x02) which results in 0x03 = 0b00000011 –affecting bits 0 and 1- 11. The following diagram shows the Input/Output schematics for Port1, pin x (=any pin). By looking at it, explain the values that you have to write in the configuration bits (P1REN.x, P1DIR.x, P1OUT.x, P1SEL.x) to output a logic H in Port1, pin x (P1.x) That’s the circuit diagram provided by the manufacturer. The bits in the port configuration registers are hard-wired as shown here, and that’s the reason why we need to write the 0 or 1 value to them in order to achieve the desired operation. We can trust the tables provided by the manufacturer or, if we really want to understand how it works, we can take a look at the diagrams. -P1SEL.x bit is the selection bit of a multiplexer; it choses what goes to the output pin. ‘0’ connects P1OUT.x bit to the output, while ‘1’ connects the alternative function (Module X OUT) to the output. We want to configure the pin as output, then we must write a ‘0’ to P1SEL.x - After the previous selection, the value in bit P1OUT.x is sent towards the output pin. As we wish to output a logic H, we need to write a ‘1’ in P1OUT.x - Just before P1OUT.x bit reaches the output pin, a tri-state gate appears. The tri- state is controlled by the P1DIR.x bit. A ‘1’ in bit P1DIR.x enables the tri-state, then the output will be H or L taking the same logic level that the input (=P1OUT.x). So this selectes the pin direction as “output”. On the other hand, a ‘0’ in P1DIR.x sets the pin as input by disabling the tri-state gate, making its output is High-Impedance (highZ) so it behaves as an open switch, effectively “disconnecting” the pin from P1OUT.x. In this situation, the voltage in the pin (H or L) can be set by any external device connected to the pin, and the MCU can read this voltage in the input bit PxIN.x. As this time we wish to output the voltage, we must make P1DIR.x=1. -Making P1DIR.x=1 also opens the switch marked as “1” in the diagram, disconnecting the pull-up resistor. So the settings in P1REN.x are ignored, we can write a ‘1’ or a ‘0’. This setting only applies when the pin is an input (P1DIR.x=0)