This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to write a class which can perfom like a register? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to write a class which can perfom like a register?" Watch "How to write a class which can perfom like a register?" New topic

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

magic zha

Joined: Mar 25, 2005
Posts: 24
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

Joined: Jan 29, 2003
Posts: 8791
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
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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.


Java API Documentation
The Java Tutorial
magic zha

Joined: Mar 25, 2005
Posts: 24
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!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: How to write a class which can perfom like a register?
It's not a secret anymore!