28
Instructor: Rob Nash Readings: Chap 7-9 Midterm next Monday! Review this Wednesday You will see code again… Programming for the 68K

Programming for the 68K

  • Upload
    dava

  • View
    64

  • Download
    2

Embed Size (px)

DESCRIPTION

Programming for the 68K. Instructor: Rob Nash Readings: Chap 7-9 Midterm next Monday! Review this Wednesday You will see code again…. Hello World. Lets declare a message to display to the world org $600 *start of data HMSGDC.B'Hello!' EOMDC.B0 * eom end $400. - PowerPoint PPT Presentation

Citation preview

Page 1: Programming for the 68K

Instructor: Rob Nash Readings: Chap 7-9

Midterm next Monday! ◦ Review this Wednesday◦ You will see code again…

Programming for the 68K

Page 2: 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

Page 3: Programming for the 68K

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

Page 4: Programming for the 68K

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

Page 5: Programming for the 68K

FTOC SUBI.W #32, D0MULS #5, D0DIVS #9, D0RTS

FTOC Example

Page 6: Programming for the 68K

See p.28, section 2.6

68K V.S. 8086

Page 7: Programming for the 68K

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…

Page 8: Programming for the 68K

A word op, so the upper half of D4 remains constant. The lower half will be loaded as follows: 8E5530FF

Answer

Page 9: Programming for the 68K

What will A2 contain after the execution of MOVEA.L A5,A2

Query

Page 10: Programming for the 68K

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

Page 11: Programming for the 68K

D7 contains 1234FE09

Answer

Page 12: Programming for the 68K

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

Page 13: Programming for the 68K

A5 : 0x00007F00 D2 : 0x4E4F2000

0x007EFF : 3C 0x007F00 : 09 0x007F01 : BA

MOVE.W (A5)+, D2

Predecrement

Page 14: Programming for the 68K

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

Page 15: Programming for the 68K

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

Page 16: Programming for the 68K

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

Page 17: Programming for the 68K

A2: 0x007F00 D4: F3052BC9

//Mem 0x007EFF : 3C 0x007F00 : 09 0x007F01 : BA

MOVE.B –(A2),D4

MOVE.B D4, -(A2) *push

Indirect with Predecrement

Page 18: Programming for the 68K

Answer: Decrement A2 first, so 0x007EFF Copy from that location into the lower byte

of D4

D4 : F3052B3C

Page 19: Programming for the 68K

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

Page 20: Programming for the 68K

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

Page 21: Programming for the 68K

What does this code look like in ASM?

adder( int x, int y) {◦ int z;◦ z = x + y;

}

Query

Page 22: Programming for the 68K

*assuming D0 holds x, D1 holds y, D2 is z

adder AND.W #0, D2ADD.W D0, D2ADD.W D1, D2RTS

Answer

Page 23: Programming for the 68K

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?

Page 24: Programming for the 68K

What does the asm look like for the following?

branch( int a, int b) {◦ if( a > b ) {

b = a◦ } else {

a = b◦ }

}

Query

Page 25: Programming for the 68K

Write an ASM module that defines two (3x3) matrices and sums up the first row

Data section:

Sample Problem #2

Page 26: Programming for the 68K

What does the following code look like in ASM?

◦ for(int a = 0; a < 10; a++ ) { nop

◦ }

Query

Page 27: Programming for the 68K

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

Page 28: Programming for the 68K

What is a good HW problem for us to consider?

HW problem