Skip to content

Commit 347ce03

Browse files
authored
찐막 최종코드 !!
컴퓨터구조 p2 끝
1 parent 543139d commit 347ce03

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

riscv_sim.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void print_cycles();
3232
void print_reg();
3333
void print_pc();
3434

35+
// code
3536
char inst[33];
3637
char inst32[33];
3738
char opcode[8];
@@ -43,13 +44,15 @@ char rs2[6];
4344
char I_imm[13];
4445
char S_imm[13];
4546

47+
// control
4648
int memto_reg;
4749
int reg_write;
4850
int mem_read;
4951
int mem_write;
5052
int branch;
5153
int PCSrs;
5254

55+
// index, value, pc
5356
int rd_index;
5457
int rs1_index;
5558
int rs2_index;
@@ -66,14 +69,14 @@ int read_from_mem;
6669
char type[10];
6770

6871
// 2진수 문자열을 10진수 숫자로 변환하는 함수
69-
int read_bin(char code[])
72+
int read_bin(char code[])
7073
{
7174
int result = 0;
7275
int code_len = strlen(code);
73-
char convert[13] = {0,};
76+
char convert[13] = { 0, };
7477

7578
// 상수가 음수일 때 2의 보수로 구하기!
76-
if (code_len == 12 && code[0]=='1')
79+
if (code_len == 12 && code[0] == '1')
7780
{
7881
// 0->1 , 1->0
7982
for (int i = 0; code[i]; i++)
@@ -93,7 +96,7 @@ int read_bin(char code[])
9396
}
9497

9598
// 2진수 -> 10진수
96-
else
99+
else
97100
{
98101
for (int i = 0; code[i]; i++)
99102
{
@@ -224,7 +227,7 @@ void decode() {
224227
//printf("rs2_index, rs2_value = x%d, %d\n", rs2_index, rs2_value);
225228

226229
// branch_offset
227-
int beq_imm[13] = {'\0',};
230+
int beq_imm[13] = { '\0', };
228231
strncat(beq_imm, S_imm, 1);
229232
strncat(beq_imm, S_imm + 11, 1);
230233
strncat(beq_imm, S_imm + 1, 6);
@@ -248,7 +251,7 @@ void decode() {
248251
//printf("rd_index = x%d\n", rd_index);
249252

250253
// branch_offset
251-
int jal_imm[13] = {'\0',};
254+
int jal_imm[13] = { '\0', };
252255
strncat(jal_imm, I_imm, 1);
253256
strncat(jal_imm, I_imm + 12, 8);
254257
strncat(jal_imm, I_imm + 11, 1);
@@ -315,7 +318,7 @@ void decode() {
315318
}
316319

317320
// ld
318-
if (strcmp(opcode, "0000011") == 0 && strcmp(funct3, "011") == 0)
321+
if (strcmp(opcode, "0000011") == 0 && strcmp(funct3, "011") == 0)
319322
{
320323
// rd
321324
rd_index = read_bin(rd);
@@ -338,7 +341,7 @@ void decode() {
338341
branch = 0;
339342
PCSrs = 0;
340343
}
341-
344+
342345
//printf("%s\n", type);
343346
}
344347

0 commit comments

Comments
 (0)