lesson09.ppt

advertisement
CISC versus RISC
Two competing philosophies for
the design of a processor’s
instruction-set
The RISC idea
• RISC: Reduced Instruction-Set Computer
– There will be a relatively small number of very
simple operations that the CPU can execute,
which the programmer uses as basic building
blocks for constructing complex algorithms
– Because there are so few instructions, they
can be uniquely identified by only a few bits
– Hence these short instructions can be more
quickly fetched, decoded, and executed
The CISC idea
• CISC: Complex Instruction-Set Computer
– Identify the most important operations that a
computer will need to perform, then build the
circuitry for each one of those operations into
its own special-purpose machine-instruction
– Instead of fetching a large number of small
instructions, it will be more efficient to fetch
and execute just one very powerful instruction
Some x86 CISC instructions
• The x86’s ‘string-manipulation’ instructions
are examples of the CISC philosophy
• These instructions are specially designed
to do the most common ‘word processing’
operations in an optimized manner (e.g.,
copying, comparing, and searching long
strings of characters stored in memory)
The string operations
•
•
•
•
•
•
•
Move-string: movs
Compare-strings: cmps
Scan-string: scas
Store-string: stos
Load-string: lods
Output-string: outs
Input-string: ins
Initial setup
• Each of the string-instructions requires a
certain amount of preparatory setup, but
then can repeatedly execute an operation
without needing to re-fetch and re-decode
• Hence the overall string-operation can be
done more efficiently than could be done
by using a customary program-loop
Example: ‘strlen’
#
# Finding the length of a null-terminated string of ASCII character-codes
#
mov
$msg, %rdi
# point RDI to beginning of the string
mov
$0, %al
# setup the null-byte’s value in AL
cld
# clear the DF-bit in EFLAGS
mov
$-1, %rcx
# maximum unsigned integer in RCX
repne
scasb
# scan string for its first NULL byte
sub
$msg, %rdi
# subtract start to get string length
Midterm question
• On a different topic, we show a slide which
conveys an idea for solving Question V
• Most of the code in our ‘myargs.s’ demo
can be reused, but a couple of changes
will be needed:
– Start from the end of the array of pointers,
instead of from the beginning
– Decrement the array-index upon each pass
through the loop, instead of incrementing it
‘reorder.s’
command-line:
$ ./reorder xx yyy zzzz
0
8
16
argc (=4)
argv0
24
argv1
32
40
argv2
argv3
NULL (=0)
x x
y y y
z z z z
RSP
.
/
r e o r d e r
argc (argument count) = number of strings
typed on the command-line
mov (%rsp), %rbx
dec %rbx
mov 8( %rsp, %rbx, 8 ), %rsi
 RSI (=argv3)
Download