-
Notifications
You must be signed in to change notification settings - Fork 0
/
registers.c
76 lines (62 loc) · 1.66 KB
/
registers.c
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
73
74
75
#include <stdio.h>
#include "bool.h"
#include "registers.h"
#include "tools.h"
static unsigned int registers[REGSIZE]; //array of registers
static unsigned int CC; //Condition code
/**
* getRegister
* This function returns the contents of a register
* @param: regNum: The register to return
* @return: registers[regNum]: Contents of a register
*/
unsigned int getRegister(int regNum){
if(regNum >= EAX && regNum <= EDI){
return registers[regNum];
}
else {
return 0;
}
}
/**
* setRegister
* This function sets the contents of a register to a value
* @param: regNum: The register number to set
* regValue: The value to store in the register
*/
void setRegister(int regNum, unsigned int regValue){
if(regNum >= EAX && regNum <= EDI ){
registers[regNum] = regValue;
}
}
/**
* clearRegisters
* This function initializes all registers to 0
*/
void clearRegisters(){
int loop = 0;
for(loop = 0; loop<REGSIZE; loop++){
registers[loop] = 0;
}
}
/**
* setCC
* This function sets a specific bit in the condition code
* @param: bitNumber: the bit of the CC to set
* value: The value to set the bit to(1 or 0)
*/
void setCC(unsigned int bitNumber, unsigned int value){
if(value == 0 || value == 1) {
CC = assignOneBit(bitNumber, value, CC);
}
//printf("SF(registers) = %x\n", getCC(SF));
}
/**
* getCC
* This function returns a bit of the condition code
* @param: bitNumber: The bit to get
* @return: getBits(..,..,..): The value of the bit
*/
unsigned int getCC(unsigned int bitNumber){
return getBits(bitNumber,bitNumber,CC);
}