CSE 331 Computer Organization and Design Fall 2007 Week 5

1 / 27

# CSE 331 Computer Organization and Design Fall 2007 Week 5 - PowerPoint PPT Presentation

CSE 331 Computer Organization and Design Fall 2007 Week 5. Section 1: Mary Jane Irwin ( www.cse.psu.edu/~mji ) Section 2: Krishna Narayanan Course material on ANGEL: cms.psu.edu [ adapted from D. Patterson slides ]. Head’s Up. Last week’s material Supporting procedure calls and returns

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' CSE 331 Computer Organization and Design Fall 2007 Week 5' - leola

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### CSE 331Computer Organization and DesignFall 2007Week 5

Section 1: Mary Jane Irwin (www.cse.psu.edu/~mji)

Section 2: Krishna Narayanan

Course material on ANGEL: cms.psu.edu

• Last week’s material
• Supporting procedure calls and returns
• This week’s material
• Reading assignment - PH: 2.10, A.1-A.5
• Next week’s material (after Exam #1)
• Introduction to VHDL and basic VHDL constructs
• Reading assignment – Y, Chapters 1 through 3
• Reminders
• HW 4 is due Thursday, Sept 27th (by 11:55pm)
• Quiz 3 will close Sunday, Sept 30th (at 11:55pm)
• Exam #1 is Tuesday, Oct 2, 6:30 to 7:45pm, 113 IST
CDT Article on IBM’s BlueGene/P (9/25/07)
• Calculations per second
• Gigaflop 1 billion (1,000,000,000)
• Teraflop 1 trillion (1,000,000,000,000)
• Exaflop 1 quintrillion (1,000,000,000,000,000,000)

op rs rt rd funct

Register

word operand

op rs rt offset

Memory

word or byte operand

base register

op rs rt operand

• Register addressing – operand is in a register
• Base (displacement) addressing – operand’s address in memory is the sum of a register and a 16-bit constant contained within the instruction
• Immediate addressing – operand is a 16-bit constant contained within the instruction

op rs rt offset

Memory

branch destination instruction

Program Counter (PC)

Memory

||

jump destination instruction

Program Counter (PC)

• PC-relative addressing – instruction’s address in memory is the sum of the PC and a 16-bit constant contained within the instruction
• Pseudo-direct addressing – instruction’saddress in memory is the 26-bit constant contained within the instruction concatenated with the upper 4 bits of the PC
Review: MIPS R3000 ISA
• Instruction Categories
• Computational
• Jump and Branch
• Floating Point
• coprocessor
• Memory Management
• Special
• 3 Instruction Formats: all 32 bits wide

Registers

R0 - R31

PC

HI

LO

6 bits

5 bits

5 bits

5 bits

5 bits

6 bits

R format

OP

rs

rd

shamt

funct

rt

I format

rt

16 bit number

OP

rs

J format

26 bit jump target

OP

RISC Design Principles Review
• Simplicity favors regularity
• fixed size instructions – 32-bits
• small number of instruction formats
• Smaller is faster
• limited instruction set
• limited number of registers in register file
• limited number of addressing modes
• Good design demands good compromises
• three instruction formats
• Make the common case fast
• arithmetic operands from the register file (load-store machine)
• allow instructions to contain immediate operands
Compiler

Transforms the C program into an assembly language program

• many fewer lines of code
• easier to understand and debug
• Today’s optimizing compilers can produce assembly code nearly as good as an assembly language programming expert and often better for large programs
• smaller code size, faster execution

compiler

assembly code

assembler

object code

The Code Translation Hierarchy

C program

Assembler

Does a syntactic check of the code (i.e., did you type it in correctly) and then transforms the symbolic assembler code into object (machine) code

• much easier than remembering instr’s binary codes
• can use labels for addresses – and let the assembler do the arithmetic
• can use pseudo-instructions
• e.g., “move \$t0, \$t1” exists only in assembler (would be implemented using “add \$t0,\$t1,\$zero”)
• When considering performance, you should count instructions executed, not code size
The Two Main Tasks of the Assembler
• Builds a symbol table which holds the symbolic names (labels) and their corresponding addresses
• A label is local if it is used only within the file where its defined. Labels are local by default.
• A label is external (global) if it refers to code or data in another file or if it is referenced from another file. Global labels must be explicitly declared global (e.g., .globl main)
• Translates each assembly language statement into object (machine) code by “assembling” the numeric equivalents of the opcodes, register specifiers, shift amounts, and jump/branch targets/offsets
MIPS (spim) Memory Allocation

Memory

f f f f f f f c

Mem Map I/O

Kernel Code & Data

\$sp

7f f f f f fc

Stack

230

words

Dynamic data

\$gp

1000 8000

Static data

1000 0000

Text

Segment

PC

0040 0000

Reserved

0000 0000

• Converts pseudo-instr’s to legal assembly code
• register \$at is reserved for the assembler to do this
• Converts branches to far away locations into a branch followed by a jump
• Converts instructions with large immediates into a lui followed by an ori
• Converts numbers specified in decimal and hexidecimal into their binary equivalents and characters into their ASCII equivalents
• Deals with data layout directives (e.g., .asciiz)
• Expands macros (frequently used sequences of instructions)
Typical Object File Pieces
• Object file header: size and position of the following pieces of the file
• Text (code) segment (.text) : assembled object (machine) code
• Data segment (.data) : data accompanying the code
• static data - allocated throughout the program
• dynamic data - grows and shrinks as needed
• Relocation information: identifies instructions (data) that use (are located at) absolute addresses – not relative to a register (including the PC)
• on MIPS only j, jal, and some loads and stores (e.g., lw \$t1, 100(\$zero) ) use absolute addresses
• Symbol table: global labels with their addresses (if defined in this code segment) or without (if defined external to this code segment)
• Debugging information
An Example

.data

.align 0

str: .asciiz "The answer is "

cr: .asciiz "\n"

.text

.align 2

.globl main

.globl printf

main: ori \$2, \$0, 5

syscall

move \$8, \$2

loop: beq \$8, \$9, done

blt \$8, \$9, brnc

sub \$8, \$8, \$9

j loop

brnc: sub \$9, \$9, \$8

j loop

done: jal printf

compiler

assembly code

assembler

object code

library routines

executable

The Code Translation Hierarchy

C program

main text segment

printf text segment

machine code

Takes all of the independently assembled code segments and “stitches” (links) them together

• Faster to recompile and reassemble a patched segment, than it is to recompile and reassemble the entire program
• Decides on memory allocation pattern for the code and data segments of each module
• Remember, modules were assembled in isolation so each has assumed its code’s starting location is 0x0040 0000 and its static data starting location is 0x1000 0000
• Relocates absolute addresses to reflect the new starting location of the code segment and its data segment
• Uses the symbol tables information to resolve all remaining undefined labels
• branches, jumps, and data addresses to/in external modules
• Linker produces an executable file

Executable file

main:

.

.

.

jal printf

printf:

.

.

.

Object file

main:

.

.

.

jal ????

call, printf

C library

printf:

.

.

.

Relocation info

Executable

File 1

+

File 2

Hdr Txtseg Dseg Reloc

Hdr Txtseg Dseg Reloc Smtbl Dbg

Hdr Txtseg Dseg Reloc Smtbl Dbg

compiler

assembly code

assembler

object code

library routines

executable

memory

The Code Translation Hierarchy

C program

machine code

• Loads (copies) the executable code now stored on disk into memory at the starting address specified by the operating system
• Copies the parameters (if any) to the main routine onto the stack
• Initializes the machine registers and sets the stack pointer to the first free location (0x7fff fffc)
• Jumps to a start-up routine (at PC addr 0x0040 0000 on xspim) that copies the parameters into the argument registers and then calls the main routine of the program with a jal main