@@ -32,6 +32,7 @@ void print_cycles();
32
32
void print_reg ();
33
33
void print_pc ();
34
34
35
+ // code
35
36
char inst [33 ];
36
37
char inst32 [33 ];
37
38
char opcode [8 ];
@@ -43,13 +44,15 @@ char rs2[6];
43
44
char I_imm [13 ];
44
45
char S_imm [13 ];
45
46
47
+ // control
46
48
int memto_reg ;
47
49
int reg_write ;
48
50
int mem_read ;
49
51
int mem_write ;
50
52
int branch ;
51
53
int PCSrs ;
52
54
55
+ // index, value, pc
53
56
int rd_index ;
54
57
int rs1_index ;
55
58
int rs2_index ;
@@ -66,14 +69,14 @@ int read_from_mem;
66
69
char type [10 ];
67
70
68
71
// 2진수 문자열을 10진수 숫자로 변환하는 함수
69
- int read_bin (char code [])
72
+ int read_bin (char code [])
70
73
{
71
74
int result = 0 ;
72
75
int code_len = strlen (code );
73
- char convert [13 ] = {0 , };
76
+ char convert [13 ] = { 0 , };
74
77
75
78
// 상수가 음수일 때 2의 보수로 구하기!
76
- if (code_len == 12 && code [0 ]== '1' )
79
+ if (code_len == 12 && code [0 ] == '1' )
77
80
{
78
81
// 0->1 , 1->0
79
82
for (int i = 0 ; code [i ]; i ++ )
@@ -93,7 +96,7 @@ int read_bin(char code[])
93
96
}
94
97
95
98
// 2진수 -> 10진수
96
- else
99
+ else
97
100
{
98
101
for (int i = 0 ; code [i ]; i ++ )
99
102
{
@@ -224,7 +227,7 @@ void decode() {
224
227
//printf("rs2_index, rs2_value = x%d, %d\n", rs2_index, rs2_value);
225
228
226
229
// branch_offset
227
- int beq_imm [13 ] = {'\0' ,};
230
+ int beq_imm [13 ] = { '\0' , };
228
231
strncat (beq_imm , S_imm , 1 );
229
232
strncat (beq_imm , S_imm + 11 , 1 );
230
233
strncat (beq_imm , S_imm + 1 , 6 );
@@ -248,7 +251,7 @@ void decode() {
248
251
//printf("rd_index = x%d\n", rd_index);
249
252
250
253
// branch_offset
251
- int jal_imm [13 ] = {'\0' ,};
254
+ int jal_imm [13 ] = { '\0' , };
252
255
strncat (jal_imm , I_imm , 1 );
253
256
strncat (jal_imm , I_imm + 12 , 8 );
254
257
strncat (jal_imm , I_imm + 11 , 1 );
@@ -315,7 +318,7 @@ void decode() {
315
318
}
316
319
317
320
// ld
318
- if (strcmp (opcode , "0000011" ) == 0 && strcmp (funct3 , "011" ) == 0 )
321
+ if (strcmp (opcode , "0000011" ) == 0 && strcmp (funct3 , "011" ) == 0 )
319
322
{
320
323
// rd
321
324
rd_index = read_bin (rd );
@@ -338,7 +341,7 @@ void decode() {
338
341
branch = 0 ;
339
342
PCSrs = 0 ;
340
343
}
341
-
344
+
342
345
//printf("%s\n", type);
343
346
}
344
347
0 commit comments