Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program to print a string from run arguments
- main{
- define func* sampleFunction malloc(sizeof(*)) //alocate memory with size of 1 pointer (aka function call address)
- bit[10*sizeof(call)] functInstructions={ //alocate and fill bit array with size of 10 ("call>" is instruction to convert readalbe code to asembler instructions
- call>LOAD(DEFS::RUN_ARGS, sizeof(int)) //get length of first string (load pointer from defs, read int at that position... requires 2 asmebler calls)
- call>calloc(__STACK[0]*sizeof(char)) //alocate memory to store string characters from last read number aka string length (stack 0 already in place so no need to load that, call sizeof on char, multiply 2 numbers, request memory alocation... requires 4 asmebler calls)
- call>WRITE_IO(DEFS::CONSOLE_OUT, __STACK[0], __STACK[1]*sizeof(char)) //at stack 0 is now start of string character array, and at stack 1 is the string length (load console stream pointer, load string length, call sizeof in char, muliply, call wite io... 5 asembler calls)
- call>TRACE POP (go back to pointer at the cuntion call, aka return... 1 asembler call)
- };
- memWrite(sampleFunction, functInstructions, 0, sizeof(byte)*arrSize(functInstructions));
- delete functInstructions;
- call sampleFunction;
- __terminate;
- }
- without comments explaining it
- main{
- define func* sampleFunction malloc(sizeof(*)
- bit[10*sizeof(call)] functInstructions={
- call>LOAD(DEFS::RUN_ARGS, sizeof(int))
- call>calloc(__STACK[0]*sizeof(char))
- call>WRITE_IO(DEFS::CONSOLE_OUT, __STACK[0], __STACK[1]*sizeof(char))
- call>TRACE POP
- };
- memWrite(sampleFunction, functInstructions, 0, sizeof(byte)*arrSize(functInstructions));
- delete functInstructions;
- call sampleFunction;
- __terminate;
- }
- java equivalent:
- public static void main(String[] args){
- System.out.print(args[0]);
- }
Add Comment
Please, Sign In to add comment