Presentation is loading. Please wait.

Presentation is loading. Please wait.

Program Assembly.

Similar presentations


Presentation on theme: "Program Assembly."— Presentation transcript:

1 Program Assembly

2 Module Outline Review ISA and understand instruction encodings
Arithmetic and Logical Instructions Review memory organization Memory (data movement) instructions Control flow instructions Procedure/Function calls Program assembly

3 Reading Reading 2.8, 2.12 Appendix A: A1 - A.6 ( in online text) Practice Problems: 10, 14,23 Goals Understand the binary encoding of complete program executables How can procedures be independently compiled and linked (e.g., libraries)? What makes up an executable? How do libraries become part of the executable? What is the role of the ISA in encoding programs? What constitutes the hardware/software interface

4 The Complete Picture Reading: 2.12, A2, A3, A4, A5 C program compiler
Assembly assembler Object module Object library linker executable loader memory

5 The Assembler Create a binary encoding of all native instructions
Translation of all pseudo-instructions Computation of all branch offsets and jump addresses Symbol table for unresolved (library) references Create an object file with all pertinent information Header (information) Text segment Data segment Relocation information Symbol table Example:

6 Assembly Process Local labels, global labels, external labels and the symbol table What does mean when a symbol is unresolved? Absolute addresses and re-location

7 Example .data What changes when you relocate code? Hard address!
L1: .word 0x44,22,33,55 # array .text .globl main main: la $t0, L1 li $t1, 4 add $t2, $t2, $zero loop: lw $t3, 0($t0) add $t2, $t2, $t3 addi $t0, $t0, 4 addi $t1, $t1, -1 bne $t1, $zero, loop bgt $t2, $0, then move $s0, $t2 j exit then: move $s1, $t2 exit: li $v0, 10 syscall What changes when you relocate code? ] 3c lui $8, 4097 [L1]         [ ] ori $9, $0, 4             [ ] add $10, $10, $0          [ c] 8d0b0000 lw $11, 0($8)             [ ] 014b5020 add $10, $10, $11         [ ] addi $8, $8, 4            [ ] 2129ffff   addi $9, $9, -1           [ c] 1520fffc   bne $9, $0, -16 [loop-0x c] [ ] 000a082a slt $1, $0, $10           [ ] bne $1, $0, 12 [then-0x ] [ ] 000a8021 addu $16, $0, $10         [ c] d j 0x [exit]       [ ] 000a8821 addu $17, $0, $10        [ ] a ori $2, $0, 10           [ ] c syscall Hard address! Assembly Program Native Instructions Assembled Binary

8 Linker & Loader Linker Loader “Links” independently compiled modules
Determines “real” addresses Updates the executables with real addresses Static vs. dynamic (lazy) linking Loader As the name implies Specifics are operating system dependent We will come back to this later when we discuss OS

9 Linking Program A Program B Assembly A Assembly B cross reference
header text static data Assembly A Assembly B reloc cross reference symbol table labels debug Why do we need independent compilation? What are the issues with respect to independent compilation? references across files (can be to data or code!) absolute addresses and relocation Study: Example on pg. 127

10 Example: # separate file .text 0x20040004 addi $4, $0, 4 0x20050005
jal func_add done 0x a 0x c .text .globl func_add func_add: add $2, $4, $5 0x jr $ x03e00008 0x x 0x x 0x ? 0x c 0x a 0x x c 0x x 0x x03e00008 Ans: 0x0c100005

11 Standard Formats: ELF Executable and Linking Format (ELF) ELF header
Program Header Table (optional) Section 1 Section 2 Section Header Table (required) ELF header Program Header Table (required) Segment 1 Segment 2 Section Header Table (optional) Linking View Execution View See wikipedia.org

12 Standard Object File Formats
There are other formats associated with different operating systems ISA neutral format for building executables Tools Source  assembly  object  executable  process image Header (information) Text segment Data segment Relocation information Symbol table Image stored on disk How do we translate the image into a running process?  OS

13 The Computing Model Revisited
Register File (Programmer Visible State) Memory Interface stack 0x00 0x01 0x02 0x03 Processor Internal Buses 0x1F Dynamic Data Data segment (static) Text Segment Programmer Invisible State Reserved 0xFFFFFFFF Program Counter Instruction register Arithmetic Logic Unit (ALU) Memory Map Kernel registers Program Execution and the von Neumann model

14 Stored Program Concept
Fetch & Execute Cycle  sequential flow of control Instructions are fetched and put into a special register Bits in the register "control" the subsequent actions Fetch the “next” instruction and continue Program Counter  Program Counter + 4 (byte addressing!) Von Neumann execution model Example: compiler ISA HW HW support

15 Study Guide Encode/disassemble jal and jr instructions
Compute number of bytes to encode a SPIM program What does it mean for a code segment to be relocatable? Identify addresses that need to be modified when a program is relocated. Given the new start address modify the necessary addresses Encode/disassemble jal and jr instructions Computation of jal encodings for independently compiled modules

16 Study Guide (cont.) How are independently compiled modules linked into a single executable? (assuming one calls a procedure located in another)

17 Glossary Disassembly Independent compilation
Labels: local, global, external Linker/loader Linking: static, dynamic, lazy Native instructions Object file Pseudo instructions Relocatable code Symbol table Unresolved symbol


Download ppt "Program Assembly."

Similar presentations


Ads by Google