Академический Документы
Профессиональный Документы
Культура Документы
(a) (b)
Figure 1
1
Beside from the executes feature as if you were running it on a real 68K
microprocessor, the Simulator has Debugging features which include Single Step,
Trace, advanced Breakpoints.
The Single Step feature allows you to execute a single instruction at a time, and to
observe the state of simulated registers after the execution of each instruction.
The Trace feature allows you to execute the program in a slow motion manner such
that you monitor the sequence of instruction being executed.
INSTRUCTION
A. Running the EASY68K from windows.
Theory
We need to use an text editor to write a program. In rthis Lab we are going to use the
EASY68K editor
Instruction
To begin a session, run the program EDIT68K.exe from the START|All Program|
EASY68K|Easy68K selection using the mouse.
When you run EASY68K you see the following screen.
This code in this window provides a template for your own program. You can erase
this code and start again or you can use it. Note that the provided code gives you the
beginning and end of a program.
This code puts your program in memory at 100016. The END assembler directive has
the label 'START' which point to the beginning of the program (i.e., at address $1000).
You must not put data here (i.e., immediately after the ORG statement! The first line
after START must be a valid 68K instruction.
2
B. Writing a 68K program
Write the following program using the EASy68K editor. The program will add five
numbers in a array labeled as LIST, using indexed addressing. Characters in bold are
original in the template. The START labeled has been moved.
*-----------------------------------------------------------
* Program :PROG1.X86
* Written by :Zuraimi bin Yahya
* Date :9/6/08
* Description: Introduction to 68K programming
*-----------------------------------------------------------
ORG $1000
The following picture shows the effect of entering this code into the editor.
3
D. Assembling the 68K program
Theory
Before you can run a program you will need to assemble the source file to build an
executable file which contains the machine code of the program which is
understandable by the microprocessor. The executable file recognizable by
EASY68K is a text file which contain the machine code of the program is S-format
code.
Instruction
To assemble the code, click on 'Project' then click on 'Assemble Source' in the pull-
down menu. This will invoke the assembler. The code will either assemble
successfully with no errors, or unsuccessfully with one or more errors. If you have an
error, you have to re-edit your code and then assemble it again. You repeat this step
until you have no errors.
4
When you click the Assemble button, the editor will open a Save As dialog box. Note
that the default directory to save is at C:\EASY68K\Examples. Name the file for the
program as PROG1. By default it will be saved as PROG1.X68 which is the source
file. The following diagram is a picture of the situation after we have successfully
assembled the code and we are about to click on 'Execute' to invoke the simulator.
This is the
screen with the
'no errors'
message.
Note that two other files is also created in the same directory which are PROG1.L68
and PROG1.S68. The former is the list file and the latter is the binary file in S-format
version.
If you open a command prompt window and executes the following instruction you
will get the following display indicating that the listing file and object file has been
created.
Make sure that the latter two files are dated later or equal to the date of source file.
Earlier date means that the latter two files were not assembled from the current source
file.
Click the button, the editor executes the simulator and load PROG1. At
this stage, what you will see is:
The simulated
registers
Set the Program Counter (PC) to the desired address. By default, it will be set to the
starting address of the program. You may also change any of the 68000's other
registers at any time while the simulator is in Stop or Pause mode.
All numbers in the registers are displayed using Hexadecimal notation except the
Status Register which is in Binary.
6
D0= ... D7= Data registers
A0= ... A7= Address registers
SR= Status register
US= User Stack (The user stack is the same as A7 when the S bit in the Status Register
is set to 0).
SS= System Stack (The system stack is the same as A7 when the S bit in the Status
Register is set to 1).
PC= Program Counter
7
F. Single Stepping through the program
Theory
Single stepping will allow you to understand what an instruction does, how the
program flow is, and in the end debug the program if you want to find out why it does
not work.
Instruction
You can click the Step-Over button to use the Single-Step feature to execute the code
line-by-line (i.e., instruction-by-instruction) and observe the execution of the program
and see the contents of the registers. Note the value of PC=00001000 which is equal
to the address of START. PC equals the address of start because of the assembler
directive END START.
8
Click once on the Step Over button and you will see the following display.
9
Table 1.
Trace Registers involved in program CCR Remarks
number PC A0 D0 D1 X N Z V C
0 00001000 0 0 0 0 0
10
Table 2. Filled tracing table for PROG1.
Trace Registers involved in program CCR Remarks
number PC A0 D0 D1 X N Z V C
0 00001000 0 0 0 0 0
1 00001006 0000101E Point to data #0 in array
2 0000100A 00000005 0 0 0 0 0 Set counter
3 0000100C 00000000 0 0 1 0 0 Clear accumulator
4 0000100E 00000001 0 0 0 0 0 1st data accumulated
5 00001014 0000101F 0 0 0 0 0 Point to SECOND data in array
6 00001016 00000004 0 0 0 0 0 Decrement D0
7 00001018 Z=0 BNE Condition TRUE; PC=PC+0ffset
0000100C =00001018+ FFFFFFFC = 0000100C
8 0000100E 00000005 0 0 0 0 0 2nd data accumulated
9 00001014 00001020 Point to 3rd data in array
10 00001016 00000003 0 0 0 0 0 Decrement D0
11 00001018 Z=0 BNE Condition TRUE; PC=PC+0ffset
0000100C =00001018+ FFFFFFFC = 0000100C
12 0000100E 00000008 0 0 0 0 0 3rd data accumulated
13 00001014 00001021 Point to 4th data in array
14 00001016 00000002 0 0 0 0 0 Decrement D0
15 00001018 Z=0 BNE Condition TRUE; PC=PC+0ffset
0000100C =00001018+ FFFFFFFC = 0000100C
16 0000100E 0000000E 0 0 0 0 0 4th data accumulated
17 00001014 00001022 Point to 5th data in array
18 00001016 00000001 0 0 0 0 0 Decrement D0
19 00001018 Z=0 BNE Condition TRUE; PC=PC+0ffset
0000100C =00001018+ FFFFFFFC = 0000100C
20 0000100E 00000015 0 0 0 0 0 4th data accumulated
21 00001014 00001023 Point to 5th data in array
22 00001016 00000000 0 0 1 0 0 Decrement D0
23 00001018 Z=1 BNE Condition False; PC is not altered
24 0000101C 00000009 0 0 0 0 0 Set for function 9 of trap 15
11
12
G. Using Breakpoints
Theory
A breakpoint is a point in the code at which execution stops and the simulated registers are
displayed. You can run the code (execution taking place at high speed invisibly) until the
program counter reaches the breakpoint at which the simulation stops. We use breakpoint if
we want to see a condition in a program at that breakpoint but we do not want to single-step
through it because it may take time.
To open a break point dialog box, select View|Breakpoint and you will see the following
display.
In EASY68K you can set a breakpoint or many breakpoints if the processor meets a certain
condition in register, memory which can be declared in the dialog box.
Note: The following information is applicable if you want to set complex breakpoint
application
Once clicked, the line will fill in with numerous drop-down and input boxes.
The Op selection sets the type of comparison. (greater than, less than, equal
to, etc.)
The Size specifies the size for the comparison. (byte, word, or longword)
13
The Address selection specifies address in memory to be tested.
The Op selection sets the type of comparison. (greater than, less than, equal to, etc.)
NOTE: The N/A selection causes the comparison to always be true.
The Value selection sets the value to be compared to the location in memory.
The Size specifies the size for the comparison. (byte, word, or longword)
R/W - Break will only occur on read or write while the comparison is true.
Read - Break will only occur on read and when comparison is true.
Write - Break will only occur on write and when comparison is true.
After you have finished inputting information, you must hit the SET button, or
the line you just inputted will be deleted.
===Setting-up conditions===
Also, once you have done these steps, your Break Points are NOT
functional. You must use the conditions you have created in the
Expression Builder to activate them.
The Count column specifies how many times the expression must be
true before breaking.
=Expression buttons=
14
PC/Reg - Inserts a condition defined earlier in the Registers section
into the current position in the Expression column. The number of the
condition inserted is specified by the digits to the right of the button.
After you have finished inputting information, you must hit the SET
button, or the line you just inputted will be deleted.
Now, your Break Points are active as long as you have set the Enabled
column to On. You may change information in the Registers, Memory, or
Expression Builder sections by double clicking on the line you want to
change.
For ease of understanding, in this lab we are going to set only one break point and we are
going to use the PC to breakpoint at an address.
Instruction
You must Reset the simulator by selecting RUN|Reset Program
1. We are going to set the breakpoint at address 00001018
To begin setting up a breakpoint, double click on an empty line in Registers section. Select
PC, chose the OP as “==” set at 00001018 , , and press the Set button. This will set the
condition that when the program is executed, it will stop (break) if it meet the condition
PC=00001018. In the program PROG1.L68 it is at the instruction “MOVE.B #9,D0”
15
2. Then we are going to enable the breakpoint
To do so, on the Expression Builder set Enable ON, Click the PC/Reg button and
Click the set Button
16
3, Run the program from PC which is $00001000 and you will find that it stops at
address $00001018, the breakpoint address that we set. What you have encountered is
that we can set the EASY68K simulator to stop at any address that we want. Then we
can inspect registes or memory at that location if we want to, or proceed further by
either single stepping setting another breakpoint or just Run.
Note that the value of A0, D0 and D1 at this breakpoint is the same as you have
determined in table 1.
17
QUESTIONS
1. What register in the program is used to determine the number of loop the instruction
“bne loop” will encounter?
2. On what condition do “bne loop” exit from the loop?
3. What is the register that accumulates the sum of the number stored in array List?
4. What is the register used to point to the data in List?
5. Give the scenario when you would use single-step, break-point or just Run the
Program.
18