You are on page 1of 29

20-Jul-16

4.0 Machine Structure and


Instruction format in MC 68000
4.1 MC 68000
4.2 Memory
4.3 Register
4.4 Operand Size
4.5 Instruction Format
4.6 Addressing Mode
4.7 Instruction Translation

4.1 MC 68000

20-Jul-16

4.1 MC 68000

4.1 MC 68000
Has 68000 number for transistors
Size 6.24 by 7.14 mm
Clock speed (controlled by the clock generator): 4
MHz to 12.5 MHz

20-Jul-16

4.1 MC 68000

4.1 MC 68000

The Macintosh Classic (1990)


Processor: 16-bit Motorola 68000 at 8 MHz
Operating system written entirely in Assembly for the MC 68000. Later versions on the MC 68000 is
written in the high-level language Pascal

20-Jul-16

4.1 MC 68000

The MacBook Pro (2006)


Processor: 64-bit Intel Core 2 Duo 2.6 GHz x86-64 (specification varies between builds)
Operating system written in high-level languages. They are Objective C, kernel in C, and I/O
subsystem in C++. The source codes are compiled to run on Intel or the PowerPC processors
Processor emulators are used to run applications compiled or assembled for different processors
that the Mac had used before

4.2 Memory
Has 16777216 memory slots
The address starts at 0x000000 to 0xFFFFFF
Or 0 to 167777215
Each memory slots can store 8 bits
So total memory is 16777216 * 8 bits = 16 MB

20-Jul-16

4.2 Memory

The first 16 KB in memory (0x000000 to 0x003FFF) is the RAM


The next 44 KB is empty space (0x004000 to 0x00EFFF)
The next 4 KB is for ROM (0x00F000 to 0x00FFFF)
So total reserved memory is in the first 64 KB of memory (16 KB +
44 KB + 4 KB = 64 KB)

4.3 Register

4.3.1 Data Registers


4.3.2 Address Registers
4.3.3 User Stack Pointer (USP)
4.3.4 Supervisor Stack Pointer (SSP)
4.3.5 Program Counter (PC)
4.3.6 Status Register (SR)

20-Jul-16

4.3 Register

A register in a processor also known as the cache is used to store small


amounts of data
These data can be accessed and processed real quick compared to
accessing in RAM or in the storage device
In the MC 68000 there are 19 registers totaling to 16 MB
There are also an area reserved for I/O space
The processor uses a 16-bit bus to connect all of the registers together
Even though the registers can store 32-bits at a time, since the bus is only
16-bit the CPU can only manipulate 8 or 16 bit in a cycle
So this means, to store 32 bits into a register or memory, the CPU will
require 2 cycles
An exception to the rule are the bus connecting to the Program Counter,
User Stack Pointer, and the Supervisor Stack Pointer
They use a 24-bit bus
Another thing about 32-bit registers, it turns out the Status Register can
only store 16 bits

4.3 Register
MC 68000 available
registers
Also known as the 68000
Programmers Model
We will look at each type
in the following slides

20-Jul-16

4.3.1 Data Registers


For the MC 68000, there are 8 data registers
Data in these registers are subjected to logic and
arithmetical operations
Data registers are named D0 to D7
They can hold 32 bits (0 to 31) of data
The Assembly instructions operate on 8, 16 or 32 bits of
data
Affected bits: 8-bit (0 7), 16-bit (0 15), 32-bit (0 31)

4.3.2 Address Registers


Address registers are used to store the
memory address that will be fetch into the
CPU
It is also used to obtain data pointed by the
address or to store data
Available address registers are from A0 to A6

20-Jul-16

4.3.3 User Stack Pointer (USP)


User Stack Pointer (USP) or A7 has the same
purpose and characteristics as the normal
address register as shown in 4.3.2
Bus: 24-bit wide

4.3.4 Supervisor Stack Pointer (SSP)


Supervisor Stack Pointer (SSP) or A7 has the
same purpose and characteristics as the
normal address register as shown in 4.3.2
Bus: 24-bit wide

20-Jul-16

4.3.5 Program Counter (PC)


Stores address on where is the next
instruction is
Bus: 24-bit wide

4.3.6 Status Register (SR)


All of the registers that we have seen are 32 bits
long
The Status Register or SR are actually 16 bit long
Divided into User Byte or CCR and System Byte
The CCR or User Byte contains the carry bit (C),
overflow bit (V), zero bit (Z), and extended bit (X)
which is a modified version of the carry bit used
only for multi-precision arithmetic operations
All of this allows for additional operations to be
performed on data

20-Jul-16

4.4 Operand Size


Operand are items that are going to be operated on.
Example: 2+2, 2 are the operands, + is the operator
The MC 68000 operates on 8, 16 and 32 bit data
This means that it can process data types like byte (B) (8
bit), word (W) (16 bit), long word (L) (32 bit)
- Move.B D1,D2 Byte operation (8 bits)
- Move.W D1,D2 Word operation (16 bits)
- Move.L D1,D2 Long word operation (32 bits)
Note that if there is know data type declared, then the
default is W
- Move D1,D2 Word operation (16 bits)
Consider the clear (CLR) operator in the next slide and how
it affects the bits contained in a data register

4.4 Operand Size


CLR.W D3
Since its a word operation, only the first 16 bits
will be affected

Hence the output will be


The same applies to byte and long word which
the first 8 and 32 bits are affected respectively

10

20-Jul-16

4.5 Instruction Format

4.5.1 No operand
4.5.2 One operand
4.5.3 Two operand
4.5.4 Branch instruction

4.5 Instruction Format


<label> opcode<.field> <operands> <;comments>

label points to a the instructions


memory location
opcode operation code (MOVE, ADD)
.field width of operand (B, W, L)
operands data used in the operation
;comments for program documentation

11

20-Jul-16

4.5.1 No operand
<label> opcode<.field> <operands> <;comments>

Description: Returns to the starting point of


the program
The code has only an operator code and
nothing else
RTS

4.5.2 One operand


<label> opcode<.field> <operands> <;comments>

Description: Halts or pauses the program


The code has only one operator and one
operand
TRAP #15

12

20-Jul-16

4.5.3 Two operand


<label> opcode<.field> <operands> <;comments>

Description: Moves 32 bits from one register


to another (from D1 to D3)
This code has an operator and 2 operands
MOVE.L D1,D3

4.5.4 Branch instruction


A branch instruction is like an if-else statement in
C
It executes a certain function based on the
condition
There are a few more branching instructions but
here are the most used ones:
- 4.5.4.1 BNE
- 4.5.4.2 BRA
- 4.5.4.3 BEQ
- 4.5.4.4 BCC

13

20-Jul-16

4.5.4.1 BNE
The BNE instruction means that a statement
will always be executed until a condition is
met
<label> opcode<.field> <operands> <;comments>
LOOPY MOVE D1,D2
...
BNE LOOPY

4.5.4.2 BRA
The BRA instruction means that a statement
will always be executed. To stop the execution,
use another branching instruction like BNE
<label> opcode<.field> <operands> <;comments>
LOOPY MOVE D1,D2
...
BRA LOOPY

14

20-Jul-16

4.5.4.3 BEQ
The BEQ instruction means that a statement
will be executed if the condition is met
<label> opcode<.field> <operands> <;comments>
LOOPY MOVE D1,D2
...
BEQ LOOPY

4.5.4.4 BCC
The BCC instruction means that a statement
will be executed if the last statement
produced the carry bit (the C in XNZVC from
the Status Register in slide 18)
<label> opcode<.field> <operands> <;comments>
LOOPY MOVE D1,D2
...
BCC LOOPY

15

20-Jul-16

4.6 Addressing Mode


Addressing modes specify how to identify the
operands of each instruction
In the MC 68000, there are 13 modes
You should study all of them but focus on the
first 7 (Data Register Direct to Predecrement
Register Indirect)
See next slide for the list of addressing modes

4.6 Addressing Mode

16

20-Jul-16

4.6 Addressing Mode


Before understanding the addressing modes,
it helps to know where does all the types of
registers are, and the memory is actually
located on the physical microchip
The next slide shows a simplified diagram of of
how everything is connected

4.6 Addressing Mode

CU is the Control Unit This is where everything is coordinated


ALU is the Arithmetic Logic Unit Where basic calculations are done (true,
false, comparisons, basic arithmetic)
mem The memory where your ASM program is loaded in to
Dn Data registers where data are stored
An Adress registers where address of memory locations are stored
Or Some other types of registers (see slide 12)
Everything is connected to the Control Unit

17

20-Jul-16

4.6 Addressing Mode

4.6 Addressing Mode

18

20-Jul-16

4.6 Addressing Mode

4.6 Addressing Mode

19

20-Jul-16

4.6 Addressing Mode

4.6 Addressing Mode

20

20-Jul-16

4.6 Addressing Mode

4.6 Addressing Mode

21

20-Jul-16

4.6 Addressing Mode

4.6 Addressing Mode

22

20-Jul-16

4.6 Addressing Mode

4.6 Addressing Mode

23

20-Jul-16

4.7 Instruction Translation


4.7.1 Introduction
4.7.2 Translation Example
4.7.3 Instruction Manual

4.7.1 Introduction
The Assembly instruction that you type must
first be converted into object code before it
can be executed
The object code is in binary but for
convenience, it is shown in hexadecimal
format by the Assembler
The object code is shown in the next slide

24

20-Jul-16

4.7.1 Introduction
The image below shows the Assembly code MOVE.B #9,D0
It also shows the translated machine or object code but in hex
format that is ready to be executed by the processor (103C 0009)
If it were to be shown in binary, it will look like this:
0001 0000 0011 1100 0000 0000 0000 1001
As you can see, showing the object code in its true form (in binary)
is really inconvenient so the hex format is used instead
But the processor uses the binary format. The hex format is for
human representation only

4.7.2 Translation Example


We will translate the MOVE instruction into machine code
There is a large number of instructions that the MC 68000
understand and there is a manual for each instruction
The manual will look like the next 2 slides. You use the
manual to help convert the Assembly instruction into
machine code
You do not need to memorize all of the manuals. The
manual will be given at the back of your final exam papers
You only need to know how to use it to answer the
question
The manual that will be shown next is for the MOVE
instruction

25

20-Jul-16

4.7.2 Translation Example

4.7.2 Translation Example

26

20-Jul-16

4.7.2 Translation Example


One more thing is that the object code consist
of 2 parts
The first part contains the information like the
opcode, operation size, the source and
destination and also the addressing mode
The second part contains the data or operand
Consider the assembly instruction:
MOVE.L #$12,D0

PDF 61/646 MC68000 PRM.PDF

4.7.2 Translation Example

27

20-Jul-16

4.7.2 Translation Example


MOVE.L #$12,D0

4.7.2 Translation Example

Hence the first part of the code is


00 10 000 000 111 100
Rearrange and group into 4 digits
0010 0000 0011 1100
Then convert into hex, it becomes
203C
The second part is the data, #$12
Since it is already in hex as denoted by the $
symbol then you can use it directly as 00000012.
The 6 zeros are there because the total digits is
8 as the operation size is long
So combining both parts it becomes
203C 00000012 in hex or
0010 0000 0011 1100 0000 0000 0000 0000 0000 0000
0001 0010 in binary

28

20-Jul-16

4.7.3 Instruction Manual

These are the common instructions that are used during the final exam
The MOVE, MOVEA, and TRAP are the most basic ones and will always come out in
the exam
They are basic because they are used even in the most simplest of Assembly
programs. They are used in programs that are simple as a program that simply
displays the sentence Hello World!
So make sure that you are familiar with them
The list of common instructions are:
BRA
ADD
MOVE
MOVEA
SUBQ
TRAP
BCC
SUBI

4.7.3 Instruction Manual


The instruction manual for every single instructions
that the MC 68000 can understand is in the file 02
MC68000 PRM.pdf
Just read the common ones that are listed in slide 57
To test your skill of translating ASM code into machine
code, write a program in ASM in the Easy68K using the
instructions available in slide 57 and run it
Compare the object code generated by the Easy68K
and with the one you did on pen and paper

29

You might also like