-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start implementing vm_op_and, vm_op_live, and vm_op_zjmp
- Loading branch information
Showing
4 changed files
with
45 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/04/19 21:39:11 by rnugroho #+# #+# */ | ||
/* Updated: 2018/04/25 01:38:11 by rnugroho ### ########.fr */ | ||
/* Updated: 2018/04/25 03:14:13 by rnugroho ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -111,7 +111,7 @@ void vm_op_print(t_process p); | |
void vm_sti_print(t_process p); | ||
void vm_and_print(t_process p); | ||
void vm_live_print(t_process p); | ||
void vm_zjump_print(t_process p); | ||
void vm_zjmp_print(t_process p); | ||
|
||
int vm_valid_arg(char *arg); | ||
int vm_valid_verbosity_lvl(int lvl); | ||
|
@@ -137,7 +137,7 @@ static t_op_dict g_op_dict[17] = { | |
{ .name = "\0", .opcode = 0x00, .d_size = 0, .param_c = 0, .is_oc = 0, | ||
{0, 0, 0}, &vm_op_inc, &vm_op_print, .is_car = 0, .cycles = 0}, | ||
{ .name = "live", .opcode = 0x01, .d_size = 4, .param_c = 1, .is_oc = 0, | ||
{T_DIR, 0, 0}, &vm_op_inc, &vm_live_print, .is_car = 0, .cycles = 10}, | ||
{T_DIR, 0, 0}, &vm_op_live, &vm_live_print, .is_car = 0, .cycles = 10}, | ||
{ .name = "ld", .opcode = 0x02, .d_size = 4, .param_c = 2, .is_oc = 1, | ||
{T_DIR | T_IND, T_REG, 0}, | ||
&vm_op_inc, &vm_op_print, .is_car = 1, .cycles = 5}, | ||
|
@@ -152,7 +152,7 @@ static t_op_dict g_op_dict[17] = { | |
&vm_op_inc, &vm_op_print, .is_car = 1, .cycles = 10}, | ||
{ .name = "and", .opcode = 0x06, .d_size = 4, .param_c = 3, .is_oc = 1, | ||
{T_REG | T_IND | T_DIR, T_REG | T_IND | T_DIR, T_REG}, | ||
&vm_op_inc, &vm_and_print, .is_car = 1, .cycles = 6}, | ||
&vm_op_and, &vm_and_print, .is_car = 1, .cycles = 6}, | ||
{ .name = "or", .opcode = 0x07, .d_size = 4, .param_c = 3, .is_oc = 1, | ||
{T_REG | T_IND | T_DIR, T_REG | T_IND | T_DIR, T_REG}, | ||
&vm_op_inc, &vm_op_print, .is_car = 1, .cycles = 6}, | ||
|
@@ -161,7 +161,7 @@ static t_op_dict g_op_dict[17] = { | |
&vm_op_inc, &vm_op_print, .is_car = 1, .cycles = 6}, | ||
{ .name = "zjmp", .opcode = 0x09, .d_size = 2, .param_c = 1, .is_oc = 0, | ||
{T_DIR, 0, 0}, | ||
&vm_op_inc, &vm_zjump_print, .is_car = 0, .cycles = 20}, | ||
&vm_op_zjmp, &vm_zjmp_print, .is_car = 0, .cycles = 20}, | ||
{ .name = "ldi", .opcode = 0x0a, .d_size = 2, .param_c = 3, .is_oc = 1, | ||
{T_REG | T_DIR | T_IND, T_DIR | T_REG, T_REG}, | ||
&vm_op_inc, &vm_op_print, .is_car = 0, .cycles = 25}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/04/23 19:23:14 by rnugroho #+# #+# */ | ||
/* Updated: 2018/04/25 01:37:22 by rnugroho ### ########.fr */ | ||
/* Updated: 2018/04/25 03:14:13 by rnugroho ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -62,3 +62,36 @@ void | |
free(temp); | ||
vm_op_inc(vm, p); | ||
} | ||
|
||
void | ||
vm_op_and(t_vm *vm, t_process *p) | ||
{ | ||
int param0; | ||
int param1; | ||
|
||
(void)vm; | ||
param0 = (p->op.params[0].type == REG_CODE) ? | ||
g_reg[p->op.params[0].value] : p->op.params[1].value; | ||
param1 = (p->op.params[1].type == REG_CODE) ? | ||
g_reg[p->op.params[1].value] : p->op.params[2].value; | ||
g_reg[p->op.params[2].value] = param0 & param1; | ||
if (g_reg[p->op.params[2].value] == 0) | ||
g_carrier = 1; | ||
vm_op_inc(vm, p); | ||
} | ||
|
||
void | ||
vm_op_live(t_vm *vm, t_process *p) | ||
{ | ||
(void)vm; | ||
p->live_nbr++; | ||
vm_op_inc(vm, p); | ||
} | ||
|
||
void | ||
vm_op_zjmp(t_vm *vm, t_process *p) | ||
{ | ||
(void)vm; | ||
if (g_carrier) | ||
p->pc = p->op.params[0].value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/04/24 13:51:02 by rnugroho #+# #+# */ | ||
/* Updated: 2018/04/24 19:36:00 by rnugroho ### ########.fr */ | ||
/* Updated: 2018/04/25 03:14:13 by rnugroho ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -56,7 +56,7 @@ void | |
} | ||
|
||
void | ||
vm_zjump_print(t_process p) | ||
vm_zjmp_print(t_process p) | ||
{ | ||
int value; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
.name "zork" | ||
.comment "just a basic living prog" | ||
|
||
l2: sti r1,r1,%0 | ||
l2: sti r1,%:live,%0 | ||
and r1,%0,r1 | ||
live: live %1 | ||
zjmp %:live |