initial this repos, add template frome students

This commit is contained in:
feng-arch 2024-10-30 11:29:20 +08:00
commit 55efae7c59
12 changed files with 117 additions and 0 deletions

17
asm_parser.c Normal file
View File

@ -0,0 +1,17 @@
/***************************************************************************
* file name : asm_parser.c *
* author : *
* description : the functions are declared in asm_parser.h *
* The intention of this library is to parse a .ASM file *
* *
* *
***************************************************************************
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "asm_parser.h"
/* to do - implement all the functions in asm_parser.h */

22
asm_parser.h Normal file
View File

@ -0,0 +1,22 @@
/***************************************************************************
* file name : asm_parser.h *
* author : *
* description : this header file declares the functions for those *
* in the "asm_parser.c" library *
* standard "string.h" C-library. *
* *
***************************************************************************
*
*/
#define ROWS 100
#define COLS 255
int read_asm_file (char* filename, char program [ROWS][COLS] ) ;
int parse_instruction (char* instr, char* instr_bin_str) ;
int parse_reg (char reg_num, char* instr_bin_str) ;
int parse_add (char* instr, char* instr_bin_str ) ;
int parse_mul (char* instr, char* instr_bin_str ) ;
/* 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] ) ;

25
assembler.c Normal file
View File

@ -0,0 +1,25 @@
/***************************************************************************
* file name : assembler.c *
* author : *
* description : This program will assemble a .ASM file into a .OBJ file *
* This program will use the "asm_parser" library to achieve *
* its functionality. *
* *
***************************************************************************
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "asm_parser.h"
int main(int argc, char** argv) {
char* filename = NULL ; // name of ASM file
char program [ROWS][COLS] ; // ASM file line-by-line
char program_bin_str [ROWS][17] ; // instructions converted to a binary string
unsigned short int program_bin [ROWS] ; // instructions in binary (HEX)
}

BIN
cpp Normal file

Binary file not shown.

BIN
lcc Normal file

Binary file not shown.

0
libs/.gitkeep Normal file
View File

BIN
rcc Normal file

Binary file not shown.

7
test1.asm Normal file
View File

@ -0,0 +1,7 @@
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

0
tests/.gitkeep Normal file
View File

View File

@ -0,0 +1,5 @@
# This validation config is autogenerated by buildconfigs.sh script
# Here you can specify files that user has to enter relative to workplace directory.
# Allowed file types, default "", but can be name of file like: "submit/my_string.c" and similar
ALLOWED_FILE_TYPES="submit/asm_parser.c, submit/assembler.c"

36
tests/runtests.sh Normal file
View File

@ -0,0 +1,36 @@
#!/bin/bash
cd /home/codio/workspace/tests
# make sure source code exists
. ./files-validation.cfg
FILES_ALLOWED=$(echo "${ALLOWED_FILE_TYPES}" | tr -d '[:space:]')
VALIDATION_SUCCESSFULL="0"
for file_allowed in $(echo "${FILES_ALLOWED}" | sed -n 1'p' | tr ',' '\n'); do
if [ ! -f "../${file_allowed}" ]; then
echo "Could not find ${file_allowed}, please check if you have uploaded your files"
VALIDATION_SUCCESSFULL="1"
fi
done
if [ "${VALIDATION_SUCCESSFULL}" -eq "1" ]; then
echo "You have missing files, please check if you have uploaded everything that was required"
exit 1
fi
echo "No files are missing."
echo "______________________"
echo
# test compile all .c files
cd /home/codio/workspace
for file_allowed in $(echo "${FILES_ALLOWED}" | sed -n 1'p' | tr ',' '\n'); do
if [[ $file_allowed == *.c ]]; then
file_name="$(cut -d'/' -f2 <<<$file_allowed)"
if clang -c $file_allowed; then
echo "$file_name - Compile successful."
rm "$(cut -d'.' -f1 <<<$file_name)"".o"
else
echo "$file_name - Failed to compile!"
fi
fi
done
echo

5
tests/weights.cfg Normal file
View File

@ -0,0 +1,5 @@
# Score weights for all test classes
# This file has been generated by buildweightsconfig.sh script
# The score weights will work only if you include the weight key as first word of failure message
# The score weight can be set between 0 and infinity points :)