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

  1. /* LINKT.C
  2.  
  3.     Vrsn  Date   Comment
  4.     ----|-------|---------------------------------------------------------------
  5.     0.00 18apr95
  6.  
  7.     Reuben Thomas
  8.  
  9.  
  10.     Test the LINK instruction. Assumes 4-byte addresses.
  11.  
  12. */
  13.  
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include "beetle.h"     /* main header */
  18. #include "btests.h"    /* Beetle tests header */
  19. #include "opcodes.h"    /* opcode enumeration */
  20. #include "debug.h"      /* debugging functions */
  21.  
  22.  
  23. void test(void)
  24. {
  25.     *--SP = 37;
  26. }
  27.  
  28. int main(void)
  29. {
  30.     CELL res;
  31.  
  32.     init_beetle((BYTE *)malloc(16384), 4096, 16);
  33.     S0 = SP;    /* save base of stack */
  34.  
  35.     here = EP;    /* start assembling at 16 */
  36.     start_ass();
  37.     ass(O_LITERAL); lit((CELL)(test)); ass(O_LINK); ass(O_ZERO); ass(O_HALT);
  38.     end_ass();
  39.  
  40.     NEXT;   /* load first instruction word */
  41.     res = run();
  42.     if (res != 0) {
  43.         printf("Error in LinkT: test aborted with return code %ld\n", res);
  44.         exit(1);
  45.     }
  46.  
  47. #ifdef B_DEBUG
  48.         printf("Top of stack is %d; should be %d\n", *SP, 37);
  49.         show_data_stack();
  50.         printf("%p\n", test);
  51. #endif
  52.         if (*SP != 37) {
  53.             printf("Error in LinkT: incorrect value on top of stack\n");
  54.             exit(1);
  55.         }
  56.  
  57.     printf("LinkT ran OK\n");
  58.     return 0;
  59. }
  60.