l06 - Assembling Programs What is an assembler? Expands...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Assembling Programs What is an assembler? Expands pseudo-operations into machine instructions Translates text assembly language to binary machine code Output: object le .o les (Unix) .obj les (Windows/DOS) Assembling Programs .text # directive .ent main # directive main: la $4,$array # pseudo-op li $5,15 # pseudo-op ... li $4,0 # pseudo-op jal exit .end main # directive .data # directive $array: .long 51,491,3991,4,6881,-41 # directive .globl exit .text # directive Handling Forward References Two-pass assembly 1: allocate instructions, thus determining addresses 2: assemble instructions knowing all labels One-pass or backpatch assembly 1: assemble instructions, put in zero for unknown offsets/addresses, keep track of unnished instructions Backpatch: when labels appear or at the end of pass 1, ll in the unnished instructions. Handling Forward References Example: bne $1,$2,L # branch forward sll $0,$0,0 # to label L L: addiu $2,$3,$2 The assembler will change this to: bne $1,$2,+1 # branch forward 1 word sll $0,$0,0 # relative to the sll addiu $2,$3,$2 Final machine code: 0x14220001 # bne 0x00000000 # sll 0x24620002 # addiu Assembling Programs Start at address zero (arbitrary). Keep track of where the jumps are Keep track of references to labels in data Keep track of unresolved labels (like exit ) All this information is saved in the object le....
View Full Document

This note was uploaded on 06/25/2008 for the course ECE 3140 taught by Professor Mckee/long during the Spring '07 term at Cornell University (Engineering School).

Page1 / 18

l06 - Assembling Programs What is an assembler? Expands...

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