350 likes | 610 Views
E N D
1. ESE350: Introduction to Embedded SystemsMC9S12C128 C & Assembly Language StructureLecture #3 Professor Rahul Mangharam
Electrical and Systems Engineering
University of Pennsylvania
2. Outline of Today’s Lecture From C to Assembly
Bitwise Operators
Parts of an Assembly Program
Putting it altogether 2
3. From C to Assembly 3
4. Machine Code Machine instructions:
A sequence of binary digits which can be executed by the processor
0001 1000 0000 0110: [A] + [B] -> A ABA
01000011: [A]+1->A INCA
1000 0110 0000 0110: 6 -> A LDA #06
Unless you are Neo….
Hard to understand, enter, debug, and maintain for human being
A readable equivalent of what is performed is shown first
A mnemonic for the machine instruction is shown second. 4
5. Machine/Assembly Code Example The example shows:
The address where the machine code is to be stored in memory
The machine code in hex
The assembly code or source code with an assembler directive
The assembler directive tells the assembler at what address to start storing the machine code 5
6. Assembly Language Defined by assembly instructions
An assembly instruction is a mnemonic representation of a machine instruction
Mnemonic What it does;
ABA [A]+[B]->A ;
DECA [A]-1->A
Assembly programs must be translated into machine instructions before it can be executed -- translated by an assembler
There are two kinds of assemblers: native assembler and cross assembler
Programmers need to work on the program logic at a very low level and cannot achieve high productivity. 6
7. Assembly Language Example Ldx #Array1 ;Loads index register X with start address of Array1
Ldy #Array2 ;Loads index register Y with start address of Array2
Ldab #$0A ;Loads B accumulator with value 10 for counter 7
8. High-level Language Syntax of a high-level language is similar to English.
A translator is required to translate the program written in a high-level language -- done by a compiler.
There are two types of compilers: native compiler and cross compiler.
High-level languages allow the user to work on the program logic at higher level and achieve higher productivity.
Source code
A program written in assembly or high-level language
Object code
The output of an assembler or compiler 8
9. Let us C… C has gradually replaced assembly language in many embedded applications.
A summary of C language constructs that will be used in HCS12 programming.
Books on C language
Kernighan & Ritchie, “The C Programming Language”, Prentice Hall, 1988.
Deitel & Deitel, “C: How to Program”, Prentice Hall, 1998. –Kelly & Pohl,
“A Book on C: Programming in C”, Addison-Wesley, 1998.
A C program consists of functions and variables.
A function contains statements that specify the operations to be performed.
Types of statements:
Declaration
Assignment
Function call
Control
Null
A variable stores a value to be used during the computation.
The main () function is required in every C program. 9
10. C Data Types for Microcontrollers 10
11. Bitwise Operators (1) 11
12. Bitwise Operators (1) 12
13. Relational and Logical Operators (1) 13
14. Relational and Logical Operators (2) 14
15. Parts of an Assembly Program 15
16. Assembly Directives 16
17. Other Directives 17
18. Parts of Assembly Instruction 18
19. An Assembly Instruction 19
20. Instruction Classifications 20
21. Other Instruction Classifications 21
22. Some Assembly Instructions 22
23. 23
24. 24
25. 25
26. Addressing Modes 26
27. Extended Addressing 27
28. Direct Addressing 28
29. Immediate Addressing 29
30. Indexed Addressing 30
31. Inherent & Relative Addressing 31
32. Instruction Execution Cycle 32
33. 33
34. 34
35. 35
36. Putting it altogether - An Assembly Program 36