Simulation of The Program (Debugging) : Any Change You Do in Your Program Should Be

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Microlab File 2 – by Joseph Massoud

SIMULATION OF THE PROGRAM (DEBUGGING)

REMINDERS:

 ANY CHANGE YOU DO IN YOUR PROGRAM SHOULD BE


FOLLOWED BY QUICKBUILD ( build succeeded) FOR UPDATE AND
VALIDATION.

 ALWAYS USE CAPITAL LETTERS IN THE PROGRAM

 NOT TO FORGET WRITING END AS A LAST LINE IN YOUR


PROGRAM

A- Preparations for the simulation (watching the results)

1- Open the lab1.asm ( our first example lab) ;


Be sure to have it in non-maximized form (window form) using
maximize/restore-down click.
You may also close all other unused windows.
You stretch your program window to the left and down

1
Microlab File 2 – by Joseph Massoud

We will get the following screen

2- We open the simulator task bar using Debugger/select tool/ MPLAB SIM

2
Microlab File 2 – by Joseph Massoud

The simulator task bar

3- Then we open the “Watch” windows using “View”/ “Watch”

3
Microlab File 2 – by Joseph Massoud

4- We get the following new window; We resize it to a small window

5- We get the following screen; we move the new window to top right of the
screen

4
Microlab File 2 – by Joseph Massoud

6- We have a screen like this;


Then you stretch the watch window more to the right, so it becomes wider

5
Microlab File 2 – by Joseph Massoud

7- Select decimal and binary

We get the following screen

6
Microlab File 2 – by Joseph Massoud

8- We start defining registers we need to watch; we may start by selecting “W”


register (the working register or accumulator).

7
Microlab File 2 – by Joseph Massoud

We will see the line of W register displayed.

8
Microlab File 2 – by Joseph Massoud

9- We repeat the same procedure (select /Add SFR) for: STATUS, TRISB,
TRISD, PORTB, PORTD; we get the following screen.
Note that the order in which registers are shown is not mandatory

9
Microlab File 2 – by Joseph Massoud

10- We still have to add the representation of the memory address 0x25 (H’25’)
which is the memory location of the result in our program.

And we get the line added.

(Note: we can add any number of registers and memory locations that we need to watch
during the execution of the program). In our first program, these were the registers in
use.

10
Microlab File 2 – by Joseph Massoud

11- If we wish to delete a line, we right-click on the line and press delete

11
Microlab File 2 – by Joseph Massoud

B- Step by step simulation

12- Press on the window of the program so it becomes active ; Make a quick
build to be sure the program is error free and build succeeded; close the
window of build and we are back to main screen and ready for simulation.
Adjust the window of the program to be able to see the program.

12
Microlab File 2 – by Joseph Massoud

13- Press reset and the green pointing cursor should point to first line (confi).
If you couldn’t see it, make a quickbuild for the program and then Reset .

13
Microlab File 2 – by Joseph Massoud

14- The pointer stands at the first line ; it means we are ready to execute the first
line ( not yet executed) .
We always have to look at the value of the register involved before and after
the execution of the instruction.
Here the instruction concerns register Status and in particular the
bit RP0 ( bit 5) . RP0= 0 before execution;

To execute one line we press “step into” one time (step into is the step by
step button).
We will see that the instruction was executed ( BSF status,RP0) , and RP0
becomes =1 .

14
Microlab File 2 – by Joseph Massoud

15- Now it is the turn of the second line instruction : MOVLW H’FF’.
It should put FFh ( 1111 1111 ) in W register.
We see first the value of W before execution ( it is = 0x00 =00h=0000 0000).
After execution it will become FF.

I click again one time “step into” button . The instruction will be executed
and W=FF. The pointer moves to the next line.

15
Microlab File 2 – by Joseph Massoud

16- The third instruction is MOVWF TRISB; it should copy W value into
register TRISB;
The content of TRISB will become FF.
However, if we look before we execute, we see that TRISB by default is equal
to FF.
So after executing the instruction, the value of TRISB will remain FF because
the micro will write FF also in it.

16
Microlab File 2 – by Joseph Massoud

17- The forth instruction loads W with 00h (MOVLW H’00’);


Before the execution Wreg was still equal to FF ( as per it previous value).
After execution ( step into) , Wreg=00.
The fifth instruction moves W to TRISD.
Before execution TRISD=FF; After execution it will become equal to 00.

17
Microlab File 2 – by Joseph Massoud

18- The sixth instruction is BCF status,RP0; it will put 0 again in RP0 .
We continue the step by step execution ( and watch at each line the changes),
till we reach the last line ( LOOP GOTO LOOP) ; Then we will see that the
program will be looped to this line no matter how much we pressed step into.
This is because the instruction GOTO takes the program to the line specified,
and which is the same line here.
The PORTD will contain 09, and the memory result (address 0x25=25h) will
contain also 09.
The final watch screen will be as follows:

18
Microlab File 2 – by Joseph Massoud

C- Assignment 2 ( you may screen shot your results and save them)

19- Using same programs done in file 1 ( previous assignments):

GOLDEN REMARK :

Every time we change any line or letter in a program we should quickbuild the
program to validate the change; Otherwise the simulator will disregard the change and
execute the previous program.

a) Open lab12.asm ; make the step by step simulation and check the results on PORTD
and in memory location H’26’. It should show 19 in decimal ( and 13 in Hexa).

b) Open lab13.asm ; make the step by step simulation and check the results on PORTD
and in memory location H’27’. It should show 07 in decimal and Hexa.

c) Open lab14.asm ; make the step by step simulation and check the results on PORTD
and in memory location H’28’. It should show 11 in decimal (and 0B in Hexa.)

D- FULL program simulation ( instead of step by step)

20- Using Animation function

Close MPlab and open it again. Open the file lab1.asm .We are now in step 13 ;
( we open again the lab1.asm and prepare the watch window). We click Reset and we
check that the pointer indicates the first line of the program (if it doesn’t show we make a
quick build ).

Instead of using “step into” , we click on animate button which comes with double blue

arrows ( and not the single arrow). We will see that MPLAB will run through the
whole program and will see the same end results. We press pause when we reach
the last instruction.

E- Assignment 3
21- Using Full program animation( you may screen shot results and save them)

Repeat simulation of the 3 programs of assignment 2 using animate operation instead of


step into.

19

You might also like