Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
Addressing Modes
Next article icon

Computer Organization | Problem Solving on Instruction Format

Last Updated : 19 Apr, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Prerequisite - Basic Computer Instructions, Instruction Formats 

Problem statement:

Consider a computer architecture where instructions are 16 bits long. The first 6 bits of the instruction are reserved for the opcode, and the remaining 10 bits are used for the operands. There are three addressing modes: immediate, direct, and register. For immediate addressing, the operand is included in the instruction itself. For direct addressing, the operand is a memory address. For register addressing, the operand is a register number.

Write the instruction format for each of the addressing modes.

Solution:

The instruction format for each addressing mode is as follows:

  1. Immediate addressing:
    | Opcode (6 bits) | Operand (10 bits) |
  2. Direct addressing:
    | Opcode (6 bits) | Memory address (10 bits) |
  3. Register addressing:
    | Opcode (6 bits) | Register number (5 bits) | Not used (1 bit) |

In immediate addressing, the operand is included in the instruction itself, so the 10 bits are used to represent the operand value.

In direct addressing, the 10 bits are used to represent the memory address where the operand value is stored.

In register addressing, the 5 bits are used to represent the register number where the operand value is stored. The remaining 1 bit is not used.

This instruction format can be used to implement a wide range of instructions and operations in a computer system.


An instruction format defines the different component of an instruction. The main components of an instruction are opcode (which instruction to be executed) and operands (data on which instruction to be executed). Here are the different terms related to instruction format: 



 

  • Instruction set size - It tells the total number of instructions defined in the processor. 
     
  • Opcode size - It is the number of bits occupied by the opcode which is calculated by taking log of instruction set size. 
     
  • Operand size - It is the number of bits occupied by the operand. 
     
  • Instruction size - It is calculated as sum of bits occupied by opcode and operands. 
     



In this article, we will discuss different types of problems based on instruction format which are asked in GATE. For details about different types of instruction formats, you can refer: Instruction Formats 


Type 1: Given instruction set size and operands size and their count, find the size of the instruction. 
In this type of questions, you will be given the size of instruction set, number of operands and their size, you have to find out the size of the instruction. 

Que-1. Consider a processor with 64 registers and an instruction set of size twelve. Each instruction has five distinct fields, namely, opcode, two source register identifiers, one destination register identifier, and a twelve-bit immediate value. Each instruction must be stored in memory in a byte-aligned fashion. If a program has 100 instructions, the amount of memory (in bytes) consumed by the program text is ____________. (GATE 2016) 
(A) 100 
(B) 200 
(C) 400 
(D) 500 

Solution: It can be approached as: 
 

  • The instruction consists of opcode and operands. Given the instruction set of size 12, 4 bits are required for opcode (2^4 = 16). 
     
  • As there are total 64 registers, 6 bits are required for identifying a register. 
     
  • As the instruction contains 3 registers (2 source + 1 designation), 3 * 6 = 18 bit are required for register identifiers. 
     
  • 12 bits are required for immediate value as given. 
     
  • Total bits for an instruction = 4 + 18 + 12 = 34 bits 
     
  • The instructions are required to be stored in a byte-aligned fashion. The nearest byte boundary after 34 bits is at 40 bits (5 bytes).
     
  • Hence, for 100 instructions, the memory required is 5 * 100 = 500 bytes, and the correct option is (D).
     



Type 2: Given instruction size, opcode size and size of some operands, find the size and maximum value of remaining operands. 
In this type of questions, you will be given the size of instruction, size of opcode, number of operands and size of some operands, you have to find out the size or maximum value of remaining operands. 

Que-2. A processor has 40 distinct instructions and 24 general purpose registers. A 32-bit instruction word has an opcode, two registers operands and an immediate operand. The number of bits available for the immediate operand field is_______. (GATE CS 2016) 

Solution: It can be approached as: 
 

  • As the processor has 40 instructions, number of bits for opcode = 6 (2^6 = 64) 
     
  • As the processor has 24 register, number of bits for one register = 5 (2^5 = 32) 
     
  • Total bits occupied by 2 registers and opcode = 6 + 5 + 5 =16. 
     
  • As instruction size given is 32 bits, remaining bit left for operand = 32-16 = 16 bits. 
     



Que-3. A machine has a 32-bit architecture, with 1-word long instructions. It has 64 registers, each of which is 32 bits long. It needs to support 45 instructions, which have an immediate operand in addition to two register operands. Assuming that the immediate operand is an unsigned integer, the maximum value of the immediate operand is ___________. (GATE CS 2014) 

Solution: It can be approached as: 
 

  • As machine has 32-bit architecture, therefore, 1 word = 32 bits = instruction size 
     
  • As the processor has 64 register, number of bits for one register = 6 (2^6 = 64) 
     
  • As the processor has 45 instructions, number of bits for opcode = 6 (2^6 = 64) 
     
  • Total bits occupied by 2 registers and opcode = 6 + 6 + 6 =18. 
     
  • As instruction size given is 32 bits, remaining bit left for immediate operand = 32-18 = 14 bits. 
     
  • Maximum unsigned value using 14 bits = 2^14 – 1 = 16383 which is the answer. 
     




Type 3: Instruction format with different categories of instruction 
In this type of questions, you will be given different categories of instructions. You have to find maximum possible instructions of a given type. 

Que-4. A processor has 16 integer registers (R0, R1, … , R15) and 64 floating point registers (F0, F1, … , F63). It uses a 2 byte instruction format. There are four categories of instructions: Type-1, Type-2, Type-3, and Type 4. Type-1 category consists of four instructions, each with 3 integer register operands (3Rs). Type-2 category consists of eight instructions, each with 2 floating point register operands (2Fs). Type-3 category consists of fourteen instructions, each with one integer register operand and one floating point register operand (1R+1F). Type-4 category consists of N instructions, each with a floating point register operand (1F). 

The maximum value of N is ________. (GATE-CS-2018) 

Solution: It can be approached as: 
 

  • As machine has 2 byte = 16 bits instruction format, therefore, possible encodings = 2^16. 
     
  • As the processor has 16 integer register, number of bits for one integer register = 4 (2^4 = 16) 
     
  • As the processor has 64 floating point register, number of bits for one floating point register = 6 (2^6 = 64). 
     
  • For type-1 category having 4 instructions each having 3 integer register operands (4*3 = 12 bits) will consume 4 * 2^12 = 2^14 encodings. 
     
  • For type-2 category having 8 instructions each having 2 floating point register operands (2*6 = 12 bits) will consume 8 * 2^12 = 2^15 encodings. 
     
  • For type-3 category having 14 instructions each having 1 integer register and 1 floating point register operands (4 + 6 = 10 bits) will consume 14 * 2^10 = 14336 encodings. 
     
  • For type-4 category instructions, number of encodings left = 2^16 – 2^14 – 2^15 – 14336 = 2048. 
     
  • For type-4 category having N instructions each having 1 floating point register operand (6 bits) will consume N* 2^6 = 2048 (calculated from previous step). Therefore, N = 32. 
     


 


Next Article
Addressing Modes

M

Mithlesh Upadhyay
Improve
Article Tags :
  • Computer Organization and Architecture

Similar Reads

    Machine instructions and addressing modes

    • Computer Organization is like understanding the "blueprint" of how a computer works internally. One of the most important models in this field is the Von Neumann architecture, which is the foundation of most modern computers. Named after John von Neumann, this architecture introduced the concept of
      6 min read

    • Computer organization refers to the way in which the components of a computer system are organized and interconnected to perform specific tasks. One of the most fundamental aspects of computer organization is the set of basic computer instructions that the system can execute. Basic Computer Instruct
      6 min read

    • Instruction formats refer to the way instructions are encoded and represented in machine language. There are several types of instruction formats, including zero, one, two, and three-address instructions. Each type of instruction format has its own advantages and disadvantages in terms of code size,
      11 min read

    • Based on the number of address fields, CPU organization is of three types: Single Accumulator organization, register based organization and stack based CPU organization. Stack-Based CPU OrganizationThe computers which use Stack-based CPU Organization are based on a data structure called a stack. The
      4 min read

    • When we are using multiple general-purpose registers, instead of a single accumulator register, in the CPU Organization then this type of organization is known as General register-based CPU Organization. In this type of organization, the computer uses two or three address fields in their instruction
      3 min read

    • The computers, present in the early days of computer history, had accumulator-based CPUs. In this type of CPU organization, the accumulator register is used implicitly for processing all instructions of a program and storing the results into the accumulator. The instruction format that is used by th
      2 min read

    • Prerequisite - Basic Computer Instructions, Instruction Formats Problem statement: Consider a computer architecture where instructions are 16 bits long. The first 6 bits of the instruction are reserved for the opcode, and the remaining 10 bits are used for the operands. There are three addressing mo
      7 min read

    • Addressing modes are the techniques used by the CPU to identify where the data needed for an operation is stored. They provide rules for interpreting or modifying the address field in an instruction before accessing the operand. Addressing modes for 8086 instructions are divided into two categories:
      7 min read

    • Machine Instructions are commands or programs written in the machine code of a machine (computer) that it can recognize and execute. A machine instruction consists of several bytes in memory that tell the processor to perform one machine operation. The processor looks at machine instructions in main
      5 min read

    • In assembly language as well as in low level programming CALL and JUMP are the two major control transfer instructions. Both instructions enable a program to go to different other parts of the code but both are different. CALL is mostly used to direct calls to subroutine or a function and regresses
      5 min read

    • Simplified Instructional Computer (SIC) is a hypothetical computer that has hardware features that are often found in real machines. There are two versions of this machine: SIC standard ModelSIC/XE(extra equipment or expensive)Object programs for SIC can be properly executed on SIC/XE which is known
      4 min read

    • Let's discuss about parallel computing and hardware architecture of parallel computing in this post. Note that there are two types of computing but we only learn parallel computing here. As we are going to learn parallel computing for that we should know following terms. Era of computing - The two f
      3 min read

    • Parallel computing is a computing where the jobs are broken into discrete parts that can be executed concurrently. Each part is further broken down to a series of instructions. Instructions from each part execute simultaneously on different CPUs. Parallel systems deal with the simultaneous use of mu
      4 min read

    • The generation of computers refers to the progression of computer technology over time, marked by key advancements in hardware and software. These advancements are divided into five generations, each defined by improvements in processing power, size, efficiency, and overall capabilities. Starting wi
      6 min read

    • It is named after computer scientist Gene Amdahl( a computer architect from IBM and Amdahl corporation) and was presented at the AFIPS Spring Joint Computer Conference in 1967. It is also known as Amdahl's argument. It is a formula that gives the theoretical speedup in latency of the execution of a
      6 min read

    ALU, data‐path and control unit

    • A Central Processing Unit is the most important component of a computer system. A control unit is a part of the CPU. A control unit controls the operations of all parts of the computer but it does not carry out any data processing operations. What is a Control Unit?The Control Unit is the part of th
      10 min read

    • Introduction : In computer architecture, the control unit is responsible for directing the flow of data and instructions within the CPU. There are two main approaches to implementing a control unit: hardwired and micro-programmed. A hardwired control unit is a control unit that uses a fixed set of l
      5 min read

    • Prerequisite - Hardwired v/s Micro-programmed Control Unit To execute an instruction, there are two types of control units Hardwired Control unit and Micro-programmed control unit. Hardwired control units are generally faster than microprogrammed designs. In hardwired control, we saw how all the con
      2 min read

    • The Control Unit, in computer architecture, plays a fundamental role in the management of instruction execution by regulating the use of the processor, memory, and I/O devices. There exist mainly two methods for designing micro-programmed control units. These comprise the Horizontal and Vertical Mic
      7 min read

    • In Synchronous Data Transfer, the sending and receiving units are enabled with the same clock signal. It is possible between two units when each of them knows the behaviour of the other. The master performs a sequence of instructions for data transfer in a predefined order. All these actions are syn
      4 min read

    Instruction pipelining

    • Pipelining is a technique used in modern processors to improve performance by executing multiple instructions simultaneously. It breaks down the execution of instructions into several stages, where each stage completes a part of the instruction. These stages can overlap, allowing the processor to wo
      9 min read

    • Please see Set 1 for Execution, Stages and Performance (Throughput) and Set 3 for Types of Pipeline and Stalling. Dependencies in a pipelined processor There are mainly three types of dependencies possible in a pipelined processor. These are : 1) Structural Dependency 2) Control Dependency 3) Data D
      6 min read

    • Please see Set 1 for Execution, Stages and Performance (Throughput) and Set 2 for Dependencies and Data Hazard. Types of pipeline Uniform delay pipeline In this type of pipeline, all the stages will take same time to complete an operation. In uniform delay pipeline, Cycle Time (Tp) = Stage Delay If
      3 min read

    • Introduction : Prerequisite - Execution, Stages and Throughput Registers Involved In Each Instruction Cycle: Memory address registers(MAR) : It is connected to the address lines of the system bus. It specifies the address in memory for a read or write operation.Memory Buffer Register(MBR) : It is co
      11 min read

    • In computer organization, performance refers to the speed and efficiency at which a computer system can execute tasks and process data. A high-performing computer system is one that can perform tasks quickly and efficiently while minimizing the amount of time and resources required to complete these
      6 min read

    • In computer organization, a micro-operation refers to the smallest tasks performed by the CPU's control unit. These micro-operations helps to execute complex instructions. They involve simple tasks like moving data between registers, performing arithmetic calculations, or executing logic operations.
      3 min read

    • RISC is the way to make hardware simpler whereas CISC is the single instruction that handles multiple work. In this article, we are going to discuss RISC and CISC in detail as well as the Difference between RISC and CISC, Let's proceed with RISC first. Reduced Instruction Set Architecture (RISC) The
      5 min read

    Cache Memory

    • In the Computer System Design, Memory Hierarchy is an enhancement to organize the memory such that it can minimize the access time. The Memory Hierarchy was developed based on a program behavior known as locality of references (same data or nearby data is likely to be accessed again and again). The
      6 min read

    • Cache memory is a small, high-speed storage area in a computer. The cache is a smaller and faster memory that stores copies of the data from frequently used main memory locations. There are various independent caches in a CPU, which store instructions and data. The most important use of cache memory
      11 min read

    • Cache is close to CPU and faster than main memory. But at the same time is smaller than main memory. The cache organization is about mapping data in memory to a location in cache. A Simple Solution: One way to go about this mapping is to consider last few bits of long memory address to find small ca
      3 min read

    • Caches are the faster memories that are built to deal with the Processor-Memory gap in data read operation, i.e. the time difference in a data read operation in a CPU register and that in the main memory. Data read operation in registers is generally 100 times faster than in the main memory and it k
      7 min read

    • The CPU Cache and Translation Lookaside Buffer (TLB) are two important microprocessor hardware components that improve system performance, although they have distinct functions. Even though some people may refer to TLB as a kind of cache, it's important to recognize the different functions they serv
      4 min read

    • A memory unit stores binary information in groups of bits called words. Data input lines provide the information to be stored into the memory, Data output lines carry the information out from the memory. The control lines Read and write specifies the direction of transfer of data. Basically, in the
      3 min read

    • Prerequisite - Virtual Memory Abstraction is one of the most important aspects of computing. It is a widely implemented Practice in the Computational field. Memory Interleaving is less or More an Abstraction technique. Though it's a bit different from Abstraction. It is a Technique that divides memo
      3 min read

    • Memory is required to save data and instructions. Memory is divided into cells, and they are stored in the storage space present in the computer. Every cell has its unique location/address. Memory is very essential for a computer as this is the way it becomes somewhat more similar to a human brain.
      11 min read

    • Memory is a fundamental component of computing systems, essential for performing various tasks efficiently. It plays a crucial role in how computers operate, influencing speed, performance, and data management. In the realm of computer memory, two primary types stand out: Random Access Memory (RAM)
      8 min read

    • In the computer world, memory plays an important component in determining the performance and efficiency of a system. In between various types of memory, Random Access Memory (RAM) stands out as a necessary component that enables computers to process and store data temporarily. In this article, we w
      8 min read

    • Memory is an important part of the Computer which is responsible for storing data and information on a temporary or permanent basis. Memory can be classified into two broad categories: Primary Memory Secondary Memory What is Primary Memory? Primary Memory is a type of Computer Memory that the Prepro
      7 min read

    I/O interface (Interrupt and DMA mode)

    • The method that is used to transfer information between internal storage and external I/O devices is known as I/O interface. The CPU is interfaced using special communication links by the peripherals connected to any computer system. These communication links are used to resolve the differences betw
      6 min read

    • The DMA mode of data transfer reduces the CPU's overhead when handling I/O operations. It also allows parallel processing between CPU and I/O operations. This parallelism is necessary to avoid the wastage of valuable CPU time when handling I/O devices whose speeds are much slower as compared to CPU.
      5 min read

    • The kernel provides many services related to I/O. Several services such as scheduling, caching, spooling, device reservation, and error handling - are provided by the kernel's I/O subsystem built on the hardware and device-driver infrastructure. The I/O subsystem is also responsible for protecting i
      7 min read

    • CPU needs to communicate with the various memory and input-output devices (I/O). Data between the processor and these devices flow with the help of the system bus. There are three ways in which system bus can be allotted to them: Separate set of address, control and data bus to I/O and memory.Have c
      5 min read

    • Introduction : In a computer system, multiple devices, such as the CPU, memory, and I/O controllers, are connected to a common communication pathway, known as a bus. In order to transfer data between these devices, they need to have access to the bus. Bus arbitration is the process of resolving conf
      7 min read

    • In I/O Interface (Interrupt and DMA Mode), we have discussed the concept behind the Interrupt-initiated I/O. To summarize, when I/O devices are ready for I/O transfer, they generate an interrupt request signal to the computer. The CPU receives this signal, suspends the current instructions it is exe
      5 min read

    • Introduction : Asynchronous input/output (I/O) synchronization is a technique used in computer organization to manage the transfer of data between the central processing unit (CPU) and external devices. In asynchronous I/O synchronization, data transfer occurs at an unpredictable rate, with no fixed
      7 min read

    • A port is basically a physical docking point which is basically used to connect the external devices to the computer, or we can say that A port act as an interface between the computer and the external devices, e.g., we can connect hard drives, printers to the computer with the help of ports. Featur
      3 min read

    • A cluster is a set of loosely or tightly connected computers working together as a unified computing resource that can create the illusion of being one machine. Computer clusters have each node set to perform the same task, controlled and produced by the software. Clustered Operating Systems work si
      7 min read

    • Introduction - The advent of a technological marvel called the “computer” has revolutionized life in the twenty-first century. From IoT to self-driving cars to smart cities, computers have percolated through the fabric of society. Unsurprisingly the methods with which we interact with computers have
      4 min read

geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences