Initial commit
This commit is contained in:
commit
e06e7d7afb
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
a.out
|
37
main.c
Normal file
37
main.c
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user