1 / 28

Programming for the 68K

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 HMSG DC.B 'Hello!' EOM DC.B 0 * eom end $400.

dava
Download Presentation

Programming for the 68K

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Hello World • 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

  3. Useful Interrupts • 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)

  4. Back to Hello World 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

  5. FTOC Example FTOC SUBI.W #32, D0 MULS #5, D0 DIVS #9, D0 RTS

  6. 68K V.S. 8086 • See p.28, section 2.6

  7. Consider… • 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?

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

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

  10. Notes • 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

  11. Answer • D7 contains 1234FE09

  12. Address Register Indirect w PostIncrement • This implements a pop • Use the value, then increment (pop off stack) • The stack grows to lower addresses, shrinks to higher addrs

  13. Predecrement • A5 : 0x00007F00 • D2 : 0x4E4F2000 • 0x007EFF : 3C • 0x007F00 : 09 • 0x007F01 : BA • MOVE.W (A5)+, D2

  14. D2 : 4E4F09BA • 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

  15. Address Register Indirect w PreDecrement • 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

  16. With Displacement • 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?

  17. Indirect with Predecrement • A2: 0x007F00 • D4: F3052BC9 • //Mem • 0x007EFF : 3C • 0x007F00 : 09 • 0x007F01 : BA • MOVE.B –(A2),D4 • MOVE.B D4, -(A2) *push

  18. D4 : F3052B3C • Answer: • Decrement A2 first, so 0x007EFF • Copy from that location into the lower byte of D4

  19. How the Assembler => Binary • 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)

  20. User Input • 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

  21. Query • What does this code look like in ASM? • adder( int x, int y) { • int z; • z = x + y; • }

  22. Answer • *assuming D0 holds x, D1 holds y, D2 is z • adder AND.W #0, D2 ADD.W D0, D2 ADD.W D1, D2 RTS

  23. Sample Problem #1: What If? • 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!!

  24. Query • What does the asm look like for the following? • branch( inta, intb) { • if( a > b ) { • b = a • } else { • a = b • } • }

  25. Sample Problem #2 • Write an ASM module that defines two (3x3) matrices and sums up the first row • Data section:

  26. Query • What does the following code look like in ASM? • for(int a = 0; a < 10; a++ ) { • nop • }

  27. Sample Problem #3 • 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

  28. HW problem • What is a good HW problem for us to consider?

More Related