chapter 5 modes understand the concepts of instruction
play

Chapter 5 modes. Understand the concepts of instruction-level A - PowerPoint PPT Presentation

Chapter 5 Objectives Understand the factors involved in instruction set architecture design. Gain familiarity with memory addressing Chapter 5 modes. Understand the concepts of instruction-level A Closer Look at pipelining and its


  1. Chapter 5 Objectives • Understand the factors involved in instruction set architecture design. • Gain familiarity with memory addressing Chapter 5 modes. • Understand the concepts of instruction-level A Closer Look at pipelining and its affect upon execution Instruction Set performance. Architectures 2 5.1 Introduction 5.2 Instruction Formats • This chapter builds upon the ideas in Chapter 4 . Instruction sets are differentiated by the following: • Number of bits per instruction. • We present a detailed look at different instruction formats, operand types, and memory • Stack-based or register-based. access methods. • Number of explicit operands per instruction. • We will see the interrelation between machine • Operand location. organization and instruction formats. • Types of operations. • This leads to a deeper understanding of • Type and size of operands. computer architecture in general. Employers frequently prefer to hire people with assembly language background, not because they need an assembly language programmer, but because they need someone who can understand computer architecture to write more efficient and more effective programs. 3 4

  2. 5.2 Instruction Formats 5.2 Instruction Formats Instruction set architectures are measured In designing an instruction set, consideration is according to: given to: • Instruction length. • Main memory space occupied by a program. – Whether short, long, or variable. • Instruction complexity. • Number of operands. • Instruction length (in bits). • Number of addressable registers. • Memory organization. • Total number of instructions in the instruction set. – Whether byte- or word addressable. • Addressing modes. – Choose any or all: direct, indirect or indexed. 5 6 5.2 Instruction Formats 5.2 Instruction Formats • Byte ordering, or endianness , is another major • As an example, suppose we have the architectural consideration. hexadecimal number 12345678. • If we have a two-byte integer, the integer may be • The big endian and little endian arrangements of stored so that the least significant byte is followed the bytes are shown below. by the most significant byte or vice versa. – Big endian machines store the most significant byte first (at the lower address). – In little endian machines, the least significant byte is followed by the most significant byte. 7 8

  3. 5.2 Instruction Formats 5.2 Instruction Formats • Big endian: • The next consideration for architecture design concerns how the CPU will store data. – Is more natural. – The sign of the number can be determined by looking at • We have three choices: the byte at address offset 0. 1. A stack architecture – Strings and integers are stored in the same order. 2. An accumulator architecture • Little endian: 3. A general purpose register architecture. – Conversion from a 16-bit integer address to a 32-bit • In choosing one over the other, the tradeoffs are integer address does not require any arithmetic. simplicity (and cost) of hardware design with – Makes it easier to place values on non-word boundaries. execution speed and ease of use. 9 10 5.2 Instruction Formats 5.2 Instruction Formats • Most systems today are GPR systems. • In a stack architecture, operands are implicitly taken from the stack. • There are three types: – A stack cannot be accessed randomly. – Memory-memory where two or three operands may be in • In an accumulator architecture, one operand of a memory. binary operation is implicitly in the accumulator. – Register-memory where at least one operand must be in a register. – One operand is in memory, creating lots of bus traffic . • In a general purpose register (GPR) architecture, – Load-store where only the load and store instructions can access memory. registers can be used instead of memory. – Faster than accumulator architecture. • The number of operands and the number of – Efficient implementation for compilers. available registers has a direct affect on instruction – Results in longer instructions. length. 11 12

  4. 5.2 Instruction Formats 5.2 Instruction Formats • Stack machines use one - and zero-operand • Stack architectures require us to think about instructions. arithmetic expressions a little differently. • PUSH and POP instructions require a single • We are accustomed to writing expressions using infix memory address operand. notation, such as: Z = X + Y. • PUSH and POP operations involve only the stack’s • Stack arithmetic requires that we use postfix notation: top element. Z = XY+. • Other instructions use operands from the stack implicitly. – This is also called reverse Polish notation , (somewhat) in honor of its Polish inventor, Jan Lukasiewicz (1878 - 1956). • Binary instructions (e.g., ADD , MULT ) use the top two items on the stack. 13 14 5.2 Instruction Formats 5.2 Instruction Formats • The principal advantage of postfix notation is • Example: Convert the infix expression (2+3) - 6/3 that parentheses are not used. to postfix: • For example, the infix expression, Z = (X × Y) + (W × U) The sum 2 + 3 in parentheses takes 2 3+ - 6/3 precedence; we replace the term with becomes: 2 3 +. Z = X Y × W U × + in postfix notation. 15 16

  5. 5.2 Instruction Formats 5.2 Instruction Formats • Example: Convert the infix expression (2+3) - 6/3 • Example: Convert the infix expression (2+3) - 6/3 to postfix: to postfix: The division operator takes next The quotient 6/3 is subtracted from the 2 3 + - 6 3 / 2 3 + 6 3 / - precedence; we replace 6/3 with sum of 2 + 3, so we move the - operator to the end. 6 3 /. 17 18 5.2 Instruction Formats 5.2 Instruction Formats • Example: Use a stack to evaluate the postfix • Example: Use a stack to evaluate the postfix expression 2 3 + 6 3 / - : expression 2 3 + 6 3 / - : Pop the two operands and 2 3 + 6 3 / - 2 3 + 6 3 / - carry out the operation Scanning the expression from left to right, push indicated by the operator. operands onto the stack, Push the result back on the until an operator is found stack. 3 5 2 19 20

  6. 5.2 Instruction Formats 5.2 Instruction Formats • Example: Use a stack to evaluate the postfix • Example: Use a stack to evaluate the postfix expression 2 3 + 6 3 / - : expression 2 3 + 6 3 / - : 2 3 + 6 3 / - 2 3 + 6 3 / - Carry out the operation and Push operands until another push the result. 3 operator is found. 2 6 5 5 21 22 5.2 Instruction Formats 5.2 Instruction Formats • Example: Use a stack to evaluate the postfix Let’s see how to evaluate an infix expression expression 2 3 + 6 3 / - : using different instruction formats. 2 3 + 6 3 / - With a three-address ISA, (e.g., mainframes), Finding another operator, carry out the operation and the infix expression, push the result. Z = X × Y + W × U The answer is at the top of might look like this: the stack. MULT R1,X,Y 3 MULT R2,W,U ADD Z,R1,R2 23 24

  7. 5.2 Instruction Formats 5.2 Instruction Formats • In a two-address ISA, (e.g., Intel, Motorola), the • In a one-address ISA, like MARIE, the infix infix expression, expression, Z = X × Y + W × U Z = X × Y + W × U might look like this: looks like this: LOAD X LOAD R1,X MULT Y MULT R1,Y STORE TEMP LOAD R2,W Note: One-address LOAD W MULT R2,U ISAs usually MULT U ADD R1,R2 require one ADD TEMP STORE Z,R1 STORE Z operand to be a register. 25 26 5.2 Instruction Formats 5.2 Instruction Formats • In a stack ISA, the postfix expression, • We have seen how instruction length is affected by the number of operands supported by the ISA. Z = X Y × W U × + might look like this: • In any instruction set, not all instructions require the same number of operands. PUSH X PUSH Y • Operations that require no operands, such as MULT HALT , necessarily waste some space when fixed- PUSH W length instructions are used. Note: The result of PUSH U a binary operation • One way to recover some of this space is to use MULT is implicitly stored ADD expanding opcodes. on the top of the POP Z stack! 27 28

  8. 5.2 Instruction Formats 5.2 Instruction Formats • A system has 16 registers and 4K of memory. • If we allow the length of the opcode to vary, we could create a very rich instruction set: • We need 4 bits to access one of the registers. We also need 12 bits for a memory address. • If the system is to have 16-bit instructions, we have two choices for our instructions: Is there something missing from this instruction set? 29 30 5.2 Instruction Formats 5.2 Instruction Formats • Example: Given 8-bit instructions, is it possible to • With a total of 256 bit patterns required, we can allow the following to be encoded? exactly encode our instruction set in 8 bits! (256 = 2 8 ) – 3 instructions with two 3-bit operands. We need: – 2 instructions with one 4-bit operand. 3 * 2 3 * 2 3 = 192 bit patterns for the 3-bit operands – 4 instructions with one 3-bit operand. 2 * 2 4 = 32 bit patterns for the 4-bit operands We need: 4 * 2 3 = 32 bit patterns for the 3-bit operands 3 * 2 3 * 2 3 = 192 bit patterns for the 3-bit operands Total: 256 bit patterns. 2 * 2 4 = 32 bit patterns for the 4-bit operands 4 * 2 3 = 32 bit patterns for the 3-bit operands One such encoding is shown on the next slide. Total: 256 bit patterns. 31 32

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend