Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to write a class which can perfom like a register?

 
magic zha
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Layne
 
magic zha
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic