linux操作系统学习-微指令程序执行模拟
2019-03-31 16:04
78 查看
代码(java实现)
package helloword; interface IInstruction{ void exe(int input); } abstract class Instruction implements IInstruction{ static protected int register1; static protected int register2; static protected int ends; static protected boolean state=true; public static Memory[] mMemory = new Memory[10]; static void add(Memory me) { mMemory[ends] = me; ends++; } static void readMemory() { for(int i=0;i<Instruction.ends;i++) { mMemory[i].exe(); } } } class Input extends Instruction{ static public Input mInput= new Input(); static Input get() { return mInput; } public void exe(int no) { if(state) { register1 = no; state = false; }else { register2 = no; 4000 state = true; } } } class Add extends Instruction{ static public Add mInput= new Add(); static Add get() { return mInput; } public void exe(int no) { register1 = register1+register2; } } class Output extends Instruction{ static public Output mInput= new Output(); static Output get() { return mInput; } public void exe(int no) { mMemory[no].value = register1; } } class Finish extends Instruction{ static public Finish mInput= new Finish(); static Finish get() { return mInput; } public void exe(int no) { //ends = 0; } } class IOut extends Instruction{ static public IOut mInput= new IOut(); static IOut get() { return mInput; } public void exe(int no) { ends = 0; System.out.println(register1); } } class CPU{ static void exe(){ Instruction.readMemory(); } } class Memory{ public Memory(IInstruction ins, int v) { mInstruction = ins; value = v; } public IInstruction mInstruction; public int value; void exe() { mInstruction.exe(value); } } public class Test { public static void main(String[] args) { System.out.println("hello worldff !"); Instruction.add(new Memory(Input.get(),5 )); Instruction.add(new Memory(Input.get(),6 )); Instruction.add(new Memory(Add.get(),0 )); Instruction.add(new Memory(Finish.get(),0 )); Instruction.add(new Memory(IOut.get(),0 )); CPU.exe(); } }
相关文章推荐
- Linux操作系统学习_用户进程之由新进程创建到可执行程序的加载
- Linux操作系统下后台执行程序
- 【Linux操作系统分析】进程的创建与可执行程序的加载
- Linux学习笔记 - 程序的执行(一)
- linux0.11学习笔记-技术铺垫-简单AB任务切换程序(2)-可加载执行其他程序的bootloader
- Linux操作系统中/sbin/init程序的执行过程
- Linux操作系统分析(2)- 进程的创建与可执行程序的加载
- Linux操作系统分析之进程的创建与可执行程序的加载
- Linux第七周学习总结——可执行程序的装载
- Linux操作系统中/sbin/init程序的执行过程
- 【Linux操作系统分析】进程的创建与可执行程序的加载
- Linux操作系统下使用MONO执行C#程序的方法
- Linux操作系统分析-lab2-进程的创建与可执行程序的加载
- Linux操作系统分析-lab2-进程的创建与可执行程序的加载
- Linux学习笔记------如何执行一个 可执行程序???
- 进程信号Linux操作系统分析(2)- 进程的创建与可执行程序的加载
- Linux操作系统下 MONO执行C#程序的方法
- 今日试用wine,让windows可执行程序在linux操作系统下运行!
- 操作系统学习_Linux0.12_引导启动程序_为啥要不停移动
- “Linux内核分析”实验报告(七)Linux 操作系统如何装载链接并执行程序