Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: zael-mab <zael-mab@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/02/14 05:40:09 by zael-mab #+# #+# #
# Updated: 2021/02/03 14:17:43 by zael-mab ### ########.fr #
# #
# **************************************************************************** #

NAME = asm

SRC = main.c\
link_lst.c\
op.c\
pars.c\
set_op.c\
args.c
OBJ = $(SRC:.c=.o)

HEADER = asm.h
LIBFT_DIR = ./libft
LIBFT = $(LIBFT_DIR)/libft.a

CC = gcc
CFLAGS = -Wall -Wextra -Werror
LDFLAGS = -L$(LIBFT_DIR)
LDLIBS = -lft

# =========================================================================== #

all: depbuild $(NAME)

depbuild:
@make -C $(LIBFT_DIR)

$(NAME): $(OBJ) $(HEADER)
$(CC) $(OBJ) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $(NAME)


clean:
@rm -f $(OBJ)
@make -C $(LIBFT_DIR) clean

fclean: clean
@rm -f $(NAME)
@make -C $(LIBFT_DIR) fclean
@echo "done\033[0m"

re: fclean all
9 changes: 9 additions & 0 deletions abs.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.name "Batman"
.comment "This city needs me"

loop:
sti r1, %:live, %1 # <-- На эту операцию указывает метка loop
live:
live %0 # <-- На эту операцию указывает метка live
ld %0, r2 # <-- А на эту операцию никакая метка не указывает
zjmp %:loop
98 changes: 98 additions & 0 deletions args.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* args.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zael-mab <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/21 17:44:27 by zael-mab #+# #+# */
/* Updated: 2021/02/21 17:44:35 by zael-mab ### ########.fr */
/* */
/* ************************************************************************** */

#include "asm.h"


int check_reg(char *line, int arg);


int pars_args(char *instruction, t_asmdata *sdata, int y)
{
int j;
int x;
int w;

j = -1;
w = y;
x = 0;
int cnt = -1; //
char **tab = ft_strsplit(instruction, ',');

ft_printf ("-_-_-_-_-_-_-_-_-_-%s-_-_-_-_-_-\n", sdata->name);
while (tab[++j])
{
x = -1;
// cnt = op_tab[x].args[j];
while (tab[j][++x])
{

if (tab[j][x] == 'r' && ft_isdigit(tab[j][x + 1]))
{
// if (ft_atoi(x + 1 + tab[j]) < 1 || ft_atoi(x + 1 + tab[j]) > 16)
// ft_printf ("Error! %d \n", ft_atoi(x + 1 + tab[j]));
ft_putchar ('R');
// check_reg(tab[j], cnt);
break ;
}
if (tab[j][x] == 'r' && !ft_isdigit(tab[j][x + 1]))
ft_printf("!Error\n");
else if (tab[j][x] == '%') //DIRECT_CHAR (%) and a number or label (LABEL_CHAR (:) in front of it)
{
//check_dir();
ft_putchar ('D');
break ;
}
else if (ft_isdigit(tab[j][x]))
{
ft_putchar ('I');
// check_ind();
break ;
}
}
ft_printf("-%s-\n", tab[j]);

}
return (1);
}

int check_reg(char *line, int arg)
{
char *tmp = ft_strtrim(line);
int i;

i = -1;
while (tmp[++i])
{
if (tmp[i] == 'r' && ft_atoi( 1 + tmp) > 0 && ft_atoi( 1 + tmp) > 0)
{
if (!(arg & T_REG))
{
ft_printf ("arg number [%s] wrrong\n", tmp);
break ;
}
else
{
ft_putstr ("(r) are good");
break;
}
}
else
{
ft_printf ("Error [%s] \n", tmp);
break ;
}
}

free(tmp);
return (1);
}
94 changes: 94 additions & 0 deletions asm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* asm.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zael-mab <zael-mab@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/28 10:48:45 by zael-mab #+# #+# */
/* Updated: 2021/02/03 14:22:25 by zael-mab ### ########.fr */
/* */
/* ************************************************************************** */


// fix the ft_printf macros !
#ifndef ASM_H
#define ASM_H

#include "libft/libft.h"
#include "op.h"
#include<fcntl.h>
#include<errno.h>

typedef enum {F , T} boolean;

typedef struct s_node
{
char *data;
size_t position;
int operation_num; //labels -pointes operation-
int op_code;
int op_arg1;
int op_arg2;
int op_arg3;
char *op_args[3];
struct s_node *next;
} t_node;

typedef struct s_head
{
size_t l_size;
struct s_node *first;
} t_head;


typedef struct s_op
{
char name[5];
int args_numb;
int args[3];
int op_code;
int wait_to_run;
char des[60];
int x;
int dir_size;
} t_op;


typedef struct s_asmdata
{
char *name;
char *comment;
int n;
int c;
int s;
int e;
int error;
int p_ex_code;
} t_asmdata;

t_op op_tab[17];




t_node *insert_node(t_head *head, void *data, int pos);
void display_nodes(t_head *head); //
void init_head(t_head *head);
char *avoid_comment (char *line);
boolean check_champion (char *line, t_asmdata *sdata);
boolean join (char *line, t_asmdata *sdata, char **cmd, int v);
t_node *search(t_node *l, char* x);


t_node *save_labels(t_head *labels, char *lin, t_head *head);
// void creat_op_table(t_hop *op, int i);

void pars_instructions(t_head *head, t_head *labels, t_asmdata *sdata);

void operations(char **operat, int i);

int pars_args(char *instruction, t_asmdata *sdata, int y);


# endif
32 changes: 32 additions & 0 deletions bee_gees.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.name"one
#two
three"
.comment"Ha, Ha, Ha,
stayiiiiin'
aliiiiiiiiiive"

sti r1, %:live, %1 ;change live by the right value

sti r1, %:live2, %1 ;change live by the right value


ld %1, r3
ld %33, r6
#While (r2 < 10)
forks:
add r2, r3, r2 ;increment r2
xor r2, %15, r4 ;if (r4) {carry = 0}
live2: live %4
zjmp %:endwhile ;if (carry)
fork %:forks
ld %0, r4 ;carry = 1
zjmp %:forks
ld :forks ,r1
#EndWhile
endwhile:
ld %0, r4 ;carry = 1

live: live %4
zjmp %:live
xxm:

90 changes: 90 additions & 0 deletions bigzork.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
.name "bigzork"
.comment "I know i cant win"

ld %0, r2
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
st r1, 211
loop:
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
live %1
zjmp %:loop
Loading