Merge pull request 'fix some bug about double comma' (#5) from fix_bug_BIGlittle into main

Reviewed-on: https://external.feng-arch.cn:35127/fengqi/asm_parser/pulls/5
This commit is contained in:
fengqi 2024-10-31 03:46:47 +00:00
commit 119ebdd89c
5 changed files with 733 additions and 144 deletions

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -Wall -Wextra -I.
CFLAGS = -Wall -Wextra -I. -g
SRC_ASSEMBLER = assembler.c
SRC_ASM_PARSER = asm_parser.c
OBJ_ASM_PARSER = asm_parser.o
@ -15,6 +15,7 @@ asm_parser.o: $(SRC_ASM_PARSER)
clean:
rm -f $(OBJ_ASM_PARSER)
clobber: clean
rm -f $(TARGET)
rm -f *~

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,7 @@
#define ASM_PARSER_H
#include <ctype.h>
#include <stdint.h>
#define ROWS 100
#define COLS 255
@ -27,10 +28,12 @@ int parse_div(char *instr, char *instr_bin_str);
int parse_and(char *instr, char *instr_bin_str);
int parse_or(char *instr, char *instr_bin_str);
int parse_xor(char *instr, char *instr_bin_str);
/* add additional helper functions to support other instructions */
int parse_imm5(char *imm_str, int *imm_value);
/* add additional helper functions to support other instructions */
unsigned short int str_to_bin(char *instr_bin_str);
int write_obj_file(char *filename, unsigned short int program_bin[ROWS], int instr_count);
void int_to_bin_str(int num, int bits, char *bin_str);
void to_uppercase(char *str);
void trim(char *str);
void write_uint16_big_endian(FILE *file, uint16_t value);
#endif

View File

@ -37,13 +37,18 @@ int main(int argc, char **argv) {
unsigned short int bin = str_to_bin(instr_bin_str);
if (bin == 6) { // Error code from str_to_bin
printf("Error on line %d: %s\n", i + 1, line);
return i + 1;
return 6;
}
// if program_bin is full, return error
if (instr_count >= ROWS) {
printf("Error: Program too large\n");
return 0;
}
program_bin[instr_count] = bin;
instr_count++;
} else {
printf("Error on line %d: %s\n", i + 1, line);
return i + 1;
return ret;
}
// ret == 0 means successful parsing
}

View File

@ -1,7 +1 @@
ADD R1, R0, R1
MUL R2, R1, R1
SUB R3, R2, R1
DIV R1, R3, R2
AND R1, R2, R3
OR R1, R3, R2
XOR R1, R3, R2
ADD R1, R0 #5