Transcript Chapter 8

Chapter 8 – Machine Instructions
These are lecture notes to accompany the book
SPARC Architecture, Assembly Language
Programming, and C,
by Richard P. Paul, 2nd edition, 2000.
Updated Spring 2014
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
Decoding Instructions
• SPARC Instructions are 32 bits long
op
31 30
29
0
• Bits <31:30> specify the “op” field
• These first 2 bits indicate how the other bits
should be handled.
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
Decoding Instructions
• Instructions are classified according to “op”
op
31 30
29
0
op
Instruction class
00
Branch instructions
01
Call instructions
10
Format Three instructions
11
Format Three instructions
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
Format 1 Instructions
01
31 30
30 bit displacement
29
• Call instruction
• The displacement must be word aligned
• Address is calculated by right shifting
displacement 2 positions
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
0
Format 2 Instructions
• branch
00 a
31 30
cond
29 28
op2
25 24
22 bit immediate
22 21
0
• sethi
00
31 30
rd
29
100
25 24
22 bit immediate
22 21
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
0
Branch Instructions
• The branch is (or is not) taken based on the “cond”
(condition) field.
• op2 = 010 means integer condition code
cond
branch type
cond
branch type
0000
never
1000
always
0001
if equal to zero
1001
if not equal to zero
0010
if less than or equal to zero
1010
if greater than zero
0011
if less than zero
1011
if greater than or equal to zero
0100
if less or equal, unsigned
1100
if greater, unsigned
0101
if carry set
1101
if carry is clear
0110
if negative
1110
if positive
0111
if overflow is set
1111
if overflow is clear
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
Format 3 Instructions
• 2 source registers
1x
31 30
rd
29
op3
25 24
rs1
19 18
0
14 13 12
rs2
5 4
0
• Immediate constant
1x
31 30
rd
29
op3
25 24
rs1
19 18
1 signed 13-bit #
14 13 12
5 4
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
0
Format Three Instructions
• Not all possible bits patterns are used
• op = 10
op3
Instruction
op3
Instruction
000000
add
111000
jumpl
000001
and
111001
rett
000010
or
111010
ticc
000011
xor
111011
iflush
000100
sub
111100
save
000101
andn
111101
restore
000110
orn
111110
<unused>
000111
xnor
111111
<unused>
001000
addx
See page 235 for a complete list
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
Format Three Instructions
• Not all possible bits patterns are used
• op = 11
op3
Instruction
000000
ld
000001
ldub
000010
lduh
000011
ldd
000100
st
000101
stb
000110
sth
000111
std
001000
<unused>
See page 236 for a complete list
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
Register coding
Register
Synonyms
Register
Synonyms
Register
Synonyms
Register
Synonyms
%g0
%r0
%o0
%r8
%l0
%r16
%i0
%r24
%g1
%r1
%o1
%r9
%l1
%r17
%i1
%r25
%g2
%r2
%o2
%r10
%l2
%r18
%i2
%r26
%g3
%r3
%o3
%r11
%l3
%r19
%i3
%r27
%g4
%r4
%o4
%r12
%l4
%r20
%i4
%r28
%g5
%5
%o5
%r13
%l5
%r21
%i5
%r29
%g6
%r6
%o6
%r14
%l6
%r22
%i6
%r30
%g7
%r7
%o7
%r15
%l7
%r23
%i7
%r31
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
Load/Store instructions
• Load and Store instructions have two
references – a register and memory location
• rd field – refers to the register component
• rs1 field – refers to register for memory
address
• rs2 field/immediate – refers to offset for
memory address
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
Load/Store examples
ldub [%o3 + %l2], %o1
rd
rs2
rs1
stb %l0, [%o1 + %o2]
rd
rs1
rs2
stb %o5, [%o1 + 50]
rd
rs1
immediate
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C
Example
• Decode the following commands:
0x9de3bfa0
0xd007bfec
0x92102004
0x90020009
0xd027bfec
0x81c7e008
0x81e80000
save %sp, -96, %sp
ld
[%fp-20], %o0
mov 4, %o1
add %o0, %o1, %o0
st
%o0, [%fp-20]
ret
restore
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C