Subroutines and Parameters

25

description

Subroutines and Parameters. Call and return Parameter passing Return values Leaf subroutines Combining C and assembly modules. Separate Assembly. Separate Assembly Language Modules Command line parameters are passed like any others   External Data. Example. include(macro_defs.m) - PowerPoint PPT Presentation

Transcript of Subroutines and Parameters

Page 1: Subroutines and Parameters
Page 2: Subroutines and Parameters

Subroutines and Parameters

• Call and return

• Parameter passing

• Return values

• Leaf subroutines

• Combining C and assembly modules

Page 3: Subroutines and Parameters

Separate Assembly

• Separate Assembly Language Modules– Command line parameters are passed like any

others  

• External Data

Page 4: Subroutines and Parameters

Example

include(macro_defs.m)

! Some symbolic constants for readability. define(argc, i0) define(argv, i1)

local_vars var(sum, 4)

fmt: .asciz "sum is %d\n" ! Read-only string ! for printf . . .

Page 5: Subroutines and Parameters

.align 4 begin

st %g0, [%fp + sum] ! sum = 0;

b test ! while test nop ! Delay slot

loop: add %fp, sum, %o0 ! &sum call summer ld [%argv], %o1 ! ptr to 1st num

test: subcc %argc, 1, %argc ! argc--; bg,a loop add %argv, 4, %argv ! argv++; . . .

Page 6: Subroutines and Parameters

. . . set fmt, %o0 call printf ! printf(fmt, sum); ld [%fp + sum], %o1 ! Delay slot

end_fn

Page 7: Subroutines and Parameters
Page 8: Subroutines and Parameters

7. Instruction Encoding

• All instructions 32 bits long

• Three “formats”

Page 9: Subroutines and Parameters

Format 1

• The call instruction

01 displacement 30

Page 10: Subroutines and Parameters

Format 2

• Branch and sethi

00 immediate 22op2rd

00 displacement 22op2conda

Page 11: Subroutines and Parameters

Format 3

• Arithmetic, Logical, Load, Store, etc.

xx asiop3rd rs1 rs20

xx op3rd rs1 immediate 131

Page 12: Subroutines and Parameters
Page 13: Subroutines and Parameters

Computer ArchitectureA Quantitative Approach

(Based on Hennessy and Patterson, 3rd Ed.)

Page 14: Subroutines and Parameters

Fundamentals of Computer Design

• Improvement in computer performance comes from two areas:– Technological improvements– Architectural improvements

• Since the 1980’s development of new architectures has been encouraged by:– High-level languages– Standardised operating systems

Page 15: Subroutines and Parameters

Background

• Since 1985 new architectures have led to startling performance improvements– Fig 1.1 (p. 3)

• Microprocessors rule!– Workstations and PC’s– Minicomputers– Mainframes– Supercomputers

Page 16: Subroutines and Parameters

Computing Markets• Desktop machines

– Price/performance is critical– Use newest technology

• Servers– Availability, scalability, throughput

• Embedded computers– Fastest growing market segment– Huge range of price/performance– Real-time requirements– Memory and power are limited

Page 17: Subroutines and Parameters

The Task of a Computer Designer

• Instruction Set Architecture• Organisation• Hardware

}Architecture• Must meet functional requirements:

• Intended application area

• Compatibility with existing software

• Support required for operating system(s)

• Standards (IEEE floating point, busses, networks, programming languages, etc.)

Page 18: Subroutines and Parameters

Task of a Designer (cont.)

• Strive to minimise complexity and cost/performance ratio

• Track future trends

Page 19: Subroutines and Parameters

Technology Trends• Processors:

– transistor counts increase +/–55% each year

• RAM: – rapid increase in density (but not speed)

• Disks: – density increases at 100+% each year

• Networks:– bandwidth increasing rapidly

Page 20: Subroutines and Parameters

Technology Trends (cont.)

• Life span of a processor +/–5 years– Must plan for changes in technologies– May design for future technology!

• Trends are continuous, but sometimes observed as discrete leaps– E.g. transistor density → on-chip caches

Page 21: Subroutines and Parameters

Power

• A major headache!

• Packing more transistors closer together greatly increases power consumption– 1970’s microprocessors: a few tenths of a watt– 2GHz P4: 100W

Page 22: Subroutines and Parameters

Cost/Price Trends

• Critical for desktop and embedded markets

• Time– “Learning curve” decreases price

• Volume

• Commodification– Competition in high volume markets decreases

price

Page 23: Subroutines and Parameters

Cost Issues• Complex and rapidly changing area

• Cost of integrated circuits– Significant impact on cost differentiation

• Overall (desktop PC):– Cabinet: 6%– Processor and motherboard: 37%

• Processor: 22%

– I/O Devices: 37%– Software: 20%

Page 24: Subroutines and Parameters

Balancing Cost/Performance

• No one answer

• Supercomputers– Cost is of little concern

• Some embedded areas (e.g. cell phones)– Cost is critical

• Workstations and servers– Cost and performance must be balanced

Page 25: Subroutines and Parameters