instructor: rob nash readings: chap 7-9 midterm next monday! ◦ review this wednesday ◦ you...
TRANSCRIPT
Instructor: Rob Nash Readings: Chap 7-9
Midterm next Monday! ◦ Review this Wednesday◦ You will see code again…
Programming for the 68K
Lets declare a message to display to the world
org $600 *start of dataHMSG DC.B 'Hello!'EOM DC.B 0 *eom
end $400
Hello World
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)
Useful Interrupts
ORG $400MOVEA.L #HMSG, A3TRAP #3TRAP #9
ORG $600 *start of dataHMSG DC.B 'Hello!'
DC.B 0 *eom
END $400
Back to Hello World
FTOC SUBI.W #32, D0MULS #5, D0DIVS #9, D0RTS
FTOC Example
See p.28, section 2.6
68K V.S. 8086
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?
Consider…
A word op, so the upper half of D4 remains constant. The lower half will be loaded as follows: 8E5530FF
Answer
What will A2 contain after the execution of MOVEA.L A5,A2
Query
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
Notes
D7 contains 1234FE09
Answer
This implements a pop ◦ Use the value, then increment (pop off stack)◦ The stack grows to lower addresses, shrinks to
higher addrs
Address Register Indirect w PostIncrement
A5 : 0x00007F00 D2 : 0x4E4F2000
0x007EFF : 3C 0x007F00 : 09 0x007F01 : BA
MOVE.W (A5)+, D2
Predecrement
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
D2 : 4E4F09BA
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
Address Register Indirect w PreDecrement
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?
With Displacement
A2: 0x007F00 D4: F3052BC9
//Mem 0x007EFF : 3C 0x007F00 : 09 0x007F01 : BA
MOVE.B –(A2),D4
MOVE.B D4, -(A2) *push
Indirect with Predecrement
Answer: Decrement A2 first, so 0x007EFF Copy from that location into the lower byte
of D4
D4 : F3052B3C
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)
How the Assembler => Binary
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
User Input
What does this code look like in ASM?
adder( int x, int y) {◦ int z;◦ z = x + y;
}
Query
*assuming D0 holds x, D1 holds y, D2 is z
adder AND.W #0, D2ADD.W D0, D2ADD.W D1, D2RTS
Answer
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!!
Sample Problem #1: What If?
What does the asm look like for the following?
branch( int a, int b) {◦ if( a > b ) {
b = a◦ } else {
a = b◦ }
}
Query
Write an ASM module that defines two (3x3) matrices and sums up the first row
Data section:
Sample Problem #2
What does the following code look like in ASM?
◦ for(int a = 0; a < 10; a++ ) { nop
◦ }
Query
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
Sample Problem #3
What is a good HW problem for us to consider?
HW problem