Sie sind auf Seite 1von 18

Laboratory 1

TITLE: Using the EASy68K Cross Assembler and Simulator


Equipment: Window XP/Vista System
Software: EASY68K Integrated Development Environment Software
Reference: EASy68K Quick Reference v1.7
THEORY:
EASy68K has an editor, a cross-assembler and an simulator for the Motorola 68000
CPU that run on Windows Operating System and Intel architecture. It is used to write
and executes programs for the Motorola M68k architecture without extra hardware.
The editor/assembler and simulator have GUI interfaces. The editor allows multiple
files to be edited. The assembler supports structured assembly (IF, WHILE, REPEAT,
FOR), macros with conditional assembly and many assembler directives. The
simulator supports Text and File I/O, Graphics and Sound.
The editor allows you to write a 68K assembly language program.
The cross-assembler assembles the program into 68K binary code on an IBM PC.
The simulator emulates a Motorola M68000 microprocessor system with the default
memory map shown if Figure 1(a) and simulate the hardware shown in Figure 1(b).
The memory map of the hardware can be changed by the user.
7100

(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

START LEA List,A0 ;A0 is set to point at the list


MOVE.B #5,D0 ;Use D0 as a loop counter and set it to 5
CLR.B D1 ,;Clear the total in D1 before we start
Loop ADD.B (A0),D1 ;Add the number pointed at by A0 to D1
ADD.L #1,A0 ;Point to the next number in the list
SUB.B #1,D0 ;Decrement the counter
BNE Loop ,;If we haven't reached zero, go round again
MOVE.B #9,D0
TRAP #15 ;Halt Simulator
List DC.B 1,4,3,6,7 ;here's the data to add.
END START

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.

Click on the Project tab to


get the 'Assemble Source'
menu. Select this.

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.

You click on the


'Execute' message
to execute
EASY68K
simulator.

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.

This is the screen with


the 'no errors' message.

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.

5 You click on the 'Execute' message to


begin running your program.
E. Running the EASY68K simulator
Theory
In a normal case you will need to upload the executable file of a program to the
memory of a processor before you can run the program. EASY68K integrates this
process when you click the button. It will load the machine code of the
program from the S-format file on address location declared in the S-format file. The
initial PC of the program is also declared in the S-format file.
Instruction

Click the button, the editor executes the simulator and load PROG1. At
this stage, what you will see is:

The simulated
registers

The first line of the code


pointed by PC declared
by the
END START directive

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.

The registers displayed are as follows:

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.

Clicking on this Step Over


button executes a single
instruction and shows the
state of all registers after the
execution of that instruction.

8
Click once on the Step Over button and you will see the following display.

Check on the simulated registers


Note the value of PC=00001006 which is equal to the address of next instruction after
single-stepping.
Note that Register A0 has changed to because the instruction 0000101E because
the instruction “LEA List,A0” load the address of List into A0.
Single step to the program until you reach the Halt Simulator instruction and fill the
table 1.
Do not fill unknown or unaffected register to allow better visualization of changed
registers. At trace #0, PC will equal to the address of the first instruction of program
which label given in the parameter of the END directive. In the program PROG1, at
trace #0, PC equals the address of START.
Remark can be filled with information about the execution of the instruction if
necessary. Note that the program will do 5 loops until D0=000000, which causes Z=0
and the BNE Loop instruction is false. Note also D1 accumulate the sum of byte size
data in the List array (as A1 increments).
Compare your tracing table with Table 2

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.

=Columns in the Registers section=

The PC/Reg column specifies the register to be tested.

The Op selection sets the type of comparison. (greater than, less than, equal
to, etc.)

The Value selection sets the value to be compared to the register.

The Size specifies the size for the comparison. (byte, word, or longword)

=Columns in the Memory section=

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)

The R/W selection has four choices:

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.

N/A - Break will occur if 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.

===Using the Expression Builder===

To begin creating an expression, double-click on an empty row.

=Columns in the Expression Builder=

Set the Enabled column to On to activate the Break Point. Set it to


Off to prevent the Break Point from occurring.

The Expression column stores an expression containing the conditions


you created earlier along with optional logical operators. These
conditions and optional logical operators are entered by clicking the
PC/Reg, Memory, And, Or, (, and ) buttons which are described
below.

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.

Memory - Inserts a condition defined earlier in the Memory 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.

And / Or buttons - Inserts a logical operator into the Expression


column.

( / ) buttons - Groups part(s) of an expression together.

Backspace - Removes the last change made to the current Expression.

=Finalizing Expression Builder=

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.

Proceed single-stepping until the end of the program.

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

Das könnte Ihnen auch gefallen