ACA Introduction Lect
ACA Introduction Lect
Lecture overview
Previous lecture
Todays lecture
9/18/2014
C operators
Shift Left
Shift Right
Bit-by-bit AND
Bit-by-bit OR
Bit-by-bit NOT
<<
>>
&
|
~
Java operators
<<
>>>
&
|
~
MIPS instr
sll
srl
and, andi
or, ori
nor
$t2, $S0, 4
or
nor
9/18/2014
9/18/2014
Example
Convert to assembly:
while (save[i] == k)
i += 1;
Loop: sll
add
lw
bne
addi
j
Exit:
$t1, $s3, 2
$t1, $t1, $s6
$t0, 0($t1)
$t0, $s5, Exit
$s3, $s3, 1
Loop
Unconditional branch
9/18/2014
10
9/18/2014
Procedures
Each procedure (function, subroutine) maintains a scratchpad of register
values when another procedure is called (the callee), the new procedure
takes over the scratchpad values may have to be saved so we can safely
return to the caller
1.
2.
3.
4.
5.
6.
parameters (arguments) are placed where the callee can see them
control is transferred to the callee
acquire storage resources for callee
execute the procedure
place result value where caller can access it
return control to caller
11
Registers
MIPS follows following convention in allocating its 32
registers for procedure calling
$a0 - $a3: four argument registers in which to pass
parameters
$v0 - $v1: two value registers in which to return values
$ra: one return address register to return to the point
of origin
12
9/18/2014
jal NewProcedureAddress
Since jal may over-write a relevant value in $ra, it must be saved
somewhere (in memory?) before invoking the jal instruction
How do we return control back to the caller after completing the
callee procedure?
13
The stack
What if more registers are required than the four parameter
registers ($a0 - $a3) and two value registers ($v0 - $v1)
The register scratchpad for a procedure seems volatile it seems to
disappear every time we switch procedures a procedures values
are therefore backed up in memory on a stack
High address
Proc A
Proc As values
Proc Bs values
Proc Cs values
Stack grows
this way
Low address
call Proc B
call Proc C
return
return
return
14
9/18/2014
15
Example 1
int leaf_example (int g, int h, int i, int j)
{
int f ;
f = (g + h) (i + j);
return f;
}
16
9/18/2014
Example 1
leaf_example
addi
$sp, $sp, -12
sw
$t1, 8($sp)
sw
$t0, 4($sp)
sw
$s0, 0($sp)
add
$t0, $a0, $a1
add
$t1, $a2, $a3
sub
$s0, $t0, $t1
add
$v0, $s0, $zero
lw
$s0, 0($sp)
lw
$t0, 4($sp)
lw
$t1, 8($sp)
addi
$sp, $sp, 12
jr
$ra
Example 2
int fact (int n)
{
if (n < 1) return (1);
else return (n * fact(n-1));
}
What is MIPS assembly code?
18
9/18/2014
Example 2
fact:
addi
sw
sw
slti
beq
addi
addi
jr
L1:
addi
jal
lw
lw
addi
mul
jr
$sp, $sp, -8
$ra, 4($sp)
$a0, 0($sp)
$t0, $a0, 1
$t0, $zero, L1
$v0, $zero, 1
$sp, $sp, 8
$ra
$a0, $a0, -1
fact
$a0, 0($sp)
$ra, 4($sp)
$sp, $sp, 8
$v0, $a0, $v0
$ra
19
Example
ra1
a0 = 4
SP
SP
SP, v0 = 6
ra2
a0 = 3
ra3
SP
SP, v0 = 24
a0 = 2
SP, v0 = 2
SP, v0 = 1
ra4
SP
a0 = 1
ra5
SP
SP, v0 = 1
a0 = 0
20
10
9/18/2014
Memory organization
The space allocated on stack by a procedure is termed the
activation record (includes saved values and data local to the
procedure)
Frame pointer points to the start of the record and stack pointer
points to the end
variable addresses are specified relative to $fp as $sp may change
during the execution of the procedure
21
Memory organization
In addition to variables local to procedure, space needed for static
variables and for dynamic data structures
Stack starts from top and grows towards bottom
$gp points to area in memory that saves global variables
Dynamically allocated storage (with malloc()) is placed on the heap
22
11
9/18/2014
MIPS registers
23
These data types are most useful when dealing with characters, pixel
values, etc.
C employs ASCII formats to represent characters each character is
represented with 8 bits and a string ends in the null character
(corresponding to the 8-bit number 0)
For Example Cal in C is represented as 67, 97, 108, 0
24
12
9/18/2014
25
Example
Consider an example
where one string of
characters is copied
into another string of
characters
Convert to assembly:
void strcpy (char x[], char y[])
{
int i;
i=0;
while ((x[i] = y[i]) != `\0)
i += 1;
}
Assume that base addresses for arrays
x and y are found in $a0 and $a1 while
i is in $s0
26
13
9/18/2014
Example
strcpy:
addi $sp, $sp, -4
sw
$s0, 0($sp)
add $s0, $zero, $zero
L1: add $t1, $s0, $a1
lb
$t2, 0($t1)
add $t3, $s0, $a0
sb
$t2, 0($t3)
beq $t2, $zero, L2
addi $s0, $s0, 1
j
L1
L2: lw $s0, 0($sp)
addi $sp, $sp, 4
jr
$ra
Large constants
Immediate instructions can only specify 16-bit constants
The lui instruction is used to store a 16-bit constant into the upper 16 bits
of a register thus, two immediate instructions are used to specify a 32bit constant
For example, what if you want to perform add operation between a 32 bit
immediate number and value stored in $s1?
32 bit number is 0000 0000 0011 1101 0000 1001 0000 0000
lui $s0, 61
$s0 = 0000 0000 0011 1101 0000 0000 0000 0000
ori $s0, $s0, 2304
$s0 = 0000 0000 0011 1101 0000 1001 0000 0000
28
14
9/18/2014
Large constants
The destination PC-address in a conditional branch is specified as a 16-bit
constant, relative to the current PC
A jump (j) instruction can specify a 26-bit constant; if more bits are
required, the jump-register (jr) instruction is used
29
Memory addressing
Byte addressing or word addressing?? 80x86, ARM,
MIPS use byte addressing
Objects are aligned or no? ARM, MIPS yes. 80x86 no
An access to object of size S bytes at byte address A is
aligned if A mod s = 0
30
15
9/18/2014
31
Operations
For example data transfer, arithmetic logical, control, and
floating point
16
9/18/2014
Trends in technology
A successful ISA must be designed to survive technology evolution
Five implementation technologies have changed at a dramatic pace
Integrated circuit logic technology
Transistor density increases by about 35% per year quadrupling every 4 years
Growth in transistor count on a chip about 40% to 55% per year or doubling
every 18 to 24 months (Moores law)
Semiconductor DRAM
Capacity increase 25% to 40% per year doubling roughly every two to three
years
Growth rate getting slower and may hit the wall sooner than later
34
17
9/18/2014
Trends in technology
Semiconductor flash: standard storage device in PMDs
Capacity increases 50% to 60% per year doubling roughly every two
years
15 to 20 times cheaper per bit than DRAM
Network technology
Depends upon performance of both network switches and
transmission systems
From early 80s till today, bandwidth of network switches has increased
10000 times
Latency has improved by 30 times
35
18
9/18/2014
37
19
9/18/2014
39
40
20
9/18/2014
Energy in microprocessors
For a complete transition i.e. 0-1-0
1
2
For power
(
) 1/2
42
21
9/18/2014
43
Overclocking
Run your system in turbo mode for short bursts of time and
then go to sleep
For example a 3.3 GHz core i7 can run at 3.6 GHz for short
periods
Increasing with the process technology and can be as high as
50% of total power
Can be decreased with power gating (turn off power supply)
44
22
9/18/2014
Trends in cost
The impact of time, volume and commoditization
Time
Improved learning curve, better yield
Twice the yield, half the cost
Volume
Increase in volume decreases cost/chip
Decrease in development cost
Decrease in cost by 10% by doubling the volume
45
46
23
9/18/2014
47
Bose-Einstein formula
Defects/area = 0.1 to 0.3 per square inch or 0.016 to 0.057 per square cm
N is process complexity factor. N = 11.5 to 15.5 for 40 nm
48
24
9/18/2014
Dependability
Historically integrated circuits were one of the most reliable
components of a computer
With the advancement in processing technology transient and
permanent faults have become more common
Module/component reliability is a measure of continuous
service accomplishment from a reference initial time
Measure in Mean Time To Failure (MTTF)
Reciprocal of MTTF is Failure In Time (FIT) or failure rate
FIT normally measured in no of failures per billion hour
Principle of locality
90-10 rule of thumb: programs spend 90% of time in 10%
of code
Temporal locality: recently accessed data is likely to be
accessed again in future
Spatial Locality: items whose addresses are near one
another tend to be referenced close together in time
50
25
9/18/2014
Amdahls law
26
9/18/2014
Amdahls law
53
54
27