Submission Guidelines:

  1. Every submission must have a coversheet (hardcopy or softcopy) - the coversheet must include your name, semester, date, course number, assignment number, title of the assignment. Use Font 18 and above.
  2. Evey snapshot/figure must have a description. You will not receive any grade if you do not have a clear description for the snapshot/figure.
  3. Make sure you include the entire question. If you don't have the entire question you do not receive a grade.
  4. Each question must be answered by a complete sentence. Example: just writing "22" will not be a complete answer! You should state: The value of register 0x8 will be 0x22"
  5. Everything must be typed.
  6. If the scanned figure is not readable, you will not receive a grade.
  7. Problem statement must be clear and free of any error. Do not just copy the question.; use your own words. Example: "The purpose of this assignment is to design..."
  8. Your code must have the correct heading - see example file.

LAB 2 (use Assembly language only!) - See submission guidelines above!

A (50 points) - Using MPLABX write instructions for a PIC18F45K20 to store two unsigned 8-bit HEX numbers (e.g., 0x48 and 0x4F) in data registers 0x220 and 0x221, respectively. Add the two numbers and save the sum in register 0x230 and 0x231 (register 0x231 will hold the carry bit - the MSB). Your code should work for any two input values. All values are only expressed in HEX. When the instructions are completed the program should stop by entering into a "continuous loop". You must start your code from location 0x20. See the example file. Submit the following:

INPUT1 & 2: SUM/Carry: Fcyc:
0x220 0x221 0x230 0x231 Time to complete
         

B (50 points) - Using MPLABX write instructions to store two unsigned 8-bit HEX numbers (e.g., 0xF8 and 0x4F) in data registers 0x20 and 0x21, respectively. Your code should figure out which input is larger and subtract the larger from smaller input (e.g., smaller_number - larger_number). The final result must be displayed at PORTC and saved in register 0x30. Note that you already learned how to set PORTC in previous exercises (Appendix F of textbook).You must start your code from location 0x20. Submit the following:

INPUT1 & 2 Outputs: Fcyc:
0x20 0x21 0x30 PORTC Time to complete
         

______________________________

LAB 3 (use Assembly language only!): - See submission guidelines above!

A- In this problem you are designing a simple 8-bit calculator. You must first learn about Test and Skip Operations, branch commands, as well as MULLW and MULWF commands. You must use MPLABX and PIC18F45K20, with Fcyc = 1MHz.

Problem: Assume two non-zero unsigned input values are stored in INPUT1 (reg 0x20) and INPUT2 (reg 0x21) data registers. The result must always be stored in the RESULT (reg 0x40) register. All values are only expressed in HEX. When the instructions are completed the program should go to halt (continuous loop). You must start your code from location 0x20. In your code you must have two variables referring to INPUT1 and INPUT2. These values are your inputs and can be changed by the user at the beginning of the program.

Your calculator must perform FOUR operations: addition, multiplication, division, and subtraction. The nature of the operation can be determined by setting the following bits in the OPERATION (reg 0x30) register:

Submit the following:

12 PLUS 230
0 PLUS 255
23 NEG 11
230 NEG 245
54 NEG 123
45 NEG 8
12 MUL 12
0 MUL 18
240 MUL 1
19 MUL 10
17 DIV 3
16 DIV 4
241 DIV 4
0 DIV 12
Inputs to the program Outputs Fcyc (number of Cycles required)
0x20 (INPUT1) 0x21(INPUT2) 0x30 (OPERATION) 0x40 (RESULT) 0x41 (REM)  
           

___________________________

LAB 4 (use Assembly language only!): - See submission guidelines above!

A- In this problem you are designing a calculator to calculate the MIN. MAX, and AVG values among several given number. Assume the given numbers are located in RAM registers starting with REG20 to REG30. Assume all input values are 8-bit unsigned numbers grater than zero. Complete the following codes:

  1. Write a program that reads the content of registers REG20 to REG30. A zero register indicates the last input value. The number of non-zero entries must be recorded in a register called NUM_REG (REG40).
  2. Calculate the average value of the inputs. The average must be recorded in REG41 and called AVG_REG. Assume the sum of all inputs is always divisible by the number of inputs (e.g., the average is always a whole number).
  3. Find the smallest input value. The smallest number must be recorded in REG42 and called MIN_REG.
  4. Find the largest input value. The largest number must be recorded in REG43 and called MAX_REG.

Submit the following:

_______________

 

For Later Only

Part IV:

See PART IV or the problem description.

---------------------------------------------------------------------

Later:

a- Write instructions to store two 8-bit HEX numbers (e.g., 0x48 and 0x4F) in data registers 0x20 and 0x21, respectively. Add the two numbers and save the sum in register 0x30. Your code should work for any two values. Identify which flags will be set after the addition. Note: you must start your code from location 0x30. Indicate the value of Registers WREG, 0x20,0x21, 0x30,0x31, and STATUS. Take a snapshot of your code. Your code must include proper format as described in class. For Extra Credit Only: The result must also be shown on the 7-Segment screen.

b- Write instructions to load two numbers from registers 0x30 and 0x31 (say, numbers 0x7F and 0x28) and subtract the larger from the smaller. Your code must figure out which number is larger and which is smaller. Display the results at PORTC and also save it in register 0x30. Identify which flags will be set after the addition. Indicate the value of Registers WREG, PORTC, 0x30,0x31, and STATUS. Note: you must start your code from location 0x40. Take a snapshot of your code. Your code must include proper format as described in class. Must do the flowchart first!

Part II:

Make sure you test your program using many different values to ensure it works properly! Before doing these problems make sure you have carefully read chapter 4 (and all other related materials provided on the web) and completed Simulation exercises on page 121.

Write a program to add any unsigned 24-bit numbers stored in the following registers: NUM1L (lowest byte), NUM1H (middle byte), NUM1U (highest byte), NUM2L (lowest byte), NUM2H (middle byte), NUM2U (highest byte). The number must be stored in SUML (lowest byte), SUMH (middle byte), SUMU (highest byte), and CARRY_BIT. If the carry bit is set all three SUM registers must be cleared. Otherwise, the SUM register must reflect the correct result. Note that RC1 (bit 1 of PORTD) must reflect the status of the CARRY_BIT. You must submit the following: flowchart for your code and a snapshot of the results and code. You need to demonstrate to the instructor that the program operates properly. (50 points) - Must do the flowchart first!

Test: Check the following: NUM1 NUM2 SUM CARRY_BIT(RC1)

Test 1 /

(solution is here!)
Input Results Remainder