home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / RiscOS / APP / DEVS / FORTH / BEETLE / BEETLE.ZIP / Beetle / literalt.c < prev    next >
C/C++ Source or Header  |  1997-04-22  |  2KB  |  69 lines

  1. /* LITERALT.C
  2.  
  3.     Vrsn  Date   Comment
  4.     ----|-------|------------------------------------------------------------
  5.     0.00 22nov94 Test (LITERAL) and (LITERAL)I.
  6.     0.01 23nov94 Removed spurious variable from main. Changed so that instrs
  7.                  is correct, after changing debug.c.
  8.     0.02 28nov94 Changed reference to b_mem to one to M0.
  9.     0.03 30nov94 Modified so that testing is automatic, and can run with or
  10.                  without debugging information. Modified to give a return value
  11.                  from main.
  12.     0.04 17feb95 Modified to work with new version of storage.c, and use
  13.                  btests.h rather than bintern.h.
  14.     0.05 28feb95 Removed printf format error.
  15.  
  16.     Reuben Thomas
  17.  
  18.  
  19.     Test the literal instructions. Also uses the NEXT instruction.
  20.  
  21. */
  22.  
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include "beetle.h"     /* main header */
  28. #include "btests.h"    /* Beetle tests header */
  29. #include "opcodes.h"    /* opcode enumeration */
  30. #include "debug.h"      /* debugging functions */
  31.  
  32.  
  33. char *correct[] = { "", "-257", "-257 12345678", "-257 12345678 -2" };
  34.  
  35.  
  36. int main(void)
  37. {
  38.     int i;
  39.  
  40.     init_beetle((BYTE *)malloc(1024), 256, 16);
  41.     here = EP;
  42.     S0 = SP;    /* save base of stack */
  43.  
  44.     start_ass();
  45.     ass(O_LITERAL); lit(-257); ass(O_LITERAL); lit(12345678);
  46.     ass(O_LITERALI); ilit(-2);
  47.     end_ass();
  48.     instrs++;    /* instrs is out by one when an immediate literal is the last
  49.                    thing assembled */
  50.  
  51.     NEXT;   /* load first instruction word */
  52.  
  53.     for (i = 0; i <= instrs; i++) {
  54. #ifdef B_DEBUG
  55.         show_data_stack();  printf("Correct stack: %s\n\n", correct[i - i / 5]);
  56. #endif
  57.         if (strcmp(correct[i - i / 5], val_data_stack())) {
  58.             printf("Error in LiteralT: EP = %ld\n", val_EP());
  59.             exit(1);
  60.         }
  61.         single_step();
  62. #ifdef B_DEBUG
  63.         printf("I = %s\n", disass(I));
  64. #endif
  65.     }
  66.     printf("LiteralT ran OK\n");
  67.     return 0;
  68. }
  69.