source/disassemble.c
/******************************************************
 * Attempt at writing some debugging functionality. This
 * is intended to display the current instruction and
 * the basic stack information as it exists when this
 * instruction is reached.
 *
 * Output takes a form like:
 *   AAAAA:   BBBBB            <C> DDDDD ---- <E> FFFFF
 *
 * Where:
 *   AAAAA   IP Address
 *   BBBBB   Instruction
 *   C       Depth of data stack
 *   DDDDD   Data stack contents
 *   E       Depth of address stack
 *   FFFFF   Address stack contents
 ******************************************************/
Attempt at writing some debugging functionality. This
is intended to display the current instruction and
the basic stack information as it exists when this
instruction is reached.

Output takes a form like:
AAAAA:   BBBBB             DDDDD ----  FFFFF

AAAAA   IP Address
BBBBB   Instruction
C       Depth of data stack
DDDDD   Data stack contents
E       Depth of address stack
FFFFF   Address stack contents
Attempt at writing some debugging functionality . This is intended to display the current instruction and the basic stack information as it exists when this instruction is reached . Output takes a form like : AAAAA : BBBBB DDDDD ---- FFFFF AAAAA IP Address BBBBB Instruction C Depth of data stack DDDDD Data stack contents E Depth of address stack FFFFF Address stack contents
void display_instruction(VM *vm)
{
  int i;
  char *names[] = { "nop",   "lit",   "dup",  "drop", "swap",  "push",         \
                    "pop",   "call",  "jump", "ret",  ">jump", "<jump",        \
                    "!jump", "=jump", "@",    "!",    "+",     "-",     "*",   \
                    "/mod",  "and",   "or",   "xor",  "<<",    ">>",    "0;",  \
                    "1+",    "1-",    "in",   "out",  "wait" };
  i = 0;
  fprintf(stderr, "%6i:   ", vm->ip);
  if(VMOP <= NUM_OPS)
    fprintf(stderr, "%5s", names[VMOP]);
  else
    fprintf(stderr, "??? ");
  if (VMOP == VM_LIT || VMOP == VM_CALL || VMOP == VM_JUMP || \
      VMOP == VM_LT_JUMP || VMOP == VM_GT_JUMP || VMOP == VM_EQ_JUMP || \
      VMOP == VM_NE_JUMP)
  {
    fprintf(stderr, " %6i", vm->image[vm->ip+1]);
    i = 1;
  }
  if (i == 0)
    fprintf(stderr, "       ");
  fprintf(stderr, "\t\t");
  fprintf(stderr, "<%i> ", vm->sp);
  for (i = vm->sp; i > 0; i--)
    fprintf(stderr, "%i ", vm->data[(vm->sp-i)+1]);
  fprintf(stderr, " ----  <%i> ", vm->rsp);
  for (i = vm->rsp; i > 0; i--)
    fprintf(stderr, "%i ", vm->address[(vm->rsp-i)+1]);
  fprintf(stderr, "\n\r");
}
void display_instruction ( VM * vm ) { int i ; char * names [ ] = { " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " } ; i = 0 ; fprintf ( stderr , " " , vm -> ip ) ; if ( VMOP <= NUM_OPS ) fprintf ( stderr , " " , names [ VMOP ] ) ; else fprintf ( stderr , " " ) ; if ( VMOP == VM_LIT || VMOP == VM_CALL || VMOP == VM_JUMP || VMOP == VM_LT_JUMP || VMOP == VM_GT_JUMP || VMOP == VM_EQ_JUMP || VMOP == VM_NE_JUMP ) { fprintf ( stderr , " " , vm -> image [ vm -> ip + 1 ] ) ; i = 1 ; } if ( i == 0 ) fprintf ( stderr , " " ) ; fprintf ( stderr , " \t \t " ) ; fprintf ( stderr , " " , vm -> sp ) ; for ( i = vm -> sp ; i > 0 ; i -- ) fprintf ( stderr , " " , vm -> data [ ( vm -> sp - i ) + 1 ] ) ; fprintf ( stderr , " " , vm -> rsp ) ; for ( i = vm -> rsp ; i > 0 ; i -- ) fprintf ( stderr , " " , vm -> address [ ( vm -> rsp - i ) + 1 ] ) ; fprintf ( stderr , " \n \r " ) ; }
Attempt at writing some debugging functionality.
Attempt at writing some debugging functionality .
/* Display the IP */ /* And the instruction, finding a name from the lookup table */ /* Some instructions take a following value. Display this if necessary. */ /* Padding if following data isn't required. */ /* Display the data stack */ /* And the address stack */ /* Whew, all done! */