Initial commit

This commit is contained in:
Marcelina Szostak 2025-04-18 15:36:38 +02:00
commit e06e7d7afb
Signed by: kapcioszek
GPG Key ID: 5B07EB46181A963B
2 changed files with 38 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
a.out

37
main.c Normal file
View File

@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv){
long mem_size = 0;
//Handling arguments
if(argc < 2){
printf("too few arguments\n");
return 1;
}
for(int i = 1; i < argc; i++){
if(strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--memory") == 0){
char *endptr;
long convert = strtol(argv[i+1], &endptr, 10);
mem_size = &endptr != NULL ? convert : mem_size;
}
if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0){
printf("Usage: %s [OPTIONS] file\nOptions:\n%s-m, --memory: specify RAM size\n%s-h, --help: print this message\n\n",argv[0]," "," ");
return 0;
}
}
//Intializing memory and stuff
long PC = 0; //program counter
char *mem_pointer = malloc(mem_size * sizeof(char)); //allocate RAM
if(mem_pointer == NULL){
printf("ERROR: Memory allocation failed (Buy more RAM)");
return 2;
}
free(mem_pointer);
return 0;
}