-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReg.c
46 lines (40 loc) · 903 Bytes
/
Reg.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
#include "Reg.h"
#define NUMRECORDS 8
static Reg RegisterTable[NUMRECORDS] =
{
{8, "01000", "$t0"},
{9, "01001", "$t1"},
{10, "01010", "$t2"},
{11, "01011", "$t3"},
{16, "10000", "$s0"},
{17, "10001", "$s1"},
{18, "10010", "$s2"},
{19, "10011", "$s3"}
};
const Reg* FindReg(const char* const reg)
{
for (int i = 0; i < NUMRECORDS; i++)
{
if (strcmp(reg, RegisterTable[i].name) == 0)
{
return &RegisterTable[i];
}
}
return NULL;
}
char* decimalToBinary(int num)
{
char* result = calloc(16, sizeof(char*));
int place;
int bit;
for(place = 15; place >= 0; place--) {
bit = num >> place;
if(bit & 1) {
result[15 - place] = '1';
}
else {
result[15 - place] = '0';
}
}
return result;
}