0% found this document useful (0 votes)
14 views19 pages

Dsu Micro Project

The document outlines a micro project titled 'Instruction Set Implementation' for the academic year 2023-24, focusing on designing and implementing a basic instruction set architecture (ISA) and its emulator. It details the objectives, instructions for implementation, tools and technologies, and includes sample code in C for a CPU emulator that executes a simple instruction set. The project aims to provide hands-on experience in CPU operation, instruction execution, and system programming fundamentals.

Uploaded by

mansee491
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views19 pages

Dsu Micro Project

The document outlines a micro project titled 'Instruction Set Implementation' for the academic year 2023-24, focusing on designing and implementing a basic instruction set architecture (ISA) and its emulator. It details the objectives, instructions for implementation, tools and technologies, and includes sample code in C for a CPU emulator that executes a simple instruction set. The project aims to provide hands-on experience in CPU operation, instruction execution, and system programming fundamentals.

Uploaded by

mansee491
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

MAHARASHTRA STATE BOARD OF TECHNICAL

EDUCATION D.Y. PATIL POLYTECHNIC

MICRO PROJECT Academic year: 2023-24

Title Of Project : Instruction set implementation


Subject : Microprocessor Subject code : 22415

Course : Computer Engineering Course code : CO4I

1
MAHARASHTRA STATE BOARD OF TECHNICAL
EDUCATION

Certificate

This is to certify that Ms. Mansi Dilip Masne Roll No. 22 of


Fourth Semester Diploma in Computer Engineering of Institute,
D.Y. Patil Polytechnic (Instt.Code:0996) has completed the
MicroProject in course microprocessor for the academic year 2024-
2025 as prescribed in the curriculum.

Place : Ambi Enrollment No : 2209960046

Date : Exam Seat No : 236813

Subject Teacher Head of the Department Principal .

2
Instruction set Implementation

Introduction

The Simple Instruction Set Implementation Microproject provides a hands-


on opportunity to design and implement a basic instruction set architecture
(ISA) and its emulator. Participants define simple instructions, design
encoding formats, implement a CPU emulator, create sample programs, test
the emulator, and document the project. Through this project, participants
gain practical experience in CPU operation, instruction execution, and
system programming fundamentals.

3

Objectives

Implement a basic instruction set architecture (ISA) consisting of a few


instructions and build a simple emulator to execute programs written in this
ISA.

Instructions:
1. Define the instruction set: Choose a set of simple instructions such as
MOV (move), ADD (addition), SUB (subtraction), JMP (unconditional
jump), JZ (jump if zero), and HLT (halt).
2. Design the instruction encoding: Decide on the format for encoding each
instruction. You could use fixed-length encoding or variable-length
encoding depending on the complexity of your instructions.
3. Implement the emulator: Write code to simulate the execution of
instructions. Create data structures to represent the CPU state including
registers, memory, and the program counter. Implement functions to fetch,
decode, and execute instructions based on the opcode.

4
4. Write sample programs: Create a few sample programs using the defined
instruction set. These programs should demonstrate the functionality of
various instructions and control flow constructs.
5. Test the emulator: Run the sample programs through the emulator to
verify that the instructions are executed correctly and produce the expected
results.
6. Document the project: Write documentation detailing the instruction set,
encoding format, emulator implementation, and sample programs. Include
any assumptions made during the design process and explain how to use the
emulator.

Tools and Technologies:


- Programming language: Choose a language suitable for system
programming such as C, C++, or Rust.
- Text editor or IDE: Use a text editor or an integrated development
environment (IDE) for writing code.
- Version control: Utilize version control software like Git for managing
changes to the codebase.
- Documentation tools: Consider using Markdown or a similar lightweight
markup language for writing project documentation.

5
Sample Code (in C):
```c
#include <stdio.h>

#define MEM_SIZE 100

Typedef struct {
Int pc; // Program counter
Int regs[4]; // Registers
Int mem[MEM_SIZE]; // Memory
} CPU;

6
Void execute_instruction(CPU *cpu) {
// Fetch instruction from memory
Int instr = cpu->mem[cpu->pc];
// Decode opcode
Int opcode = instr >> 16;
// Execute instruction
Switch (opcode) {
Case 0: // MOV
{
Int dest_reg = (instr >> 12) & 0xF;
Int src_reg = (instr >> 8) & 0xF;
Cpu->regs[dest_reg] = cpu->regs[src_reg];
}
Break;
// Add support for other instructions (ADD, SUB, JMP, JZ, HLT)
similarly
Default:
Printf(“Invalid opcode\n”);
7
Break;
}
// Increment program counter
Cpu->pc++;
}

Int main() {
CPU cpu = {0}; // Initialize CPU
// Sample program: MOV R0, 42; MOV R1, 10; ADD R0, R1; HLT
Cpu.mem[0] = 0x00004200; // MOV R0, 42
Cpu.mem[1] = 0x00011001; // MOV R1, 10
Cpu.mem[2] = 0x10000001; // ADD R0, R1
Cpu.mem[3] = 0x20000000; // HLT
// Emulate program execution
While (cpu.mem[cpu.pc] != 0x20000000) { // HLT instruction
Execute_instruction(&cpu);
}
// Output result
8
Printf(“Result: %d\n”, cpu.regs[0]);
Return 0;
}
```

System.out.println(“Correct!”);
Score++;
} else {
System.out.println(“Incorrect!”);
}
System.out.println();
}

// Display final score


System.out.println(“Quiz completed! Your score: “ + score + “/” +
questions.length);

Scanner.close();
9
}
}
```

Detail description

1. **Header and Definitions**:


- The code begins with `#include <stdio.h>`, which includes the standard
input/output library for basic I/O operations.
- `#define MEM_SIZE 100` defines the size of the memory used by the
CPU emulator.

10
2. **CPU Structure**:
- A structure named `CPU` is defined to represent the state of the CPU. It
contains:
- `pc`: Program counter, indicating the address of the next instruction to
be executed.
- `regs`: An array representing CPU registers.
- `mem`: An array representing memory.

3. **execute_instruction Function**:
- The `execute_instruction` function simulates the execution of an
instruction by the CPU.
- It takes a pointer to a `CPU` struct as its argument.
- Inside the function:
- The instruction is fetched from memory using the program counter
(`cpu->mem[cpu->pc]`).
- The opcode of the instruction is decoded (`int opcode = instr >> 16`).
- A switch statement is used to handle different opcodes. For each
opcode:

11
- The appropriate action is taken, such as moving data between
registers, performing arithmetic operations, or modifying the program
counter.
- After executing the instruction, the program counter (`cpu->pc`) is
incremented.

4. **Main Function**:
- The `main` function initializes a CPU struct (`CPU cpu`) and simulates
the execution of a sample program.
- The sample program is represented by hardcoded instructions stored in
the `cpu.mem` array.
- The program consists of MOV, ADD, and HLT instructions.
- The `execute_instruction` function is called repeatedly in a loop until the
HLT instruction is encountered.
- Once the program halts, the result of the computation is printed.

5. **Sample Program**:
- The provided sample program demonstrates the usage of MOV, ADD,
and HLT instructions.
- It moves the value 42 into register R0, the value 10 into register R1, adds
the values of R0 and R1, and halts the execution.
12
6. **Execution**:
- To execute the code, it must be compiled using a C compiler (e.g.,
GCC).
- After compilation, the resulting executable can be run to execute the
sample program.

7. **Additional Notes**:
- The code is written in a straightforward manner to demonstrate the basic
concepts of CPU emulation and instruction execution.
- It serves as a foundation for understanding more complex CPU
architectures and emulator implementations.

Overall, this code provides a simple but illustrative example of how a CPU
emulator can be implemented to execute programs written in a custom
instruction set architecture.

13
CONCLUSION

In conclusion, the Simple Instruction Set Implementation Microproject


offers a practical exploration into the fundamentals of computer architecture
and system programming. By designing and implementing a basic CPU
emulator capable of executing programs written in a simplified instruction
set architecture (ISA), participants gain hands-on experience in CPU
operation, instruction execution, and control flow mechanisms.

14
Through the stages of defining the instruction set, designing encoding
formats, implementing the emulator, creating sample programs, testing
functionality, and documenting the project, participants develop a
comprehensive understanding of CPU emulation and ISA design principles.

This microproject serves as a stepping stone for further exploration into


more advanced topics such as pipelining, caching, parallel processing, and
optimization techniques in computer architecture. It empowers participants
to deepen their knowledge and skills in system programming, laying a solid
foundation for future endeavors in the field of computer science and
engineering.

//

Sr. No. Week Activity Performed Date Sign Of Guide

1 1st Discussion and


finalization of topic
2 2nd Preparation and
submission of Abstract

15
3 3rd Literature Review
4 4th Collection of Data
5 5th Collection of Data
6 6th Discussion and outline
of Content
7 7th Formulation of Content
8 8th Editing and proof
Reading of content
9 9th Compilation of Report
and Presentation
10 10th Seminar
11 11th Viva Voce
12 12th Final submission of
Micro Project

Sign of the student Sign of the faculty

16
Evaluation Sheet for the Micro Project

Academic Year : 2024-2025

Name of Faculty : Prof.Akshay Bhabhad

Course : Computer Engineering

Course code : CO4I Semester : Fourth


17
Title of the project : Instruction set implemntation
Major learning outcomes achieved by students by doing the project
Practical outcome:

1. Here Shift the original position of person to a new position.


2. Grounded on its changed precedence or remove a person.

3. Comments/suggestions about team work


/leadership/interpersonal communication (if any)

....................................................................................................................

WEEKLY PROGRESS OF MICRO PROJECT

Roll No. Student Name Mark out of Mark out of Total out of
6 for 4 for 10
performance preformance
Group Oral /
presentation
activity

18
22 Mansee Masne

(Name & Signature Of Faculty)

19

You might also like