Homework 3 UCR EE/CS120B: Introduction to Embedded Systems Winter Quarter 2002, Prof. Frank Vahid Due Th Feb 14 before lecture 1. Write assembly code, using the instruction set provided in ESD Fig 3.7, for the following: // assume x is M[100] // assume y is M[101] y = y - ((x + 1) * 2)^2 // ^2 means squared 2. Recall that one reason for writing assembly is for device drivers. Write assembly (using the instruction set in ESD Fig 3.7 -- you may add an AND instruction) to initialize a display. The display has an 8-bit data input D that you can write to by writing to the low byte of memory location 255 (the memory is 16 bits wide). The display has 4 control inputs i3-i0 that you can write to by writing to location 254 -- bit 3 corresponds to input i3, bit 2 to i2, etc. The display has four control outputs o3-o0 that you can read by reading location 253 (the low four bits). The display requires the following initialization sequence: Set D = FFh (eight 1's) for at least 20 cycles Set i0 to 1 and hold it until o0 is a 1 Set D = 00h for at least 20 cycles while holding i0 to 1 Set i0 to 1 The display is now initialized Assume each instruction of the processor requires exactly 4 cycles (assume the processor is NOT pipelined). So two instructions take 8 cycles. 3. (a) Redo problem 1 above using the 8051 instruction set. (b) Redo problem 2 above using the 8051 instruction set. 4. Design a 16-bit processor, having a Harvard architecture, 512 words of data memory (M), 64,000 words of program memory, and 8 registers. It should support the following instructions: * Rn = M(direct) * M(direct) = Rn * Rl = immediate * Rl = Rn + Rm * Rl = Rn - Rm * Jump to PC+offset if Rn is 0 * Jump to PC+offset unconditionally (a) Define an instruction set using pneumonics. Also show the opcodes in binary. (i.e., do what was done in ESD Fig 3.7). (b) Describe the processor as an FSMD, then create a datapath plus an FSM, and finally implement a control unit having a controller that uses a state-register plus ROM (show the ROM contents). We recommend you do this problem using a word processor or other electronic capture tool, since drawing it out on paper will likely become cumbersome. 5. Write an assembly program that uses your processor to compute the following. Assume w is M[1], x is M[2], y is M[3], and z is M[4] if (w == 1) { x = y + z; } else { x = y - z; } 6. (a) How many registers does the 8051 microcontroller have? (b) What is the length of an 8051 instruction? (c) Show how to write 01010101 to Port 0 in assembly on the 8051. (d) The 8051 comes with 256 bytes of on-chip RAM. Some programs require more RAM. Explain how we can add RAM to an 8051. (e) What is the maximum amount of program memory with an an 8051? Why is this the maximum? (f) How many cycles are required for a typical 8051 instruction? (g) What is a typical clock frequency for an 8051? (h) Roughly how much does an 8051 chip cost?