CSC 3210 Computer Organization and Programming Chapter 8 MACHINE INSTRUCTIONS D.M. Rasanjalee Himali.

Slides:



Advertisements
Similar presentations
Chapter 2: Data Manipulation
Advertisements

Goal: Write Programs in Assembly
ELEN 468 Advanced Logic Design
Chapter 2 Instructions: Language of the Computer Part III.
CS2100 Computer Organisation MIPS Part III: Instruction Formats (AY2014/2015) Semester 2.
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
The Processor 2 Andreas Klappenecker CPSC321 Computer Architecture.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
Instruction Representation I (1) Fall 2005 Lecture 05: INSTRUCTION REPRESENTATION.
Processor I CPSC 321 Andreas Klappenecker. Midterm 1 Thursday, October 7, during the regular class time Covers all material up to that point History MIPS.
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
Some material taken from Assembly Language for x86 Processors by Kip Irvine © Pearson Education, 2010 Slides revised 2/2/2014 by Patrick Kelley.
CSC 3210 Computer Organization and Programming Chapter 2 SPARC Architecture Dr. Anu Bourgeois 1.
Topic 10: Instruction Representation CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and.
Lecture Objectives: 1)Define the terms least significant bit and most significant bit. 2)Explain how unsigned integer numbers are represented in memory.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Module : Algorithmic state machines. Machine language Machine language is built up from discrete statements or instructions. On the processing architecture,
Computer Organization and Architecture Instructions: Language of the Machine Hennessy Patterson 2/E chapter 3. Notes are available with photocopier 24.
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
CSC 3210 Computer Organization and Programming Chapter 2 SPARC ARCHITECTURE D.M. Rasanjalee Himali.
Computer Organization Rabie A. Ramadan Lecture 3.
CENG 311 Instruction Representation
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 8 – Machine Instructions These are lecture notes to accompany the book.
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 9 Binary Representation and Logical Operations.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
CS Computer Organization Numbers and Instructions Dr. Stephen P. Carl.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
Chapter 8 – Machine Instructions
MIPS Assembly.
Electrical and Computer Engineering University of Cyprus
Morgan Kaufmann Publishers
ELEN 468 Advanced Logic Design
COMP2121: Microprocessors and Interfacing
Morgan Kaufmann Publishers The Processor
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Morgan Kaufmann Publishers The Processor
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
Instruction Format MIPS Instruction Set.
The University of Adelaide, School of Computer Science
Design of the Control Unit for Single-Cycle Instruction Execution
THE sic mACHINE CSCI/CMPE 3334 David Egle.
CSCI206 - Computer Organization & Programming
Design of the Control Unit for One-cycle Instruction Execution
CSC 3210 Computer Organization and Programming
Computer Architecture & Operations I
MIPS Instruction Encoding
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Topic 5: Processor Architecture Implementation Methodology
Rocky K. C. Chang 6 November 2017
MIPS Instruction Encoding
Chapter 2 Instructions: Language of the Computer
Topic 5: Processor Architecture
Unit 12 CPU Design & Programming
COMS 361 Computer Organization
Computer Instructions
Computer Architecture
COMP541 Datapaths I Montek Singh Mar 18, 2010.
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
Instruction Format MIPS Instruction Set.
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
October 29 Review for 2nd Exam Ask Questions! 4/26/2019
CS501 Advanced Computer Architecture
COMS 361 Computer Organization
Presentation transcript:

CSC 3210 Computer Organization and Programming Chapter 8 MACHINE INSTRUCTIONS D.M. Rasanjalee Himali

Outline Instruction Codes Instruction Decode Format Three Instructions Format One Instruction: The call Instruction Format Two Instruction

Instruction Codes Instructions on SPARC architecture occupy one word, 32 bits All information needed to execute the instruction is encoded in the instruction word These 32 bits are divided into fields -- contiguous subsets of the bits. We need to define fields to specify the instruction's opcode, and fields to specify the instruction's arguments (operands).

Instruction Codes The format of the instruction should be uniform and as simple as possible. A typical scheme is given below: 8 bits –  To specify the instruction (we get 256 instructions) 5 bits (each)–  For address of the three registers (32 different registers) 1 bit –  To specify if second argument is a source register or constant 8 bits –  Remaining 8 bits either combined with 5 bits used for second source register for 13 bit signed immediate constant or to provide additional 8 bits to specify floating point instructions.

Instruction Decode The division of the instruction into fields in done in three different ways, called formats. The format is specified in the first two bits of the instruction (op filed): The 8 bits of the instruction opcode are divided into 2 parts:  op - 2 bits (which specifies instruction formats)  op3 - 6 bits Instruction Classes Specified by op: The Format three instructions are then decoded using the least significant bit of op with the remaining six bits of the op3 field. OPINSTRUCTION CLASSFORMAT 00Branch InstructionFormat 2 01Call InstructionFormat 1 10Format three instructionFormat 3 11Format three instructionFormat 3

Format 3 Instructions Majority of instructions executed are Format 3 instructions There are two possibilities for Format 3 instructions: op rs1, rs2, rd or op rs1, imm, rd  where "imm" is an immediate value, that is, value is coded right into the instruction.

Format 3 Instructions Case1: op rs1, rs2, rd :  op: 10 or 11, indicating that this is a format 3 instruction  rd: numeric ID of destination register  op3: encoding of opcode  rs1: numeric ID of first source register rs2: numeric ID of second source register rs20rs1op3rdOp empty 0

Format 3 Instructions Case2: op rs1, imm, rd:  op: 10 or 11, indicating that this is a format 3 instruction  rd: numeric ID of destination register  op3: encoding of opcode  rs1: numeric ID of first source register Signed immediate 13 bit constant1rs1op3rdOp

Format 3 Instructions The way the processor tells these two cases apart is by the 1 or 0 right after the rs1 field. Note that the signed constant is only allotted 13 bits. This is a consequence of our decision to limit all instructions to exactly 32 bits in size. The immediate value is encoded in two's complement, so the range of values we can encode is to Thus, if we try to use an immediate value in a format 3 instruction that is out of this range, the assembler will complain -- it just can't fit such a value in there.

Format 3 Instructions There are two tables:  with op = 10 and the  with op = 11. The instructions with op = 10 are three-address register instructions, such as add and sub. The instructions with op = 11 are the load/store instructions, all of which refer to memory.

Format Three Instructions Unimplemented instructions are listed as unimp. Three-Address Register `(Non-load-store) (op =10) Load-store (op=11)

%rs1 = %l0 = %r16 Format 3 Instructions Ex:  sub %l0, 5, %o0  The instruction may be written as the hexadecimal constant 0x : Signed constant = 5i= 1op3 %rd = %o0 = %r8 op The numeric IDs of registers are as follows: %g0 - %g to 7 %o0 - %o to 15 %l0 - %l to 23 %i0 - %i to

Ex:  st %l0,[%fp+ -24] %rs1 = %fp =%i6 %r Signed constant = 5i= 1op3 %rd = %o0 = %r16 op Format 3 Instructions : 1’s comp ’s comp

Format 3 Instructions The program: These are all Format Three instructions and may be decoded as follows:

Format One Instruction: The call Instruction There is only one Format One instruction, the call instruction. The target of such a transfer must be an instruction and thus word aligned. A word-aligned address has the least significant two bits, both zero, Address is calculated by right shifting displacement 2 positions A Format One call instruction contains an op field of followed by 30 bits of address. The address to which control is transferred = (displacement<<2) +pc 0130 bit displacement

Example Displacement = ox4059 = (0x207dc – 0x10678)>>2 0x10660 : save %sp, -96, %sp 0x10664 : clr %l0 0x10668 : b 0x x1066c : nop 0x10670 : mov %l0, %o0 0x10674 : mov 0xa, %o1 0x10678 : call 0x207dc 0x1067c : nop (gdb) x/xw *&for+8 0x10678 : 0x (gdb) x/xwt *&for+8 0x10678 :

Format Two Instructions Two instructions:  branch instructions and the sethi instruction.  The op field for Format Two instructions is 00. branch: sethi: 0 0 a cond op2 22 bit displacement rd bit displacement

Branch Instructions the target of the branch is stored relative to the program counter right-shifted two bits. Only 22 bits are available for the displacement, so that the target of branches may be only ±2 21 instructions from the program counter. 0 0 a cond op2 22 bit displacement

Branch Instructions The branch is (or is not) taken based on the “cond” (condition) field. op2 = 010 means integer condition code branch, the type of branch we have been using If the branch is to be annulled, the a bit is set.

Branch Instructions Four-bit field cond specifies the condition under which branching is to occur:

Branch Instructions

Example b 0x10694 Destination is three instructions away from this instruction Branch Target

Sethi Instruction Loading 32-Bit Constants: So far we have worked only with small constants in our programs. We were limited by the 13-bit signed- immediate field of the instruction. If we need a larger constant, we will need to use the sethi instruction, which will load the high 22 bits of a register while clearing the low 10 bits.

Loading 32-Bit Constants The annul bit field and the cond fields are combined to form a five-bit rd field, the register into which the constant is to be loaded. Op2 = 100 in sethi instruction The execution of this instruction results in the 22-bit immediate constant being loaded into the left-hand 22 bits of the register rd with the low 10 bits of the register cleared to zero. 0 0 rd bit immediate

Loading 32-Bit Constants To load a 32-bit constant, two instructions are needed:  a sethi to load the high 22 bits,  followed by an or instruction to “ or ” in the low 10 bits of the constant. For example, to load register %o0 with32 bit constant 0x30cf0034, we would write: The machine provides 2 arithmatic operators to do this shifting of 10 bits to right and get low 10 bits : %hi and %lo  %hi(x) is x>>10  %lo(x) is x & 0x3ff All 1s in last 10 bits

Loading 32-Bit Constants Thus to load a constant 0x30cf0034 into %o0 we could write: sethi %hi(0x30cf0034), %o0 or %o0, %lo(0x30cf0034), %o0 We could write above 2 instructions in one as below (preferred):

Appendix : Register Addresses