Académique Documents
Professionnel Documents
Culture Documents
• ALU Operations
• Last Time
– arithmetic (add, sub, mult, div)
– Introduction to ISAs
– logical (and, or, xor, srl, sra)
• Today – data type conversions (cvtf2d, cvtf2i)
– HW#2 assigned Sunday, due 2/15 • Data Movement
– Instruction types – memory reference (lb, lw, sb, sw)
– Memory operations – register to register (movi2fp, movf)
– Control flow operations • Control - what instruction to do next
– Instruction formats – tests/compare (slt, seq)
– branches and jumps (beq, bne, j, jr)
– Case study ISAs – MIPS, others
– support for procedure call (jal, jalr)
– Reading for next time: handout #2
– operating system entry (trap)
• Hair - string compare!
Addressing Modes
Driven by Program Usage Addressing Modes
• Stack relative for locals
double x[100] ; // global Memory and arguments
SP Memory
void foo(int a) { // argument a, j: *(R30+x)
j j
int j ; // local a a
for(j=0;j<10;j++) • Short immediates (small
x[j] = 3 + a*x[j-1] ; constants)
Stack Stack
3
bar(a);
} • Long immediates (global
addressing)
procedure array reference
x &x[0], &bar: 0x3ac1e400 x
• Indexed for array
constant argument references
bar *(R4+R3) bar
foo foo
UTCS, CS352, S07 Lecture 5 3 UTCS, CS352, S07 Lecture 5 4
1
Conditional Branching Support for Procedures
• Compute condition first • Branch and Link
– Condition codes Z N C O – store return address in reg and jump
CMP R1, R2 JALR Rdest: Rx ← PC + 4, PC ← Dest
negative
carry
zero
overflow
BGE LOOP
• Forces CMP and BR to be adjacent
• Subroutine call
– Condition in GP register
– push return address on stack and jump
CMP R3, R1, R2 R3 ZNCO
JAL foo
PC
BGE R3, LOOP Return Here
• Enables parallelism of comparisons • CALLP (VAX)
– Condition in “condition” register – push return address
Cn C2 C1 C0
– set up stack frame
• Fuse condition check and branch – save registers
foo
BGE R1, R2, LOOP – ...
– reduces instruction count, but complicates pipelining
2
MIPS ISA MIPS ISA (a visual)
Plus a 3-deep stack of mode bits. Which add for address arithmetic? Which add for integers?
UTCS, CS352, S07 Lecture 5 15 UTCS, CS352, S07 Lecture 5 16
3
MIPS data transfer instructions MIPS Compare and Branch
R5 0000 … 0000
MIPS jump, branch, compare instructions Details of the MIPS instruction set
Instruction Example Meaning
• Register zero always has the value zero (even if you try to write it)
branch on equal beq $1,$2,100 if ($1 == $2) go to PC+4+100
Equal test; PC relative branch • Branch/jump and link put the return addr. PC+4 into the link register (R31)
branch on not eq. bne $1,$2,100 if ($1!= $2) go to PC+4+100 • All instructions change all 32 bits of the destination register (including lui,
Not equal test; PC relative lb, lh) and all read all 32 bits of sources (add, sub, and, or, …)
set on less than slt $1,$2,$3 if ($2 < $3) $1=1; else $1=0
Compare less than; 2’s comp. • Immediate arithmetic and logical instructions are extended as follows:
set less than imm. slti $1,$2,100 if ($2 < 100) $1=1; else $1=0 – logical immediates ops are zero extended to 32 bits
Compare < constant; 2’s comp. – arithmetic immediates ops are sign extended to 32 bits (including addu)
set less than uns. sltu $1,$2,$3 if ($2 < $3) $1=1; else $1=0 • The data loaded by the instructions lb and lh are extended as follows:
Compare less than; natural numbers – lbu, lhu are zero extended
set l. t. imm. uns. sltiu $1,$2,100 if ($2 < 100) $1=1; else $1=0 – lb, lh are sign extended
Compare < constant; natural numbers
• Overflow can occur in these arithmetic and logical instructions:
jump j 10000 go to 10000
– add, sub, addi
Jump to target address
jump register jr $31 go to $31 • It cannot occur in
For switch, procedure return – addu, subu, addiu, and, or, xor, nor, shifts, mult, multu, div, divu
jump and link jal 10000 $31 = PC + 4; go to 10000
For procedure call
– Endianness
unaligned word access
0x1004 0x1000
4
Endianness Data Types
• How are bytes ordered within a word? • How the contents of • Most general purpose
memory and registers are computers support several
– Little Endian (Intel/DEC) interpreted types
• Can be identified by – 8, 16, 32, 64-bit
3 2 1 0 – tag – signed and unsigned
0x1003 0x1002 0x1001 0x1000 – use – fixed and floating
• Driven by application
– Big Endian (IBM/Motorola) – Signal processing int 0x8a1c
• 16-bit fixed point
(fraction)
0 1 2 3 str “abcd”
– Text processing
0x1000 0x1001 0x1002 0x1003
• 8-bit characters
– Today - most machines can do either (configuration
– Scientific computing Examples of tags (ie. Symbolics machine)
register)
• 64-bit floating point