L07-AssemblerCompiler - Assemblers and Compilers Long long...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
L07 – Assemblers and Compilers Comp 411 – Fall 2009 9/23/09 Assemblers and Compilers When I find my code in tons of trouble, Friends and colleagues come to me, Speaking words of wisdom: "Write in C." Long, long, time ago, I can still remember How mnemonics used to make me smile. .. And I knew that with just the opcode names that I could play those assembly games and maybe hack some programs for a while. But Comp 411 made me shiver, With every new lecture that was delivered, There was bad news at the door step, I couldn’t handle another problem set. My whole life thus far must have flashed, the day the SPIM simulator crossed my path, All I know is that it made my hard disk crash, On the day the hardware died. And I was singing… Study sections 2.12-2.14 Skim 2.16-2.19
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
L07 – Assemblers and Compilers Comp 411 – Fall 2009 9/23/09 Path from Programs to Bits Traditional Compilation C or C++ program Compiler Assembly Code Assembler “Object Code” Linker “Executable” Loader “Memory” “Library Routines” High-level, portable (architecture independent) program description Architecture dependent mnemonic program description with symbolic memory references Machine language with symbolic memory references A collection of precompiled object code modules Machine language with all memory references resolved Program and data bits loaded into memory
Background image of page 2
L07 – Assemblers and Compilers Comp 411 – Fall 2009 9/23/09 How an Assembler Works Three major components of assembly 1) Allocating and initialing data storage 2) Conversion of mnemonics to binary instructions 3) Resolving addresses .data array: .space 40 total: .word 0 .text .globl main main: la $t1,array move $t2,$0 move $t3,$0 beq $0,$0,test loop: sll $t0,$t3,2 add $t0,$t1,$t0 sw $t3,($t0) add $t2,$t2,$t3 addi $t3,$t3,1 test: slti $t0,$t3,10 bne $t0,$0,loop sw $t2,total j $ra lui $9, arrayhi ori $9,$9,arraylo 0x3c09???? 0x3529????
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Comp 411 – Fall 2009 9/23/09 Resolving Addresses- 1 st Pass “Old-style” 2-pass assembler approach Segment offset Code Instruction 0 4 0x3c09 0000 0x3529 0000 la $t1,array 8 12 0x00005021 0x00005821 move $t2,$ move $t3,$0 16 0x1000 0000 beq $0,$0,test 20 0x000b4080 loop: sll $t0,$t3,2 24 28 32 36 0x01284020 0xad0b0000 0x014b5020 0x216b0001 add $t0,$t1,$t0 sw $t0,($t0) add $t0,$t1,$t0 addi $t3,$t3,1 40 0x2968000a test: slti $t0,$t3,10 44 0x1500 0000 bne $t0,$0,loop 48 52 0x3c01 0000 0xac2a 0000 sw $t2,total 56 0x03e00008 j $ra Symbol Segment Location pointer offset array data 0 total data 40 main text 0 loop text 20 test text 40 Pass 1 Symbol table after Pass 1 - In the first pass, data and instructions are encoded and assigned offsets within their segment, while the symbol table is constructed. - Unresolved address
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 19

L07-AssemblerCompiler - Assemblers and Compilers Long long...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online