From 4bdad2d5c7dec0eb19c418cadb47cc3124092310 Mon Sep 17 00:00:00 2001 From: Rasmus Luha Date: Thu, 3 Nov 2022 01:08:28 +0200 Subject: praks IV done --- src/mem.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/mem.c') diff --git a/src/mem.c b/src/mem.c index 798fa1b..9b43c9d 100644 --- a/src/mem.c +++ b/src/mem.c @@ -1,4 +1,5 @@ #include +#include #include "mem.h" struct mem_st mem = { .pos = 0, .arr={0}}; @@ -62,3 +63,37 @@ void mem_printDebug(){ } printf("\n"); } + + + +/* +// Praks 10-11 Added + +void mem_add(int amount){ + mem.arr[mem.pos] += amount; +} + +mem_int(){return mem_add(-1);}; +mem_dec(){return mem_add(1);}; + +int mem_move(int amount) { + int new_pos = mem.pos + amount; + if (amount < 0) { + //NB, siin võib olla probleem + new_pos += (MEM_SIZE -1); + } + else if (new_pos >= MEM_SIZE){ + new_pos %= MEM_SIZE; + } + mem.pos = new_pos; + return mem_pos; +} + +void mem_init() { + memset(mem.arr, 0, MEM_SIZE * sizeof(char)); + //for (int i = 0; i < MEM_SIZE; ++i) { + // mem.arr[i] = 0; + //} +} + +*/ -- cgit v1.2.3