create makefile
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
TARGET_EXEC ?= a.out
|
||||||
|
|
||||||
|
BUILD_DIR ?= ./build
|
||||||
|
SRC_DIRS ?= ./src
|
||||||
|
|
||||||
|
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
|
||||||
|
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
|
||||||
|
DEPS := $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
|
||||||
|
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
|
||||||
|
|
||||||
|
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP
|
||||||
|
|
||||||
|
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
|
||||||
|
$(CC) $(OBJS) -o $@ $(LDFLAGS)
|
||||||
|
|
||||||
|
# assembly
|
||||||
|
$(BUILD_DIR)/%.s.o: %.s
|
||||||
|
$(MKDIR_P) $(dir $@)
|
||||||
|
$(AS) $(ASFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
# c source
|
||||||
|
$(BUILD_DIR)/%.c.o: %.c
|
||||||
|
$(MKDIR_P) $(dir $@)
|
||||||
|
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
# c++ source
|
||||||
|
$(BUILD_DIR)/%.cpp.o: %.cpp
|
||||||
|
$(MKDIR_P) $(dir $@)
|
||||||
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) -r $(BUILD_DIR)
|
||||||
|
|
||||||
|
-include $(DEPS)
|
||||||
|
|
||||||
|
MKDIR_P ?= mkdir -p
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
TVM is a virtual machine for LC-3 based operating systems and it used for educational purposes.
|
TVM is a virtual machine for LC-3 based operating systems and it is used for educational purposes.
|
||||||
Open-source software under MIT License
|
Open-source software under MIT License
|
||||||
Written by Erick Ahmed, 2022
|
Written by Erick Ahmed, 2022
|
||||||
*/
|
*/
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
/* Initializing 10 registers of which:
|
/* Initializing 10 registers of which:
|
||||||
8 general purpose, 1 program counter, 1 conditional */
|
8 general purpose, 1 program counter, 1 conditional */
|
||||||
enum {
|
enum registers {
|
||||||
RG_GP0 = 0,
|
RG_GP0 = 0,
|
||||||
RG_GP1,
|
RG_GP1,
|
||||||
RG_GP2,
|
RG_GP2,
|
||||||
@@ -18,7 +18,7 @@ enum {
|
|||||||
RG_GP5,
|
RG_GP5,
|
||||||
RG_GP6,
|
RG_GP6,
|
||||||
RG_GP7,
|
RG_GP7,
|
||||||
RG_PC = 0, // program counter
|
RG_PC, // program counter
|
||||||
RG_COND, // condition flag
|
RG_COND, // condition flag
|
||||||
RG_COUNT
|
RG_COUNT
|
||||||
};
|
};
|
||||||
@@ -28,7 +28,7 @@ uint16_t memory[UINT16_MAX];
|
|||||||
uint16_t reg[RG_COUNT];
|
uint16_t reg[RG_COUNT];
|
||||||
|
|
||||||
/* Creating instruction set opcodes */
|
/* Creating instruction set opcodes */
|
||||||
enum {
|
enum opcodes {
|
||||||
OP_BR = 0, // branch
|
OP_BR = 0, // branch
|
||||||
OP_ADD, // add
|
OP_ADD, // add
|
||||||
OP_LD, // load
|
OP_LD, // load
|
||||||
@@ -48,9 +48,15 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Creating condition flags */
|
/* Creating condition flags */
|
||||||
enum {
|
enum flags {
|
||||||
FL_POS = 1, // P
|
FL_POS = 1, // P
|
||||||
FL_ZRO = 1 << 1, // Z
|
FL_ZRO = 1 << 1, // Z
|
||||||
FL_NEG = 1 << 2, // N
|
FL_NEG = 1 << 2, // N
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[]) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user