fix some bug about double comma
This commit is contained in:
parent
4728cf9651
commit
ebc3c88a36
3
Makefile
3
Makefile
@ -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 *~
|
||||
|
||||
840
asm_parser.c
840
asm_parser.c
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user