Labsheet
                                  University of Jordan
                         Faculty of Engineering and Technology
                         Department of Computer Engineering
                        Embedded Systems Laboratory 0907334
    MPLAB and Instruction Set Analysis 2
Name:                 Abed el-Rahman Khaled Hamed
Student ID:           0164872
Section (Day/Time):      Thusrday---1:00 – 4:00
                                                                 1
                                                                                  COMPUTER NAME:
                                     UNIVERSITY OF JORDAN
                            FACULTY OF ENGINEERING AND TECHNOLOGY
                             DEPARTMENT OF COMPUTER ENGINEERING
                          EMBEDDED SYSTEMS LABORATORY CPE0907334
      Labsheet 2: Instruction Set Analysis 2 & Modular Programming
                                Techniques
Name:      Abed el-Rahman Khaled Hamed                                        Student ID:      0164872
Section: 4
Pre-lab) Part 1: Starting up with instructions
Answer the following short questions:
   A) Write the instructions needed to check if the value found in REGA equal to 10.
       Movlw D’10’
       Subwf REGA,0
       Btfss STATUS,Z
   B) Write the instructions needed to check if the value found in REGA equal to zero.
       Mov REGA,F
       Btfss STATUS,Z
(Pre-lab) Part 2: Code Analysis Skills
Answer the following questions regarding Program3 of the experiment @ PAGE 5 and 6:
Each question is independent from the others.
   1. What will the results of the program 3 be when we substitute the instruction @ line 23
      “decfsz counter, F ” with decfsz counter, W ?
          Infinite Loop
   2. Assuming that the PIC runs at an external oscillator speed of 4 MHz? What is the time spent
      in executing the program 3.asm code?
       29 microsecond
                                                                                                    2
(Pre-lab) Part 3: Code Writing Skills
Modify Program1.asm code of the experiment to add this case:
If testNum has the decimal value 10, Result will have the ASCII value ‘E’
include "p16F84A.inc"
cblock 0x25
       testNum
       Result
endc
       org    0x00
Main
       movf testNum, W
       sublw D'10'             ;10d - testNum
        btfsc STATUS,Z
        goto Equal
       btfss STATUS, C
       goto Greater                    ;C = 0, that's B = 1, then testNum > 10
       goto Smaller                    ;C = 1, that's B = 0, then testNum < 10
Greater
       movlw A'G'
       movwf Result
        goto   Finish
Smaller
       movlw A'S'
       movwf Result
       Goto    Finish
Equal
         movlw A'E'
         Movwf Result
Finish
         nop
         end
                                                                                 3
Part4: Code Analysis Skills
Read and simulate the given code Labsheet2.asm and answer the questions which follow:
       Preparing for simulation
       Go to View Menu -> Watch.
       Then from the drop out menu choose the registers you want to watch during simulation
        and click ADD Symbols for each one (Num, Num_7, Num_49).
       Select Debugger ->Select Tool ->MPLAB SIM.
       Simulate the program.
   1. What will be stored in the following Registers when Num has the following values:
                           Value of Num_7 after           Value of Num_49 after
             Num
                        Mul7 subroutine call in Main   Mul49 subroutine call in Main
             0x02              0x0E                              0x62
             0x05              0x23                              0xF5
   2. What is the total number of instructions inside the Mul49 subroutine?
       6 instructions
   3. Where does Mul7 subroutine expect to find its input, where does it store its output?
      Input:       Working
        Output:          Num_7
   4. What is the value at the top of stack when the Mul49 subroutine call instruction executed is?
                           0004
                                                                                                      4
Part 5: Code Writing Skills
In MPLAB, Write a program which converts a number from unpacked BCD format saved in three
registers to one decimal number, assuming that registers names are BCDH, BCDM and BCDL.
BCDH (High Digit of the decimal number) is at location 0x21, BCDM (Mid Digit of the decimal
number) is at location 0x22, BCDL (Low Digit of the decimal number) is at location 0x23, and Result
is at location 0x40, also assume that all BCD numbers are in the valid range of 0 – 9.
                        (Example: BCDH: 2 BCDM: 4 BCDL: 3 Result:’243’d)
Hint: (3) + (4 x10) + (2 x 100) =243, Use modular programming techniques in your code.
You need to simulate your code:
    Preparing for simulation
    Go to View Menu -> Watch.
    Then from the drop down menu choose the following registers you want to watch during
      simulation and click ADD Symbols for each one (BCDH, BCDM, BCDL and Result).
    Select Debugger ->Select Tool ->MPLAB SIM.
    From the watch window, give the registers BCDH, BCDM and BCDL the following values 2, 4
      and 7.
    Simulate the program.
                              Ask your engineer to check the run.