1 / 55

Assemblers

Assemblers. Goals. Assembler is a symbolic notation for machine language It improves readability: Assembler: Move R0,SUM Machine code: 0010 1101 1001 0001 (16 bits). Why assembler ?. Speed of programs in critical applications Access to all hardware resources of the machine

chars
Download Presentation

Assemblers

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. Assemblers

  2. Goals • Assembler is a symbolic notation for machine language • It improves readability: • Assembler: Move R0,SUM • Machine code: 0010 1101 1001 0001(16 bits)

  3. Why assembler ? • Speed of programs in critical applications • Access to all hardware resources of the machine • Target for compilers

  4. Case • Universele Brander Automaat • Betronic

  5. Machine Language (1) • Is Machine language difficult to learn? • That holds for every unknown language. Machine language is more difficult because you have to work with the specifically defined micro instruction set. • Is Machine language difficult to read and to understand? • Of course; if you do not know the language, but more difficult as an HLL.

  6. Machine Language (2) • Is Machine language difficult to debug? • Often debuggers give the HLL and machine language and the error is only found in the generated machine language! • Is Machine language difficult to maintain? • Maintainable programs are not specifically dependent on the language they are written in, but more on the way they are contructed

  7. Machine Language (3) • Is Machine language difficult to write? • Often HLL languages use libraries to make programming more simple. Machine language programmers often start from scratch. • Machine languageprogramming is time consuming • One estimates that the time for coding a program is only 30% of the total development time.

  8. Machine Language (4) • Compilers make Machine language superfluous • A good machine language program often looks very different from a compiler generated program. Generally a C program will win over an hand made assembly program

  9. Case Universele Brander Automaat • Klant: Nefit Fasto B.V. • Markt: HVAC • Ontwikkelen (1990) en produceren (100k/jaar) van de UBA universele brander- automaat voor Nefit-Fasto voorzien van een bipolaire ASIC. • Eerste product met een universeel karakter, die een fail-safe approval heeft

  10. Case UBA Ignition 230V , Pump and Fan 6 schakel ingangen 8 analoge ingangen 3 schakeluitgangen 3 modulerende uitgangen 2 draads communicatie bus Externe KIM module aansluiting met 178 bytes config settings Asic and micro Computer

  11. UBA software opbouw HWIO Application C- language 15 Kbyte 1 Kbyte

  12. UBA micro computer HWIO MC68HC05B16 24 I/O bi-directional 8 A/D analogue inputs 2 TCAP input timers 2 TCMP output compare 2 PWM D/A outputs 1 SCI serial output 1 COP watchdog 256 bytes RAM 256 bytes EEPROM 16 Kbytes (EP)ROM 1 Kbytes

  13. UBA Pup After Power up Reset special routine - all instruction set in testroutine - 16 bits CRC (99,98%) - Walking A0 and 05 Ramtest - Check on A/D - Mainloop partitioned in modules - Module check in each phase - Acknowlegde module check by pulse to Asic (350mSec) - Interrupt program termination check by pulse to Asic (20mSec) - Communicate through Objects with C-shell

  14. UBA Assembly • Check instruction set • Test of each opcode over and over again • Emergency stop at fault detection • Not possible in “C” • Check on memory • As part of the program • Emergency stop at fault detection • Difficult in “C” • Better control on application • Compiler generated code must be checked on correctness.

  15. Assembler Statements • Executable statements • are translated to real machine instructions (often one-to-one) • Declarations • no code generation • memory reservation • symbolic data declarations • where to start the code execution

  16. Data declarations Label operation operand S EQU 200 ORIGIN 201 N DATA 300 N1 RESERVE 300 ORIGIN 100

  17. Program Addr operation operand START Move N,R1 Move #N1,R2 Clear R0 LOOP Add (R2),R0 Incr R2 Decr R1 Branch>0 LOOP Move R0,S Return End START

  18. Memory lay-out S Move N,R1 100 200 N ..... 300 101 201 ..... ..... 102 202 N1 ..... ..... 103 203 ..... ..... 104 ..... ..... 105 Branch >0 106 107 501 Nn

  19. type source program Source in ASCII editor translate assembler listing Source and Object code +error messages object code machine 1 machine 2 link/load linker/loader run input/ output memory image Flow

  20. Structure assembler(1) • Assembler is hardly more than substitution • substitute 0001 for Move • substitute 0000 0000 0000 0101for#5 • Is level above machine language • Assembler languages for different architectures are alike

  21. Structure assembler(2) Assembler programs contain three kind of quantities: • Absolute: • opcodes, contants: can be directly translated • Relative: • addresses of instructions which are dependent of final memory location • Extern: • call to subroutines

  22. Structure assembler(3) • Literals: constants in programs • Some assemblers act as if literals are immediate operands • Example: Load #1 is equivalent to: Load One ... One: 1

  23. Number notation • Numbers can be represented using various formats: ADD #93,R1 or ADD #%01011101,R1 or ADD #$5D,R1

  24. Stack registers CPU SP PC Main Memory

  25. 70 300 20 10 60 Stack operations 0 1 SP

  26. Push Subtract #4,SP Move R0,(SP) 0 SP 1 80 70 300 or: Move R0,-(SP) 20 10 60 80 R0

  27. Pop 0 Move (SP),R0 Add #4,SP 1 80 70 SP 300 or: Move (SP)+,R0 20 10 60 70 R0

  28. Subroutines • More structure in programs • Mimics procedure and function calls in high level programming languages

  29. Calling mechanism Call SUB 200 next instr. 204 PC Link ................ 204 1000 ................ PC Link RTS 204

  30. Question Is Link register sufficient ?

  31. Subroutine nesting • For nesting of subroutines return address in link register must be stored • Can be done by using stacks

  32. Subroutine stack Stack PC Link 204 subroutine Move Link, -(SP) ...... Move (SP)+, Link RTS

  33. Parameter passing(1) • Through registers • fast • limited number of parameters • caller and callee must know where parameters are placed • Example: Move A,R0 Sub: Move R0,C Call Sub ...... RTS

  34. Parameter passing(2) • Through memory • very flexible • slower than through registers • Often implemented through Stack Pointer • Parameters are pushed on stack before calling subroutine • Results are popped from stack after return • Subroutine needs registers

  35. Parameter passing(3) Stack calling subroutine Move #List, -(SP) Move N, -(SP) Call LISTADD Move 4(SP), SUM Add #8, SP SP

  36. Parameter passing(3) Stack calling subroutine Move #List, -(SP) Move N, -(SP) Call LISTADD Move 4(SP), SUM Add #8, SP SP LIST

  37. Parameter passing(3) Stack calling subroutine Move #List, -(SP) Move N, -(SP) Call LISTADD Move 4(SP), SUM Add #8, SP n SP LIST

  38. Parameter passing(3) Stack calling subroutine Move #List, -(SP) Move N, -(SP) Call LISTADD Move 4(SP), SUM Add #8, SP Return SP n LIST

  39. Parameter passing(3) Stack calling subroutine Move #List, -(SP) Move N, -(SP) Call LISTADD Move 4(SP), SUM Add #8, SP n SP sum

  40. Parameter passing(3) Stack calling subroutine Move #List, -(SP) Move N, -(SP) Call LISTADD Move 4(SP), SUM Add #8, SP SP

  41. Parameter passing(4) LISTADD Move R0, -(SP) ... Move 16(SP), R1 Move 20(SP), R2 Clear R0 LOOP Add (R2), R0 Decr R1 Incr R2 Branch>0 LOOP Move R0, 20(SP) Move (SP)+, R2 ..... Return Stack frame [R0] SP Return n LIST Subroutine

  42. Parameter passing(4) LISTADD Move R0, -(SP) ... Move 16(SP), R1 Move 20(SP), R2 Clear R0 LOOP Add (R2), R0 Decr R1 Incr R2 Branch>0 LOOP Move R0, 20(SP) Move (SP)+, R2 ..... Return Stack frame [R2] SP [R1] [R0] Return n LIST Subroutine

  43. Parameter passing(4) LISTADD Move R0, -(SP) ... Move 16(SP), R1 Move 20(SP), R2 Clear R0 LOOP Add (R2), R0 Decr R1 Incr R2 Branch>0 LOOP Move R0, 20(SP) Move (SP)+, R2 ..... Return Stack frame [R2] SP [R1] [R0] Return n sum Subroutine

  44. Parameter passing(4) LISTADD Move R0, -(SP) ... Move 16(SP), R1 Move 20(SP), R2 Clear R0 LOOP Add (R2), R0 Decr R1 Incr R2 Branch>0 LOOP Move R0, 20(SP) Move (SP)+, R2 ..... Return Stack frame [R1] SP [R0] Return n sum Subroutine

  45. Parameter passing(4) LISTADD Move R0, -(SP) ... Move 16(SP), R1 Move 20(SP), R2 Clear R0 LOOP Add (R2), R0 Decr R1 Incr R2 Branch>0 LOOP Move R0, 20(SP) Move (SP)+, R2 ..... Return Stack frame Return SP n sum Subroutine

  46. Frame Pointer Access variables Through Index Addressing SP saved [R1] (stack pointer) saved [R0] localvar3 localvar2 localvar1 Stack FP frame saved [FP] (frame pointer) for called Return address subroutine param1 param2 param3 param4 Old TOS (top-of-stack)

  47. Re-entrancy • Subroutines can be called more than once • Recursion: subroutine calls itself • Sub A calls Sub B, which in turn calls Sub A • Multiple callers “at the same time” • Special measures for re-entrancy • No change of instructions • Each caller must have its own copy of data • Use stack(s)

  48. Additional Instructions • Logic instructions • Not R0; invert all bits in R0 • And #$FF000000,R0; AND with bit string • Shift and rotate instructions • Many variants for different purposes

  49. Logical shifts C R0 0 e.g. used in Packing . . . before: 0 0 1 1 1 0 0 1 1 . . . after: 1 1 1 0 0 1 1 0 0 (a) Logical shift left LShiftL #2,R0 0 R0 C . . . 0 1 1 1 0 0 1 1 before: 0 . . . after: 0 0 0 1 1 1 0 0 1 (b) Logical shift right LShiftR #2,R0

  50. Arithmetic shifts R0 C . . . before: 0 1 0 0 1 1 0 1 0 . . . after: 1 1 1 0 0 1 1 0 1 (c) Arithmetic shift right AShiftR #2,R0

More Related