Instructor: Rob Nash
Readings: Chap 7-9
Midterm next Monday!
◦ Review this Wednesday
◦ You will see code again…
Lets declare a message to display to the world
org $600 *start of data
HMSG DC.B 'Hello!'
EOM DC.B 0 *eom
end $400
A way to get the attention of the CPU in an
asynronous manner without polling
Also referred to as Traps, we’ll be interested
in the following
◦ Trap #3 *prints out what is pointed to by A3
◦ Trap #9 *ends the program (convention)
ORG $400
MOVEA.L #HMSG, A3
TRAP #3
TRAP #9
ORG $600 *start of data
HMSG DC.B 'Hello!'
DC.B 0 *eom
END $400
FTOC SUBI.W #32, D0
MULS#5, D0
DIVS #9, D0
RTS
See p.28, section 2.6
If register D3 contains 100030FF and register
D4 contains 8E552900, what is the result of
MOVE.W D3, D4?
8E5530FF
MOVE.L D3, D4?
What if I wanted to move the upper half?
A word op, so the upper half of D4 remains
constant. The lower half will be loaded as
follows: 8E5530FF
What will A2 contain after the execution of
MOVEA.L A5,A2
Note that, even though the address registers are
32 bits long, only the lower 24 are used to
address memory in the 68K
◦ There are no external address lines for the upper 8 bits!
So, if A0 contains 00007F00, what happens when
executing:
◦ MOVE.B (A0), D7
0x007F00 holds “0009”
D7 contains 1234FEDC
D7 contains 1234FE09
This implements a pop
◦ Use the value, then increment (pop off stack)
◦ The stack grows to lower addresses, shrinks to
higher addrs
A5 : 0x00007F00
D2 : 0x4E4F2000
0x007EFF : 3C
0x007F00 : 09
0x007F01 : BA
MOVE.W (A5)+, D2
Use what A5 is pointing to, then decrement
◦ A5 thus looks up 7F00
Since a word operation, post decrement by 2
◦ A5 is now 0x007F02
This implements a push
◦ Decrement our stack first to make space
◦ Then overwrite this new location with our data
Stacks shrink “downwards”, or to higher addresses
Relocatable code is critically important today,
and compilers provide this type of code
automatically
Contrast this to code with all absolute
memory locations specified – how do we
shuffle this around in memory?
A2: 0x007F00
D4: F3052BC9
//Mem
0x007EFF : 3C
0x007F00 : 09
0x007F01 : BA
MOVE.B –(A2),D4
MOVE.B D4, -(A2) *push
Answer:
Decrement A2 first, so 0x007EFF
Copy from that location into the lower byte of
D4
MOVE.B D3, (A5)+
00 01 101 011 000 011 => 0x1AC3
MOVE .B 5 for A5 Mode (An)+ Mode Dn 3 (D3)
Dest (ea) Source (ea)
Trap #3, Address in A3 of string
Trap #15
◦ D0 holds the “task number”
2 is for user input, A1 points to this for you
0 is for terminal output
◦ A1 holds the memory addr of the start of string
◦ D1 holds the length of the str to print
What does this code look like in ASM?
adder( int x, int y) {
◦ int z;
◦ z = x + y;
}
*assuming D0 holds x, D1 holds y, D2 is z
adder AND.W #0, D2
ADD.W D0, D2
ADD.W D1, D2
RTS
We wanted to compare two lists of bytes?
A1 points to the first list
A2 points to the second list
Each list is 5 elements long
D0 holds 0 if different, 1 if identical.
For 2 reapers!!
What does the asm look like for the
following?
branch( int a, int b) {
◦ if( a > b ) {
b=a
◦ } else {
a=b
◦ }
}
Write an ASM module that defines two (3x3)
matrices and sums up the first row
Data section:
What does the following code look like in
ASM?
◦ for(int a = 0; a < 10; a++ ) {
nop
◦ }
Implement the overriding feature of
inheritance at the ASM level
Data Section holds a VTable
◦ A table of function pointers
◦ To override a function, we’ll need to update its table
entry
◦ I’ll give you the table in A0
◦ The offset of the function to override in D0 (in longs)
◦ The address of the new function in A1
What is a good HW problem for us to
consider?