Anda di halaman 1dari 10

C Fortran Ada etc.

Basic Java

Compiler Compiler
Instruction Set Architecture
Assembly Language Byte Code

Nizamettin AYDIN Assembler Interpreter


naydin@yildiz.edu.tr
http://www.yildiz.edu.tr/~naydin Executable
http://akademik.bahcesehir.edu.tr/~naydin
Instruction Set Architecture

HW HW HW
Implementation 1 Implementation 2 Implementation N

Instruction Set Instruction Types


• Instruction: Language of the machine
• Data processing
• Instruction set: Vocabulary of the language (Collection of —ADD, SUB
instructions that are understood by a CPU)
lda, sta, brp, jmp, nop, ... (VVM)

• Machine Code • Data storage (main memory)


— machine readable
— Binary(example: 1000110010100000)
—STA

• Usually represented by assembly codes


— Human readable • Data movement (I/O)
— Example: VVM code adding a number entered from keyboard
and a number in memory location 40 —IN, OUT, LDA
0 in
1 sta 30
2 add 40
3 sta 50 • Program flow control
4 hlt —BRZ

Elements of an Instruction Source and Result Operands


• Operation code (Op-code) • Source and Result Operands can be in one
—Do this of the following areas:
—Example: ADD 30 (VVM code)
• Source Operand reference —Main memory
—To this
—Example: LDA 50 (VVM code) —Virtual memory
• Result Operand reference
—Put the result here —Cache
—Example: STA 60 (VVM code)
• Next Instruction Reference —CPU register
—When you have done that, do this...
—I/O device
—PC points to the next instruction

1
Instruction Representation Simple Instruction Format
• In machine code each instruction has a • Following is a 16 bit instruction format
unique bit pattern
• For human consumption a symbolic
representation is used (assembly language)
• Opcodes are represented by abbreviations,
called mnemonics indicating the operation
— ADD, SUB, LDA, BRP, ...
• In an assembly language, operands can also • So...
—What is the maximum number of instructions
be represented as following
in this processor?
—ADD A,B (add contents of B and A and save
—What is the maximum directly addressable
the result into A)
memory size?

Instruction Set Classification Zero Address Machine


• One way • a.k.a. Stack Machines
—Number of operands for typical arithmetic
instruction
• Example:
add $s1, $s2, $s3
3 PUSH b
a = b + c;

# Push b onto stack


—What are the possibilities? PUSH c # Push c onto stack
ADD # Add top two items
—Will use this C statement as an example: # on stack and replace
# with sum
a = b + c;
POP a # Remove top of stack
—Assume a, b and c are in memory # and store in a

One Address Machine Two Address Machine (1)


• a.k.a. Accumulator Machine • a.k.a. Register-Memory Instruction Set
• One operand is implicitly the accumulator • One operand may be a value from
memory
• Example: a = b + c; • Machine has n general purpose registers
—$0 through $n-1
LOAD b # ACC ← b
ADD c # ACC ← ACC + c
STORE a # a ← ACC • Example: a = b + c;

• A good example for such a machine is... LOAD $1, b # $1 ← M[b]


ADD $1, c # $1 ← $1 + M[c]
VVM STORE $1, a # M[a] ← $1

2
Two Address Machine (2) Two Address Machine (3)
• a.k.a. Memory-Memory Machine • a.k.a. Load-Store Instruction Set or
• Another possibility do stuff in memory! Register-Register Instruction Set
• These machines have registers used to • Typically can only access memory using
compute memory addresses load/store instructions
• 2 addresses (One address doubles as
operand and result) • Example: a = b + c;

LOAD $1, b # $1 ← M[b]


• Example: a = b + c;
LOAD $2, c # $2 ← M[c]
ADD $1, $2 # $1 ← $1 + $2
MOVE a, b # M[a] ← M[b]
STORE $1, a # M[a] ← $1
ADD a, c # M[a] ← M[a] + M[c]

Utilization of Instruction Addresses


Three Address Machine (Nonbranching Instructions)
• a.k.a. Load-Store Instruction Set or Register-
Register Instruction Set
• Typically can only access memory using
load/store instructions
• 3 addresses (Operand 1, Operand 2, Result)
— May be a forth - next instruction (usually implicit)
— Needs very long words to hold everything

• Example: a = b + c;

LOAD $1, b # $1 ← M[b]


LOAD $2, c # $2 ← M[c]
ADD $3, $1, $2 # $3 ← $1 + $2
STORE $3, a # M[a] ← $3

History Performans (which one is better?)

Hardware Expensive Hardware Less Hardware and Memory


• More addresses
Memory Expensive Expensive Cheap —More complex (powerful?) instructions
Memory Expensive
—More registers
Accumulators Microprocessors
Register Oriented Compilers getting good – Inter-register operations are quicker
EDSAC Machines (2 address) —Fewer instructions per program
IBM 701 Register-Memory CISC
IBM 360 VAX
DEC PDP-11 Motorola 68000 • Fewer addresses
Also Intel 80x86
Fringe Element RISC —Less complex (powerful?) instructions
Berkley RISC→Sparc
Stack Machines Dave Patterson —More instructions per program
Burroughs B-5000 Stanford MIPS →SGI
(Banks) John Hennessy
—Faster fetch/execution of instructions
IBM 801

1940 1950 1960 1970 1980 1990

3
Types of Operand Pentium Data Types

• Addresses • 8 bit (byte), 16 bit (word), 32 bit (double


word), 64 bit (quad word)
—Operand is in the address
• Numbers (actual operand)
—Integer or fixed point • Addressing in Pentium is by 8 bit units
—floating point • A 32 bit double word is read at addresses
—decimal divisible by 4:
• Characters (actual operand) 0100 1A 22 F1 77
—ASCII etc. +0 +1 +2 +3

• Logical Data (actual operand)


—Bits or flags

Specific Data Types


• General - arbitrary binary contents
• Integer - single binary value Pentium
• Ordinal - unsigned integer Numeric
Data
• Unpacked BCD - One digit per byte
Formats
• Packed BCD - 2 BCD digits per byte
• Near Pointer - 32 bit offset within
segment
• Bit field
• Byte String
• Floating Point

PowerPC Data Types Types of Operation


• 8 (byte), 16 (halfword), 32 (word) and 64
(doubleword) length data types • Data Transfer
• Fixed point processor recognises: • Arithmetic
—Unsigned byte, unsigned halfword, signed • Logical
halfword, unsigned word, signed word,
unsigned doubleword, byte string (<128 • Conversion
bytes) • I/O
• Floating point • System Control
—IEEE 754 • Transfer of Control
—Single or double precision

4
Data Transfer Arithmetic
• Need to specify • Basic arithmetic operations are...
—Source —Add
—Subtract
—Destination
—Multiply
—Amount of data —Divide
—Increment (a++)
• May be different instructions for different —Decrement (a--)
—Negate (-a)
movements
—Absolute

• Or one instruction and different addresses • Arithmetic operations are provided for...
—Signed Integer
—Floating point?
—Packed decimal numbers?

Logical Basic Logical Operations


• Bitwise operations
• AND, OR, NOT
—Example1: bit masking using AND operation
– (R1) = 10100101
– (R2) = 00001111
– (R1) AND (R2) = 00000101

—Example2: taking ones coplement using XOR


operation
– (R1) = 10100101
– (R2) = 11111111
– (R1) XOR (R2) = 01011010

Shift and Rotate


Operations Examples of Shift and Rotate Operations

5
An example To send the two characters in a word

• Suppose we wish to transmit characters of • Load the word into a register


data to an I/O device 1 character at a • AND with the value 1111111100000000
time. — This masks out the character on the right
• If each memory word is 16 bits in length • Shift to the right eight times
and contains two characters, we must —This shifts the remaining character to the right
unpack the characters before they can be half of the register
sent. • Perform I/O
—The I/O module reads the lower-order 8 bits
from the data bus.

To send the two characters in a word Conversion

The preceding steps result in sending the


• Conversion instructions are those that
left-hand character.
change the format or operate on the
format of data.
To send the right-hand character:
• For example:
• Load the word again into the register —Binary to Decimal conversion
• AND with 0000000011111111
• Perform I/O

Input/Output Systems Control

• May be specific instructions


—IN, OUT
• Privileged instructions

• May be done using data movement • CPU needs to be in specific state


instructions (memory mapped)
• For operating systems use
• May be done by a separate controller
(DMA)

6
Transfer of Control Branch Instruction
• Branch
—For example: brz 10 (branch to 10 if result is
zero)

• Skip
—e.g. increment and skip if zero
—ISZ Register1
—Branch xxxx
—ADD A

• Subroutine call
—c.f. interrupt call

Nested Procedure Calls Use of Stack

Types of Types of
Operation Operation

7
Pentium Operation
CPU Actions for Various Types of Operations Types

Pentium Condition Codes

Pentium Conditions for Conditional Jump and MMX


SETcc Instructions Instruction Set

8
PowerPC
Operation Types PowerPC Operation Types

Byte Ordering Byte Ordering Example


• Big Endian
• How should bytes within multi-byte word
—Least significant byte has highest address
be ordered in memory?
• Little Endian
—Least significant byte has lowest address
• Some conventions
• Example
—Sun’s, Mac’s are “Big Endian” machines
—Variable x has 4-byte representation
– Least significant byte has highest address
0x01234567
—Alphas, PC’s are “Little Endian” machines
– Least significant byte has lowest address
—Address given by &x is 0x100
Big Endian 0x100 0x101 0x102 0x103
01 23 45 67

Little Endian 0x100 0x101 0x102 0x103


67 45 23 01

Representing Integers Representing Pointers


• int A = 15213; Decimal: 15213 • int B = -15213; Alpha P
• int B = -15213; Binary: 0011 1011 0110 1101 • int *P = &B; A0
• long int C = 15213; Hex: 3 B 6 D Alpha Address FC
Hex: 1 F F F F F C A 0 FF
Linux/Alpha A Sun A Linux C Alpha C Sun C FF
Binary: 0001 1111 1111 1111 1111 1111 1100 1010 0000 01
6D 00 6D 6D 00
3B 00 Sun P 00
3B 3B 00 Sun Address
00 3B 00
00 00 3B EF
00 6D Hex: E F F F F B 2 C 00
00 00 6D FF Binary: 1110 1111 1111 1111 1111 1011 0010 1100 Linux P
00 FB
Linux/Alpha B Sun B 00 2C Linux Address D4
00 F8
93 FF Hex: B F F F F 8 D 4
00 FF
C4 FF Binary: 1011 1111 1111 1111 1111 1000 1101 0100
BF
FF C4
FF 93 Two’s complement representation Different compilers & machines assign different locations to objects
(Covered next lecture)

9
Representing Floats Representing Strings
• Float F = 15213.0; • Strings in C • char S[6] = "15213";
Linux/Alpha F Sun F
—Represented by array of characters
00 46
B4 6D
—Each character encoded in ASCII format
6D B4 – Standard 7-bit encoding of character set
46 00 – Character “0” has code 0x30
+ Digit i has code 0x30+i Linux/Alpha S Sun S
—String should be null-terminated 31 31
IEEE Single Precision Floating Point Representation 35 35
– Final character = 0
Hex: 4 6 6 D B 4 0 0 32 32
Binary: 0100 0110 0110 1101 1011 0100 0000 0000 • Compatibility 31 31
15213: 1110 1101 1011 01 —Byte ordering is not an issue 33 33
00 00
– Data are single byte quantities
Not same as integer representation, but consistent across machines —Text files generally platform independent
Can see some relation to integer representation, but not obvious – Except for different conventions of line termination
character(s)!

Common file formats and their endian order are


Example of C Data Structure as follows:
• Adobe Photoshop -- Big Endian
• BMP (Windows and OS/2 Bitmaps) -- Little Endian
• DXF (AutoCad) -- Variable
• GIF -- Little Endian
• IMG (GEM Raster) -- Big Endian
• JPEG -- Big Endian
• FLI (Autodesk Animator) -- Little Endian
• MacPaint -- Big Endian
• PCX (PC Paintbrush) -- Little Endian
• PostScript -- Not Applicable (text!)
• POV (Persistence of Vision ray-tracer) -- Not Applicable (text!)
• QTM (Quicktime Movies) -- Little Endian (on a Mac!)
• Microsoft RIFF (.WAV & .AVI) -- Both
• Microsoft RTF (Rich Text Format) -- Little Endian
• SGI (Silicon Graphics) -- Big Endian
• Sun Raster -- Big Endian
• TGA (Targa) -- Little Endian
• TIFF -- Both, Endian identifier encoded into file
• WPG (WordPerfect Graphics Metafile) -- Big Endian (on a PC!)
• XWD (X Window Dump) -- Both, Endian identifier encoded into file

10

Anda mungkin juga menyukai