LapisSea

Untitled

Oct 12th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. program to print a string from run arguments
  2. main{
  3.     define func* sampleFunction malloc(sizeof(*)) //alocate memory with size of 1 pointer (aka function call address)
  4.     bit[10*sizeof(call)] functInstructions={ //alocate and fill bit array with size of 10 ("call>" is instruction to convert readalbe code to asembler instructions
  5.         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)
  6.         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)
  7.         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)
  8.         call>TRACE POP (go back to pointer at the cuntion call, aka return... 1 asembler call)
  9.     };
  10.     memWrite(sampleFunction, functInstructions, 0, sizeof(byte)*arrSize(functInstructions));
  11.     delete functInstructions;
  12.     call sampleFunction;
  13.     __terminate;
  14. }
  15.  
  16. without comments explaining it
  17.  
  18. main{
  19.     define func* sampleFunction malloc(sizeof(*)
  20.     bit[10*sizeof(call)] functInstructions={
  21.         call>LOAD(DEFS::RUN_ARGS, sizeof(int))
  22.         call>calloc(__STACK[0]*sizeof(char))
  23.         call>WRITE_IO(DEFS::CONSOLE_OUT, __STACK[0], __STACK[1]*sizeof(char))
  24.         call>TRACE POP
  25.     };
  26.     memWrite(sampleFunction, functInstructions, 0, sizeof(byte)*arrSize(functInstructions));
  27.     delete functInstructions;
  28.     call sampleFunction;
  29.     __terminate;
  30. }
  31.  
  32. java equivalent:
  33.  
  34. public static void main(String[] args){
  35.     System.out.print(args[0]);
  36. }
Add Comment
Please, Sign In to add comment