l7_handouts_2up - 2/17/2008 Announcements Homework 2 due...

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

View Full Document Right Arrow Icon
2/17/2008 1 Announcements • Homework 2 due next Tuesday • Project 2 due week from next Tuesday – Need partner? • Keep up with the reading! 1 ECE/CS 314 Assembler Object File Assembly C source Compiler Source Code to Execution “mostly” machine code Loader Executable Linker Library sqrt(), printf(), etc. all knowable addresses in place 2 ECE/CS 314 DLL dynamically linked library (routines linked at runtime, i.e., addresses resolved)
Background image of page 1

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

View Full DocumentRight Arrow Icon
2/17/2008 2 400000 27bdffe8 .text Assembly, Linking & Loading .text 400000 24020000 400004 90880000 4000b0 27bdffe8 4000b4 3c040040 4000b8 248402c0 4000bc 0c100038 <puts> li a2,0 <strlen_loop> lbu t0,0(a0) addiu a2,a2,1 bnez t0,400124 <strlen_loop> addiu a0,a0,1 ... jr ra nop <read> li v0,4003 syscall jr ra nop 400038 00000000 400000 24060000 400004 90880000 400008 24c60001 40000c 1500fffd 400010 24840001 400014 00862823 400018 24c6ffff 40001c 08100051 400020 24040001 400000 24020fa4 400004 0000000c 400008 03e00008 40000c 00000000 4000c0 00000000 4000c4 0c10005b 4000c8 00402025 4000cc 0c100059 4000d0 24040000 4000d4 00000000 4000d8 00000000 4000dc 00000000 4000e0 24020000 4000e4 90880000 4000e8 00000000 4000ec 19000007 ECE/CS 314 s: .asciiz "a string with spaces" beq $0, $0, $start $done: jr $31 <exit> li v0,4001 syscall <puti> lui t0,0x40 addiu t0,t0,784 bgez a0,40018c <positive> ... 400038 00000000 40003c 00000000 40000c 00000000 400000 24020fa3 400004 0000000c 400008 03e00008 40000c 00000000 ... 4000f0 00000000 4000f4 24090020 4000f8 15090002 4000fc 00000000 400100 24420001 400104 1000fff7 400108 24840001 40010c 03e00008 400110 00000000 400114 00000000 Source => Object => Image Assembling Programs • Start at address 400000 (arbitrarily) – Track location of jumps – Track references to labels in data (e.g., globals) – Track unresolved references (e.g., exit, library calls) • Addresses get relocated by OS when 4 ECE/CS 314 Addresses get by OS when program is loaded into memory • All needed info saved in object file
Background image of page 2
2/17/2008 3 Assembling Programs 5 ECE/CS 314 What Does the Assembler Do? When it sees the label $array? How does it calculate the address of $array? 6 ECE/CS 314
Background image of page 3

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

View Full DocumentRight Arrow Icon
2/17/2008 4 Forward References • Two-pass assembly – First pass allocates instructions, determines label addresses – Second pass assembles instructions (all labels are known) • One-pass assembly (backpatching) – Assemble instructions, but use 0 as address for all unknowns keep track of those unknowns 7 ECE/CS 314 unknowns, keep track of those unknowns – When encountering a label, if address known, fill in – At end of file, backpatch to fill in unfinished instructions Main.s <main> 400000 27bdffe8 addiu sp,sp, 24 400004 3c04???? li a0,<s> 400008 2484???? 40000c 0c?????? jal <NumSpaces> 400010 00402025 or a0,v0,$0 400014 0c?????? jal <puti> 400018 24040000 li a0,0 40001c 0c?????? jal <exit> 8 ECE/CS 314 400020 00000000 nop 400024 00000000 nop 400028 00000000 nop 40002c 00000000 nop
Background image of page 4
2/17/2008 5 Main.s <main> 400000 27bdffe8 addiu sp,sp, 24 400004 3c04???? li a0,<s> 0c??????
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

l7_handouts_2up - 2/17/2008 Announcements Homework 2 due...

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

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