I am using java to write a mini operate system. Now i want to write a class which can work like a register. I use the register to store data and it is 16-bit long. How can i write it ? Can i make it derive from the BitSet?
One good way to think out a new class is by the operations it can do. What does your register have to support? Load, read? Some bit logic like OR, XOR? Do you know enough about it to start writing the Javadoc for it first? Or will you explore the requirements and "grow" it as you go?
This sounds like a cool assignment. Let us know what you're thinking so far.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
If I were writing a program like this, I would ultimately store the register's value in a primitive. I don't think I'd inherit from BitSet or anything else nearly as complicated. In fact, I really don't think I'd even create a class for an individual register. However, I might create a class for a register file that contains a group of registers. I'd probably use an array of int (or long) to hold the registers in this RegisterFile class.
This is just a suggestion. Of course, there are plenty of other ways to do it. This is what comes to mind if I were to try and implement something along these lines.
Anyway, I hope this gives you something to think about. This sure sounds like an insteresting project. Let us know how things go as you work on it.
Thank you very much! I know now it will not be a good method to write it as a class.It will be much more simple if I write it as a primitive.But i have a problem,the data type will be int,long,float or double,I don't know how to distinguish them when i get them out from the register.Do you have some good suggestion? I only begin my project.In the first step,i need to implements the functions following:1.registers including data register,address register,IR,PC and PSW.2Some simple instructions such as "ADD R1 R2".3Write a interpreter which can translate the instructions into binary format. In the future there are also much i have to do,for example implements the Process!