Topics (Chapters 2 and 4) Mnemonics, OP codes Assembler Assembler Directives Assembly Process Object program Linker Loader Debugger 1
Turning C into Assembly C Program Compiler Assembly File Program in assembly language 2
4.5 The Compiler Assembly language programming requires knowledge of machine-specific details Programming in a high-level language (like C) reduces this need Program in high-level language must be translated into assembly language for machine execution 1 to many The compiler : performs translation/optimization 1 to 1 The assembler : transforms to object code (0/1) 3
From Assembly to Object C Program Compiler Assembly File Assembler Object File Assembly Program Binary 0 s and 1 s Assembler Object File 4
Fig. 2.13 A Sample Assembly Program 5
2.5 Assembly Language Mnemonic: Syntax and Semantics Machine specific: ST/ADD or Store/Add Human recognizable alphanumeric text format Mnemonics represent OP codes (operation codes): Binary pattern hard to recognize by human Amenable to computer processing 6
Fig. 2.13 A Sample Assembly Program Mnemonics Labels 7
2.5.1 Assembler Directives What is a symbolic name (defined by us)? A variable, constant, or location reference Where should instructions/data be placed? Under programmer or development system control Assembler directives provide this information ORIGIN defines instruction/data starting position RESERVE and DATAWORD define data storage 8
Fig. 2.13 A Sample Assembly Program 9
4.1 The Assembly Process Program created using a text editor or by compiler Written to a file in memory for later processing Assembler Translates source file to object code Maps mnemonics to OP codes Generates address for operands Recognizes directives that define constants and allocate space in memory for data 10
From C to Assembly to Object C Program Assembly Program Compiler Assembly File Assembler Object File Assembler Object File Linker What s Next? Object Program Library File 11
4.2 Loading/Executing Object Programs Loader invoked by typing command or clicking icon Identifies object file on disk Object file has information on starting location in memory and length of program Secondary Memory Loader transfers object program from disk to memory Primary Memory Control logic starts execution until termination 12
From Object Program to Execution C Program Assembly Program CPU Compiler Assembler RAM Assembly File Object File Loader Assembler Object File Linker Object Program Library File 13
4.6 The Debugger Programming errors, or bugs, can cause a program to produce incorrect results The debugger enables the programmer to identify such errors at execution time Execution can be stopped at points of interest At such points, debugger accepts commands to display contents of registers or memory Execution resumed until next point of interest 14
4.6 Trace and Breakpoints The debugger uses trace interrupt What s the Difference? Trace library invoked after each instruction to enable user to inspect registers/memory Breakpoints involve placing software-interrupt instruction in program to switch to debugger Current instruction restored to resume execution 15
2.5.3 Number Notation Decimal numbers used as immediate values: ADDI R2, R3, 93 Assembler translates to binary representation Programmer may also specify binary numbers: ADDI R2, R3, %01011101 or $... Hexadecimal specification is an alternative: ADDI R2, R3, 0x5D Note that 93 = 1011101 2 = 5D 16 16