-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstruct_13_16.c
77 lines (68 loc) · 2.31 KB
/
instruct_13_16.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* instruct_13_16.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ydeineha <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/07 18:30:27 by ydeineha #+# #+# */
/* Updated: 2018/09/07 18:30:29 by ydeineha ### ########.fr */
/* */
/* ************************************************************************** */
#include "corewar.h"
void exec_lld(t_process *process, unsigned int *arg, t_arg_type *arg_type)
{
int res;
res = arg_fin(process, arg[0], arg_type[0]);
process->reg[arg[1] - 1] = res;
if (res == 0)
process->carry = 1;
else
process->carry = 0;
}
void exec_lldi(t_process *process, unsigned int *arg, t_arg_type *arg_type)
{
unsigned int res;
int delta;
int dst;
int arg_1;
int arg_2;
dst = arg[2];
arg_1 = arg_fin(process, arg[0], arg_type[0]);
arg_2 = arg_fin(process, arg[1], arg_type[1]);
if (arg_type[0] == T_DIR && arg_type[1] == T_DIR)
delta = (short)arg_1 + (short)arg_2;
else if (arg_type[0] == T_DIR)
delta = (short)arg_1 + arg_2;
else if (arg_type[1] == T_DIR)
delta = arg_1 + (short)arg_2;
else
delta = arg_1 + arg_2;
res = extract_ind(process, delta, 0);
process->reg[dst - 1] = res;
if (res == 0)
process->carry = 1;
else
process->carry = 0;
}
void exec_lfork(t_process *process, unsigned int *arg, t_arg_type *arg_type)
{
int delta;
int pc;
t_process *new;
new = NULL;
delta = arg_fin(process, arg[0], arg_type[0]);
pc = (process->pc + (short)delta) % MEM_SIZE;
if (pc < 0)
pc += MEM_SIZE;
new = new_process(NULL, process, pc);
add_process(&(g_game.proc), new);
}
void exec_aff(t_process *process, unsigned int *arg, t_arg_type *arg_type)
{
unsigned int res;
res = arg_fin(process, arg[0], arg_type[0]);
res = res % 256;
if (g_game.a && !g_game.visu)
ft_printf("Aff: %C\n", res);
}