Development/Plasticity/Repair LossofIntercalatedCells(ITCs ...
Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language...
-
Upload
amy-hensley -
Category
Documents
-
view
218 -
download
1
Transcript of Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language...
![Page 1: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/1.jpg)
Implementation of a Stored Program Computer
• Memory addressing• Machine instructions• Assembly language notation• Addressing formats
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides2.ppt Modification date: March 16, 2015 1
![Page 2: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/2.jpg)
2
Instructions: Processor fetches binary encoded machine instructions from memory and performs actions defined, e.g. add two numbers together and put result back in memory.
Data: Needed for the calculation stored in memory.
Main Memory
Holds list of executablemachine instructions, and data(as binary patterns)
Processor
Main memory• Set of storage locations holding binary patterns.
• Used to hold both machine instructions and data
![Page 3: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/3.jpg)
3
Memory Addressing
2n locations requiren-bit address
01234
2n 1
Address Memory
Memorylocation
• Each location given a unique address (a binary number starting from zero).
• Each “addressable” location holds a fixed number of bits.
• Any location can be accessed at high speed in any order (random access memory).
How many bits in each location?
![Page 4: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/4.jpg)
4
Size of memory locations
In the early days of computers (perhaps up to 1970), various sizes existed e.g. 24 bits, 36 bits, 40 bits, etc.Usually dictated by the number of bits in the instruction.
Currently (and for last 40 years at least), each addressable
memory location holds 8 bits (a byte).
Originally convenient for holding ASCII (American Standard Code for Information Interchange) code that represented alphanumeric characters (letters, digits, symbols as found on a keyboard).
More recently Unicode/UTF-8 variable width encoding (1 - 4 bytes) mostly used, see www.unicode.org/
![Page 5: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/5.jpg)
5
Size of memory locations continuedEight bits not large enough for encoding machine instructions or most numbers. For more than eight bits, consecutive locations used. Address given by address of first location.
Example
int a, b, c, d;
Declaring variables as integers usually means 32-bit integers.
Suppose the integer variables a, b, c, and d are located at addresses 0, 4, 8, 12.
a
b
c
00..00000
00..00100
00..01000
00..01100
d
Address(in binary)
Memory
0
4
8
12
![Page 6: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/6.jpg)
6
Little endian (little end first)
nn+1n+2n+3
Memory
031
Most Leastsignificant
bytesignificant
byte
32-bit word
Address
Addressof 32-bit word
Memory physically organized so that all32 bit transferred simultaneously along bus
nn+1n+2n+3
Memory
031
Most Leastsignificant
bytesignificant
byte
32-bit word
Address
Addressof 32-bit word
Memory physically organized so that all32 bit transferred simultaneously along bus
Big endian (big end first)
Early common approachFound in some current processorsUsed in network protocols
Intel uses little endian (a little easier logic)
Little endian/big endian from Gulliver’s Travels
![Page 7: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/7.jpg)
7
QuestionSuppose a compiler uses memory locations starting from location zero to hold the variable x using big endian representation. Specify what would be in these memory locations (in binary) if the program has the statement:
int x = 17;
Memory is byte-addressable (each location holding a byte) and x is a 32-bit number.
Answer
0
1
2
3 0 0 0 1 0 0 0 117 = 0..010001
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Address
![Page 8: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/8.jpg)
8
Follow-on question
Suppose x is then read from memory by a processor using little endian representation. What value would it get?
Answer
0
1
2
3 0 0 0 1 0 0 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Address
00010001000000000000000000000000224
20
228 +
Answer
![Page 9: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/9.jpg)
9
Machine Instructions
The operation of an instruction reduced to a very simple form.
Consider a calculation one might write in a high level language:
x = (y + z) / (a - b);
where a, b, x, y, and z are declared as integers.
Unreasonable to provide a specific machine instruction just for this calculation.
Need to break down calculation into a series of simple arithmetic operations.
![Page 10: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/10.jpg)
10
Suppose the variables a, b, x, y, and z are stored by the compiler in memory locations 100, 104, 108, 112, and 116:
100104108112116
xyzab
temp1
x = (y + z) /(a - b);
temp2
+
-/
Memory
Address
temp1 = y + ztemp2 = a - bx = temp1/temp2
temp1, temp2 could be memory locations but better to use fast internal register storage, see later. Note: integers are stored in registers by the compiler if possible
![Page 11: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/11.jpg)
11
Machine Instructions
Each of the steps in the previous example:
temp1 = y + z
temp2 = a - b
x = temp1/temp2
might be encoded into one machine instruction.
Each machine instruction usually only has one operation (+, - etc), possibly two source operands, and a single result.
![Page 12: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/12.jpg)
12
Machine Instruction Encoding
A binary pattern that specifies one operation (usually), the operands used for the operation and where the result should be placed if any.
Specifies location of source operands
Operation
Opcodeand where to put result
(various methods - see next)
Addition, subtraction, etc .
Number bits may be fixed or may be variabledepending upon design of processor
![Page 13: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/13.jpg)
13
Op-code Encoding
Suppose there were 60 different operations, add subtract, multiply, divide, etc. Six bits would be sufficient (25 <= 60 < 26). Could allocate one pattern for each operation:
Exampleop-code
ADD (“ADD”) 000001SUBTRACT (“SUB”) 000010MULTIPLY (“MUL”) 000011DIVIDE (“DIV”) 000100
etc. . .
Sometimes more complex encoding used. Many possibilities.Pattern of all zeros often reserved for no operation (“no-op”)
![Page 14: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/14.jpg)
14
Specifying the Locations of Operands
First let us assume operands and results in main memory:
Three-Address Format
Memory Addresses
Operation Result 1st operand 2nd operand
Three-address format
Opcode
NoteOrder of operands here is with destination first but it could be different depending upon processor.
![Page 15: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/15.jpg)
15
Example:
Addition
+100
200
300
Memory ADD 300 200 100
Processor
Instruction
Address
Op-code pattern for ADD here
![Page 16: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/16.jpg)
16
Machine Instruction
The processor executes machine instructions which are binary patterns. The previous machine instruction might be encoded as:
ADD 300 200 100
Machine
000001 000...00100101100 000...00011001000 000...00001100100
32 32 326
instruction
where in this case, 6 bits in opcode and 32 bits for each address.
![Page 17: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/17.jpg)
17
Assembly Language and Machine Instructions
Much more convenient to use an “assembly language” notation to describe machine instruction rather than actual binary patterns.
Previous machine instruction might be written in assembly language as:
ADD [300], [200], [100]
where [ ] means “contents of memory”, a common notation. ADD is the op-code mnemonic.
![Page 18: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/18.jpg)
18
The 3-(memory) address format has the disadvantages:
• Long instruction length• Three memory accesses
and rarely used.
![Page 19: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/19.jpg)
19
Two-Address Format
Operands and results in memory. One operand and result same location
Operation1st operand
2nd operand
Two-address format
and result
AddressesOpcode
Eliminates one address
![Page 20: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/20.jpg)
20
Example:
ADD [200], [100]
+100
200
Memory Processor
ADD 200 100
Instruction
![Page 21: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/21.jpg)
21
Disadvantages:
• One operand overwritten• Still needs three memory accesses
![Page 22: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/22.jpg)
22
One-Address Format
Only one location allowed for one operand and result, a location within the processor, called an accumulator historically.
Other operand still in main memory, and its address given in instruction:
AddressesOpcode
Operation
One-address format
2nd operand
![Page 23: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/23.jpg)
23
Example
ADD [100]
+100
Memory
Processor
ADD 100
AccumulatorInstruction
![Page 24: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/24.jpg)
24
Advantages:
• Shorter instruction• Eliminates two memory accesses• Faster accessing location inside processor than memory
Disadvantages:
• Only one location for one operand and result• Still needs one memory access
![Page 25: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/25.jpg)
25
Register Format
Have more than one location within processor - set of registers.
Operation Register 2nd operand
Register-memory format
AddressesOpcode
If there were 32 registers, say R0 to R31, 5 bits are required in each field to specify the register.
This format sometimes called 1 ½ address format.
![Page 26: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/26.jpg)
26
Example
ADD R1, [100]
100
Memory
Processor
ADD 100
Instruction
+
R4R3R2R1R0
Registers
R311
Refers to register R1
![Page 27: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/27.jpg)
27
Register-Register Formats
With registers, can now hold all operands in registers and operate on registers only:
Operation Register
Opcode
Register
1st operand/result 2nd operand
Operation Register
Opcode
Register
Result 2nd operand
Register
1st operand
If 2 registers specified
If 3 registers specified
![Page 28: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/28.jpg)
28
Example
ADD R3,R1,R2
+
Processor
ADD 3 1 2
R4R3R2R1R0
Registers Instruction
R31
![Page 29: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/29.jpg)
29
Zero-Address Format
Possible to eliminate all addresses by using specific locations.Then only the operation need be specified in the instruction
Usually locations for operands/result are top two locations of a stack (a last-in first-out queue) in memory or implemented with registers within processor.
Stack pointer - a register within processor used to hold the address of the top location.
Operation
Opcode
![Page 30: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/30.jpg)
30
Example
ADD
+
Stack
Processor
100100
Stack pointer
ADD
Could be insideprocessor, but usually in memory
Instruction
Zero-address format useful to compilers for producing code for arithmetic expressions (using reverse Polish notation)Used by Burroughs in their computers in the 1960’s and not widely since (but re-introduced in SUN Java chip).
![Page 31: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/31.jpg)
31
We have outlined several instruction format possibilities:
• 3-address (3 memory addresses)
• 2-address (2 memory addresses)
• 1-address (1 memory address with an accumulator)
• 1½ address (one memory address and one register address)
• Register (3 registers or 2 registers)
• Zero-address (no memory addresses, uses stack and stack pointer)
A particular processor will not use all formats.
![Page 32: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/32.jpg)
32
Examples
Intel 64/IA-32 instruction set processors (continuing early 8086 processor designs)
• From an external perspective, 1½ address (register-memory) and register formats.
IBM PowerPC, SUN Sparc processor and other so-called reduced instruction set computers
• 3-register format for arithmetic and register-memory format for accessing memory operands. More details later.
![Page 33: Implementation of a Stored Program Computer Memory addressing Machine instructions Assembly language notation Addressing formats ITCS 3181 Logic and Computer.](https://reader030.fdocuments.us/reader030/viewer/2022032522/56649d6e5503460f94a4fe59/html5/thumbnails/33.jpg)
33
Questions