Machine description

profilereevin
os_problem_set.zip

os_problem_set/~$output.docx

os_problem_set/~$sign Doc.docx

os_problem_set/~WRL2076.tmp

DESIGN DOCUMENT

Name: Anvitha Katragadda

NSU Id: N01751902

Introduction:

This document explains the detail design and implementation of SIMMAC, a virtual machine which will accept programs in the target machine level language. SIMMAC is implemented using C language.

Project Description:

SIMMAC is a machine that will accept only a specific machine level language. It contains a 512 bit words of memory, few registers, ALU for performing arithmetic operations and each instruction contains an operand and an opcode. SIMMAC machine language contains instructions with opcode and operands. Opcode such as ADD, SUB, LDA, STR, BRH, CBR and LDI are supported and operand will hold either the value or address of the opcode. SIMMAC should execute parallel programs in a round robin technique where the time quantum is specified as an input.

Implementation and Design:

Memory allocation: Each instruction is stored in a char array named memory[][]. For each node

PCB struct: A Process Control Block data structure is maintained by the operating systems for every process to keep a track of all the information of a process. To support parallel execution of SIMMAC programs, round robin method is used which will execute the instruction for a specific time limit. If the complete program is not executed in this specific time, to again start the execution of the program from where it has stopped, the register values are stored in this PCB node.

PCB_Linkedlist struct: This is a structure of linked list where each node represents a PCB structure. A single PCB_Linkedlist node is created for each program therefore this will keep a track of number of programs.

Approach:

· When the user enters the input which can be a single file or multiple files with time quantum, for each file a PCB_queue node is created and each instruction is loaded into a memory in an array format(mem[][]).

· This loop continues till all the files are loaded into the memory.

· Once all the programs are loaded into the memory, the instructions are fetched from the main memory and stored in instruction register(IR).

· These instructions are decoded which means that the opcode and operands are determined.

· After that the instructions are executed.

· As the programs are executed in round robin method each one will be executed only for a specific time frame. If the complete program is not executed in that specific time, the current register values are stored in PCB, so that program will resume from the last instruction

· Once the complete program is executed, the memory is cleared for all the instruction in that program and the program is removed from the memory.

Flow Diagram:

Start

End

Remove the program from memory.

If PSIAR = 0

Clear the memory for instruction.

If PSIAR != 0

Save PCB with current register values.

If counter = 0

True

false

True

false

Inputs are given from command line which are time_quantum and text_files.

Fetch, decode and execute the instructions

If number of files to load =0

Create PCB and allocate memory (main memory) for instructions.

If inputs are valid

os_problem_set/compile and run main_prgm.txt

/* for compiling the program */ gcc simmac.c /* setting then files in read only format */ attrib +r c:\c_pgm\prgm1.txt attrib +r c:\c_pgm\prgm2.txt attrib +r c:\c_pgm\prgm3.txt attrib +r c:\c_pgm\prgm1.1.txt attrib +r c:\c_pgm\prgm1.2.txt attrib +r c:\c_pgm\prgm1.3.txt /* executing the program */ a.exe 10 c:\c_pgm\prgm1.txt a.exe 10 c:\c_pgm\prgm2.txt c:\c_pgm\prgm3.txt

os_problem_set/Design Doc.docx

DESIGN DOCUMENT

Introduction:

This document explains the detail design and implementation of SIMMAC, a virtual machine which will accept programs in the target machine level language. SIMMAC is implemented using C language.

Project Description:

SIMMAC is a machine that will accept only a specific machine level language. It contains a 512 bit words of memory, few registers, ALU for performing arithmetic operations and each instruction contains an operand and an opcode. SIMMAC machine language contains instructions with opcode and operands. Opcode such as ADD, SUB, LDA, STR, BRH, CBR and LDI are supported and operand will hold either the value or address of the opcode. SIMMAC should execute parallel programs in a round robin technique where the time quantum is specified as an input.

Implementation and Design:

Memory allocation: Each instruction is stored in a char array named mem[][]. For each node a specific amount of memory is created which is equal to length of node.

PCB struct: A Process Control Block data structure is maintained by the operating systems for every process to keep a track of all the information of a process. To support parallel execution of SIMMAC programs, round robin method is used which will execute the instruction for a specific time limit. If the complete program is not executed in this specific time, to again start the execution of the program from where it has stopped, the register values are stored in this PCB node.

PCB_Linkedlist struct: This is a structure of linked list where each node represents a PCB structure. A single PCB_Linkedlist node is created for each program therefore this will keep a track of number of programs.

Approach:

· When the user enters the input which can be a single file or multiple files with time quantum, for each file a PCB_queue node is created and each instruction is loaded into a memory in an array format(mem[][]).

· This loop continues till all the files are loaded into the memory.

· Once all the programs are loaded into the memory, the instructions are fetched from the main memory and stored in instruction register(IR).

· These instructions are decoded which means that the opcode and operands are determined.

· After that the instructions are executed.

· As the programs are executed in round robin method each one will be executed only for a specific time frame. If the complete program is not executed in that specific time, the current register values are stored in PCB, so that program will resume from the last instruction.

· Once the complete program is executed, the memory is cleared for all the instruction in that program and the program is removed from the memory to create space for other programs.

( Start ) Flow Diagram:

( End ) ( Remove the program from memory. ) ( If PSIAR = 0 ) ( Clear the memory for instruction. ) ( If PSIAR ! = 0 ) ( Save PCB with current register values. ) ( If time out ) ( True ) ( false ) ( True ) ( false ) ( Inputs are given f rom command line which are time quantum and text files. ) ( Fetch, decode and execute the instructions ) ( If number of files to load =0 ) ( Create PCB and allocate memory (main memory) for instructions. ) ( If inputs are valid )

os_problem_set/output.docx

C:\c_pgm>gcc simmac.c

C:\c_pgm>a.exe 10 c:\c_pgm\prgm1.txt

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

Execution of program with pid = 2 completed

values stored in registers for this process

ACC = 1050

PSIAR = 62

SAR = 21

SDR = 1050

TMPR = 21

CSIAR = 0

IR = 875560981

the output of the program is: 1050

C:\c_pgm>a.exe 10 c:\c_pgm\prgm2.txt

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

Execution of program with pid = 2 completed

values stored in registers for this process

ACC = 0

PSIAR = 10

SAR = 202

SDR = 0

TMPR = 202

CSIAR = 0

IR = 875561162

the output of the program is: 0

C:\c_pgm>a.exe 10 c:\c_pgm\prgm3.txt

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

Execution of program with pid = 2 completed

values stored in registers for this process

ACC = 0

PSIAR = 16

SAR = 14

SDR = 16

TMPR = 2

CSIAR = 0

IR = 909115408

the output of the program is: 0

C:\c_pgm>a.exe 10 c:\c_pgm\prgm3.txt c:\c_pgm\prgm2.txt

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 3

Execution of program with pid = 3 completed

values stored in registers for this process

ACC = 0

PSIAR = 25

SAR = 202

SDR = 0

TMPR = 202

CSIAR = 0

IR = 875561162

the output of the program is: 0

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

Execution of program with pid = 2 completed

values stored in registers for this process

ACC = 0

PSIAR = 16

SAR = 14

SDR = 16

TMPR = 2

CSIAR = 0

IR = 909115408

the output of the program is: 0

C:\c_pgm>a.exe 10 c:\c_pgm\prgm1.1.txt

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

Execution of program with pid = 2 completed

values stored in registers for this process

ACC = 420

PSIAR = 62

SAR = 490

SDR = 420

TMPR = 490

CSIAR = 0

IR = 875561450

the output of the program is: 420

C:\c_pgm>a.exe 10 c:\c_pgm\prgm1.2.txt

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

Execution of program with pid = 2 completed

values stored in registers for this process

ACC = 2100

PSIAR = 62

SAR = 469

SDR = 2100

TMPR = 469

CSIAR = 0

IR = 875561429

the output of the program is: 2100

C:\c_pgm>a.exe 10 c:\c_pgm\prgm1.3.txt

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

execution Time out and the register values are saved in the PCB

Executing program with PID = 2

Execution of program with pid = 2 completed

values stored in registers for this process

ACC = 1050

PSIAR = 62

SAR = 21

SDR = 1050

TMPR = 21

CSIAR = 0

IR = 875560981

the output of the program is: 1050

os_problem_set/prgm1.1.txt

LDI 2 STR 510 LDI 4 STR 509 LDI 6 STR 508 LDI 8 STR 507 LDI 10 STR 506 LDI 12 STR 505 LDI 14 STR 504 LDI 16 STR 503 LDI 18 STR 502 LDI 20 STR 501 LDI 22 STR 500 LDI 40 STR 499 LDI 24 STR 498 LDI 26 STR 497 LDI 28 STR 496 LDI 30 STR 495 LDI 32 STR 494 LDI 34 STR 493 LDI 36 STR 492 LDI 38 STR 491 LDA 510 ADD 509 ADD 508 ADD 507 ADD 506 ADD 505 ADD 504 ADD 503 ADD 502 ADD 501 ADD 500 ADD 499 ADD 498 ADD 497 ADD 496 ADD 495 ADD 494 ADD 493 ADD 492 ADD 491 STR 490

os_problem_set/prgm1.2.txt

LDI 10 STR 489 LDI 20 STR 487 LDI 30 STR 486 LDI 40 STR 485 LDI 50 STR 484 LDI 60 STR 483 LDI 70 STR 482 LDI 80 STR 481 LDI 90 STR 480 LDI 100 STR 479 LDI 110 STR 478 LDI 120 STR 477 LDI 130 STR 476 LDI 140 STR 475 LDI 150 STR 474 LDI 160 STR 473 LDI 170 STR 472 LDI 180 STR 471 LDI 190 STR 470 LDI 200 STR 488 LDA 489 ADD 488 ADD 487 ADD 486 ADD 485 ADD 484 ADD 483 ADD 482 ADD 481 ADD 480 ADD 479 ADD 478 ADD 477 ADD 476 ADD 475 ADD 474 ADD 473 ADD 472 ADD 471 ADD 470 STR 469

os_problem_set/prgm1.3.txt

LDI 5 STR 1 LDI 10 STR 2 LDI 15 STR 3 LDI 20 STR 4 LDI 25 STR 5 LDI 30 STR 6 LDI 35 STR 7 LDI 40 STR 8 LDI 45 STR 9 LDI 50 STR 10 LDI 55 STR 11 LDI 60 STR 12 LDI 65 STR 13 LDI 70 STR 14 LDI 75 STR 15 LDI 80 STR 16 LDI 85 STR 17 LDI 90 STR 18 LDI 95 STR 19 LDI 100 STR 20 LDA 1 ADD 2 ADD 3 ADD 4 ADD 5 ADD 6 ADD 7 ADD 8 ADD 9 ADD 10 ADD 11 ADD 12 ADD 13 ADD 14 ADD 15 ADD 16 ADD 17 ADD 18 ADD 19 ADD 20 STR 21

os_problem_set/prgm1.txt

LDI 5 STR 1 LDI 10 STR 2 LDI 15 STR 3 LDI 20 STR 4 LDI 25 STR 5 LDI 30 STR 6 LDI 35 STR 7 LDI 40 STR 8 LDI 45 STR 9 LDI 50 STR 10 LDI 55 STR 11 LDI 60 STR 12 LDI 65 STR 13 LDI 70 STR 14 LDI 75 STR 15 LDI 80 STR 16 LDI 85 STR 17 LDI 90 STR 18 LDI 95 STR 19 LDI 100 STR 20 LDA 1 ADD 2 ADD 3 ADD 4 ADD 5 ADD 6 ADD 7 ADD 8 ADD 9 ADD 10 ADD 11 ADD 12 ADD 13 ADD 14 ADD 15 ADD 16 ADD 17 ADD 18 ADD 19 ADD 20 STR 21

os_problem_set/prgm2.txt

LDI 101 STR 201 LDI 1 STR 202 LDA 201 SUB 202 CBR 9 BRH 6 STR 202

os_problem_set/prgm3.txt

LDI 100 STR 301 LDA 301 STR 302 LDI 2 STR 303 LDI 200 STR 304 LDA 302 ADD 303 STR 302 LDA 304 SUB 303 CBR 16 BRH 8

os_problem_set/simmac.c

#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #define start_add 0 #define end_add 2048 unsigned char mem[512][4];/* it will store instructions */ /* PCB strcuture for storing register values */ typedef struct PCB { int PCBID; int ins_start_addr; int ins_end_addr; int ins_cur_addr; int32_t ACC; int16_t PSIAR; int16_t SAR; int32_t SDR; int32_t TMPR; int16_t CSIAR; int32_t IR; int16_t MIR; }PCB; /* single linked list to store all the files/programs */ typedef struct PCB_Linkedlist { PCB Node; struct PCB_Linkedlist *Next; }PCB_Linkedlist; int main(int argc,char *argv[]) { if(argc < 3) { printf("Usage simmac <time_quantum> <program_files>\n"); return 1; } else { int time_quantum; int no_of_programs; int last_program_loaded; PCB_Linkedlist *root=NULL,*tmpPtr = NULL,*tmpPtr1 = NULL; FILE *fp; int i=2; char str[50]; char *token1; char *token2; char opcode[2]; unsigned char operand[2]; int tmp; int mem_add = 1; int time_out; int32_t ACC; int16_t PSIAR; int16_t SAR; int32_t SDR; int32_t TMPR; int16_t CSIAR; int32_t IR; int16_t MIR; int cur_instr; time_quantum = atoi(argv[1]); no_of_programs = argc-2; time_out = time_quantum; /* loading the instrcution into memory[][] of each file and looping till all the files are read */ while(no_of_programs > 0) { /* Open SIMMAC machine level program file */ fp = fopen(argv[i],"r"); if(fp == NULL) { printf("couldn't open file %s\n",argv[i]); continue; } else { memset(str,0,50); fgets(str,50,fp); if(root == NULL) { root = (PCB_Linkedlist *)malloc(sizeof(PCB_Linkedlist)); root->Next = NULL; tmpPtr = root; } else { tmpPtr = root; while(tmpPtr->Next != NULL) tmpPtr = tmpPtr->Next; tmpPtr->Next = (PCB_Linkedlist *)malloc(sizeof(PCB_Linkedlist)); tmpPtr = tmpPtr->Next; tmpPtr->Next = NULL; } tmpPtr->Node.ins_start_addr = mem_add; tmpPtr->Node.ins_cur_addr = mem_add; tmpPtr->Node.PSIAR = mem_add; tmpPtr->Node.PCBID = i; while(str != NULL) { str[strlen(str)-1] = '\0'; token1 = strtok(str," "); token2 = strtok(NULL," "); /* assigning value to opcodes, token1 = opcode, token2 = operand */ if(strcmp(str,"ADD") == 0) strcpy(opcode,"10"); else if(strcmp(str,"SUB") == 0) strcpy(opcode,"20"); else if(strcmp(str,"LDA") == 0) strcpy(opcode,"30"); else if(strcmp(str,"STR") == 0) strcpy(opcode,"40"); else if(strcmp(str,"BRH") == 0) strcpy(opcode,"50"); else if(strcmp(str,"CBR") == 0) strcpy(opcode,"60"); else if(strcmp(str,"LDI") == 0) strcpy(opcode,"70"); else if(strcmp(str,"HALT") == 0) strcpy(opcode,"80"); else { printf("unrecognized opcode %s\n",token1); break; } tmp = atoi(token2); operand[0] = (unsigned char)(tmp >> 8); operand[1] = tmp & 0xFF; /* loading the operand and opcode into memory which meand loading an instruction */ mem[mem_add][0] = opcode[0]; mem[mem_add][1] = opcode[1]; mem[mem_add][2] = operand[0]; mem[mem_add][3] = operand[1]; mem_add += 1; /* Read Next line */ memset(str,0,50); if(fgets(str,50,fp) == NULL) break; } tmpPtr->Node.ins_end_addr = mem_add-1; } i++; fclose(fp); no_of_programs -= 1; } /* Executing the programs in round robin */ tmpPtr = root; while(tmpPtr != NULL && tmpPtr->Node.PSIAR !=0) { time_out = time_quantum; printf("Executing program with PID = %d\n",tmpPtr->Node.PCBID); ACC = tmpPtr->Node.ACC; PSIAR = tmpPtr->Node.PSIAR; SAR = tmpPtr->Node.SAR; SDR = tmpPtr->Node.SDR; TMPR = tmpPtr->Node.TMPR; CSIAR = tmpPtr->Node.CSIAR; IR = tmpPtr->Node.IR; MIR = tmpPtr->Node.MIR; while(time_out > 0) { /* Fetch the instructions, store them IR register and decode the opcode*/ SAR = PSIAR; SDR = 0; SDR |= (mem[PSIAR][0] << 24); SDR |= (mem[PSIAR][1] << 16); SDR |= (mem[PSIAR][2] << 8); SDR |= (mem[PSIAR][3]); IR = SDR; operand[0] = mem[PSIAR][2]; operand[1] = mem[PSIAR][3]; SDR = 0; SDR |= (operand[0] << 8); SDR |= (operand[1]); opcode[0] = mem[PSIAR][0]; opcode[1] = mem[PSIAR][1]; CSIAR = atoi(opcode); /* Executing the instructions */ switch(CSIAR) { case 10: TMPR = ACC; ACC = PSIAR+1; PSIAR = ACC; ACC = TMPR; TMPR = SDR; SAR = TMPR; SDR = 0; SDR |= (mem[SAR][0] << 24); SDR |= (mem[SAR][1] << 16); SDR |= (mem[SAR][2] << 8); SDR |= (mem[SAR][3]); TMPR = SDR; ACC = ACC+TMPR; CSIAR = 0; break; case 20: TMPR = ACC; ACC = PSIAR+1; PSIAR = ACC; ACC = TMPR; TMPR = SDR; SAR = TMPR; SDR = 0; SDR |= (mem[SAR][0] << 24); SDR |= (mem[SAR][1] << 16); SDR |= (mem[SAR][2] << 8); SDR |= (mem[SAR][3]); TMPR = SDR; ACC = ACC-TMPR; CSIAR = 0; break; case 30: TMPR = ACC; ACC = PSIAR+1; PSIAR = ACC; ACC = TMPR; TMPR = SDR; SAR = TMPR; SDR = 0; SDR |= (mem[SAR][0] << 24); SDR |= (mem[SAR][1] << 16); SDR |= (mem[SAR][2] << 8); SDR |= (mem[SAR][3]); ACC = SDR; CSIAR = 0; break; case 40: TMPR = ACC; ACC = PSIAR+1; PSIAR = ACC; ACC = TMPR; TMPR = SDR; SAR = TMPR; SDR = ACC; mem[SAR][0] = (unsigned char)((SDR >> 24) & 0xFF); mem[SAR][1] = (unsigned char)((SDR >> 16) & 0xFF); mem[SAR][2] = (unsigned char)((SDR >> 8) & 0xFF); mem[SAR][3] = (unsigned char)(SDR & 0xFF); CSIAR = 0; break; case 50: PSIAR = (SDR+tmpPtr->Node.ins_start_addr-1); CSIAR = 0; break; case 60: if(ACC == 0) PSIAR = (SDR+tmpPtr->Node.ins_start_addr-1); else { TMPR = ACC; ACC = PSIAR+1; PSIAR = ACC; ACC = TMPR; } CSIAR = 0; break; case 70: TMPR = ACC; ACC = PSIAR+1; PSIAR = ACC; ACC = TMPR; ACC = SDR; CSIAR = 0; break; case 80: //Halt case printf("Current registers content:\n"); printf("ACC = %d\n",ACC); printf("PSIAR = %d\n",PSIAR); printf("SAR = %d\n",SAR); printf("SDR = %d\n",SDR); printf("TMPR = %d\n",TMPR); printf("CSIAR = %d\n",CSIAR); printf("IR = %d\n",IR); printf("Ending the program\n"); exit(0); break; default: printf("unrecognized command\n"); break; } time_out--; /*End this program if it reached the final instruction*/ if((PSIAR-1) >= tmpPtr->Node.ins_end_addr) { time_out = 0; tmpPtr->Node.PSIAR = 0; break; } } /* Remove pointer for the node for which process has finished execution */ if(tmpPtr->Node.PSIAR == 0) { for(i=tmpPtr->Node.ins_start_addr; i<tmpPtr->Node.ins_end_addr; i++) { mem[i][0] = 0; mem[i][1] = 0; mem[i][2] = 0; mem[i][3] = 0; } tmpPtr1 = root; /* Remove this Process from the queue */ while(tmpPtr1 != NULL) { if(tmpPtr1->Next == tmpPtr) { tmpPtr1->Next = tmpPtr->Next; break; } else if(tmpPtr1 == tmpPtr && tmpPtr1->Next != NULL) { root = tmpPtr->Next; break; } tmpPtr1 = tmpPtr1->Next; } printf("Execution of program with pid = %d completed \n",tmpPtr->Node.PCBID); printf(" values stored in registers for this process\n"); printf("ACC = %d\n",ACC); printf("PSIAR = %d\n",PSIAR); printf("SAR = %d\n",SAR); printf("SDR = %d\n",SDR); printf("TMPR = %d\n",TMPR); printf("CSIAR = %d\n",CSIAR); printf("IR = %d\n",IR); printf("the output of the program is: %d\n", ACC); SDR = 0; SDR |= (mem[PSIAR][0] << 24); SDR |= (mem[PSIAR][1] << 16); SDR |= (mem[PSIAR][2] << 8); SDR |= (mem[PSIAR][3]); } else { printf(" execution Time out and the register values are saved in the PCB\n"); /* Save the PCB block */ tmpPtr->Node.ins_cur_addr = PSIAR; tmpPtr->Node.ACC = ACC; tmpPtr->Node.PSIAR = PSIAR; tmpPtr->Node.SAR = SAR; tmpPtr->Node.SDR = SDR; tmpPtr->Node.TMPR = TMPR; tmpPtr->Node.CSIAR = CSIAR; tmpPtr->Node.IR = IR; } tmpPtr = tmpPtr->Next; if(tmpPtr == NULL) tmpPtr = root; } } return 0; }