-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramCounter.java
More file actions
72 lines (64 loc) · 1.41 KB
/
ProgramCounter.java
File metadata and controls
72 lines (64 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Class that represent counter of program
*/
public class ProgramCounter{
/**
* Display the current counter value
*/
private Bit4 count;
/**
* current counter value for MAR
*/
private Bit4 ctMar;
/**
* ProgramCounter Class Constructor
*/
public ProgramCounter(){
this.count=new Bit4(0);
this.ctMar=new Bit4(0);
}
/**
* Method to add the counter
*/
public void countUp(){
this.count.setValue(this.count.toBinary(this.count.toDecimal()+1,4));
}
/**
* Method for setting a new counter value based on user input
* @param new counter value
*/
public void setCount(Bit4 count){
this.count=count;
}
/**
* Method for getting the current counter
* @return current counter value in a form of 4Bit number
*/
public Bit4 getCount(){
return this.count;
}
/**
* Method for getting the current counter for MAR
* @return current counter for MAR value in a form of 4Bit number
*/
public Bit4 getCtMar() {
return ctMar;
}
/**
* Method for setting a new counter for MAR value based on user input
* @param new counter for MAR value
*/
public void setCtMar(Bit4 ctMar) {
this.ctMar = ctMar;
}
/**
* Method return a data value if data is not null.
* @return data value
*/
public String toString(){
if(count!=null){
return this.count.getValue();
}
return "XXXXXXXX";
}
}