📄 os.cs
字号:
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2}",currentProcess.PCB.pid, instruction, register);
int instructionsToSkip = (int)CPU.registers[register];
// Do some sillyness to substract if we are a negative number
if (Math.Sign(instructionsToSkip) == -1)
CPU.ip-= (uint)Math.Abs(instructionsToSkip);
else
CPU.ip+= (uint)instructionsToSkip;
}
/// <summary>
/// If the sign flag is set, jump to the instruction that is offset r1 bytes from the current instruction
/// <pre>
/// 16 r1
/// </pre>
/// </summary>
public void Jlt()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Jlt == instruction);
//move to the param containing the 1st register
CPU.ip++;
uint register = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2}",currentProcess.PCB.pid, instruction, register);
if (CPU.sf == true)
{
CPU.ip+= CPU.registers[register];
}
}
/// <summary>
/// If the sign flag is clear, jump to the instruction that is offset r1 bytes from the current instruction
/// <pre>
/// 17 r1
/// </pre>
/// </summary>
public void Jgt()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Jgt == instruction);
//move to the param containing the 1st register
CPU.ip++;
uint register = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2}",currentProcess.PCB.pid, instruction, register);
if (CPU.sf == false)
{
CPU.ip+= CPU.registers[register];
}
}
/// <summary>
/// If the zero flag is set, jump to the instruction that is offset r1 bytes from the current instruction
/// <pre>
/// 18 r1
/// </pre>
/// </summary>
public void Je()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Je == instruction);
//move to the param containing the 1st register
CPU.ip++;
uint register = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2}",currentProcess.PCB.pid, instruction, register);
if (CPU.zf == true)
{
CPU.ip+= CPU.registers[register];
}
}
/// <summary>
/// Just that, does nothing
/// </summary>
public void Noop()
{
;
}
/// <summary>
/// This opcode causes an exit and the process's memory to be unloaded.
/// Another process or the idle process must now be scheduled
/// <pre>
/// 27
/// </pre>
/// </summary>
public void Exit()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Exit == instruction);
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1}",currentProcess.PCB.pid, instruction);
currentProcess.PCB.state = ProcessState.Terminated;
}
/// <summary>
/// Moves constant 1 into register 1
/// <pre>
/// 6 r1, $1
/// </pre>
/// </summary>
public void Movi()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Movi == instruction);
CPU.ip++;
uint register = FetchUIntAndMove();
uint param2 = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2} {3}",currentProcess.PCB.pid, instruction, register, param2);
//move VALUE of param into 1st register
CPU.registers[register] = param2;
}
/// <summary>
/// Moves contents of register2 into register 1
/// <pre>
/// 7 r1, r2
/// </pre>
/// </summary>
public void Movr()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Movr == instruction);
//move to the param containing the 1st register
CPU.ip++;
uint register1 = FetchUIntAndMove();
uint register2 = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2} r{3}",currentProcess.PCB.pid, instruction, register1, register2);
//move VALUE of 2nd register into 1st register
CPU.registers[register1] = CPU.registers[register2];
}
/// <summary>
/// Moves contents of memory pointed to register 2 into register 1
/// <pre>
/// 8 r1, r2
/// </pre>
/// </summary>
public void Movmr()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Movmr == instruction);
//move to the param containing the 1st register
CPU.ip++;
uint register1 = FetchUIntAndMove();
uint register2 = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2} r{3}",currentProcess.PCB.pid, instruction, register1, register2);
//move VALUE of memory pointed to by 2nd register into 1st register
CPU.registers[register1] = memoryMgr.getUIntFrom(currentProcess.PCB.pid,CPU.registers[register2]);
}
/// <summary>
/// Moves contents of register 2 into memory pointed to by register 1
/// <pre>
/// 9 r1, r2
/// </pre>
/// </summary>
public void Movrm()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Movrm == instruction);
//move to the param containing the 1st register
CPU.ip++;
uint register1 = FetchUIntAndMove();
uint register2 = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2} r{3}",currentProcess.PCB.pid, instruction, register1, register2);
//set memory pointed to by register 1 to contents of register2
memoryMgr.setUIntAt(currentProcess.PCB.pid,CPU.registers[register1],CPU.registers[register2]);
}
/// <summary>
/// Moves contents of memory pointed to by register 2 into memory pointed to by register 1
/// <pre>
/// 10 r1, r2
/// </pre>
/// </summary>
public void Movmm()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Movmm == instruction);
//move to the param containing the 1st register
CPU.ip++;
uint register1 = FetchUIntAndMove();
uint register2 = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2} r{3}",currentProcess.PCB.pid, instruction, register1, register2);
//set memory point to by register 1 to contents of memory pointed to by register 2
memoryMgr.setUIntAt(currentProcess.PCB.pid,CPU.registers[register1],memoryMgr.getUIntFrom(currentProcess.PCB.pid,CPU.registers[register2]));
}
/// <summary>
/// Prints out contents of register 1
/// <pre>
/// 11 r1
/// </pre>
/// </summary>
public void Printr()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Printr == instruction);
//move to the param containing the 1st param
CPU.ip++;
uint register = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2}",currentProcess.PCB.pid, instruction, register);
Console.WriteLine(CPU.registers[register]);
}
/// <summary>
/// Prints out contents of memory pointed to by register 1
/// <pre>
/// 12 r1
/// </pre>
/// </summary>
public void Printm()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Printm == instruction);
//move to the param containing the 1st param
CPU.ip++;
uint register = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2}",currentProcess.PCB.pid, instruction, register);
Console.WriteLine(memoryMgr[currentProcess.PCB.pid, CPU.registers[register]]);
}
/// <summary>
/// Read the next 32-bit value into register r1
/// <pre>
/// 32 r1
/// </pre>
/// </summary>
public void Input()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Input == instruction);
//move to the param containing the 1st param
CPU.ip++;
uint register = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2}",currentProcess.PCB.pid, instruction, register);
CPU.registers[register] = uint.Parse(Console.ReadLine());
}
/// <summary>
/// Sleep the # of clock cycles as indicated in r1.
/// Another process or the idle process
/// must be scheduled at this point.
/// If the time to sleep is 0, the process sleeps infinitely
/// <pre>
/// 25 r1
/// </pre>
/// </summary>
public void Sleep()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Sleep == instruction);
//move to the param containing the 1st param
CPU.ip++;
uint register = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2}",currentProcess.PCB.pid, instruction, register);
//Set the number of clockCycles to sleep
currentProcess.PCB.sleepCounter = CPU.registers[register];
currentProcess.PCB.state = ProcessState.WaitingAsleep;
}
/// <summary>
/// Set the priority of the current process to the value
/// in register r1
/// <pre>
/// 26 r1
/// </pre>
/// </summary>
public void SetPriority()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.SetPriority== instruction);
//move to the param containing the 1st param
CPU.ip++;
uint register = FetchUIntAndMove();
if (bDumpInstructions) Console.WriteLine(" Pid:{0} {1} r{2}",currentProcess.PCB.pid, instruction, register);
currentProcess.PCB.priority = (int)Math.Min(CPU.registers[register],(int)ProcessPriority.MaxPriority);
}
/// <summary>
/// Pushes contents of register 1 onto stack
/// <pre>
/// 4 r1
/// </pre>
/// </summary>
public void Pushr()
{
//get the instruction and make sure we should be here
InstructionType instruction = (InstructionType)memoryMgr[currentProcess.PCB.pid,CPU.ip];
Debug.Assert(InstructionType.Pushr == instruction);
//move to the param containing the 1st param
CPU.ip++;
uint register = FetchUIntAndMove();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -