home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / emulate / x_comp / 68hc11 / pseudo.c < prev    next >
C/C++ Source or Header  |  1986-11-01  |  4KB  |  154 lines

  1. /*
  2.  * pseudo --- pseudo op processing
  3.  */
  4.  
  5. #define RMB     0       /* Reserve Memory Bytes         */
  6. #define FCB     1       /* Form Constant Bytes          */
  7. #define FDB     2       /* Form Double Bytes (words)    */
  8. #define FCC     3       /* Form Constant Characters     */
  9. #define ORG     4       /* Origin                       */
  10. #define EQU     5       /* Equate                       */
  11. #define ZMB     6       /* Zero memory bytes            */
  12. #define FILL    7       /* block fill constant bytes    */
  13. #define OPT     8       /* assembler option             */
  14. #define NULL_OP 9       /* null pseudo op               */
  15.  
  16. struct oper pseudo[] = {
  17. "bsz",  PSEUDO, ZMB,    0,
  18. "end",  PSEUDO, NULL_OP,0,
  19. "equ",  PSEUDO, EQU,    0,
  20. "fcb",  PSEUDO, FCB,    0,
  21. "fcc",  PSEUDO, FCC,    0,
  22. "fdb",  PSEUDO, FDB,    0,
  23. "fill", PSEUDO, FILL,   0,
  24. "nam",  PSEUDO, NULL_OP,0,
  25. "name", PSEUDO, NULL_OP,0,
  26. "opt",  PSEUDO, OPT,    0,
  27. "org",  PSEUDO, ORG,    0,
  28. "pag",  PSEUDO, NULL_OP,0,
  29. "page", PSEUDO, NULL_OP,0,
  30. "rmb",  PSEUDO, RMB,    0,
  31. "spc",  PSEUDO, NULL_OP,0,
  32. "ttl",  PSEUDO, NULL_OP,0,
  33. "zmb",  PSEUDO, ZMB,    0
  34. };
  35.  
  36. /*
  37.  * do_pseudo --- do pseudo op processing
  38.  */
  39. do_pseudo(op)
  40. int op; /* which op */
  41. {
  42.  char fccdelim;
  43.  int     j;
  44.  int     fill;
  45.  char *skip_white();
  46.  
  47.  if( op != EQU && *Label )
  48.   install(Label,Pc);
  49.  
  50.  P_force++;
  51.  switch(op){
  52.   case RMB:                       /* reserve memory bytes */
  53.    if( eval() ){
  54.     Pc +=  Result;
  55.     f_record();     /* flush out bytes */
  56.     }
  57.    else
  58.     error("Undefined Operand during Pass One");
  59.    break;
  60.   case ZMB:                       /* zero memory bytes */
  61.    if( eval() )
  62.     while( Result-- )
  63.      emit(0);
  64.    else
  65.     error("Undefined Operand during Pass One");
  66.    break;
  67.   case FILL:                      /* fill memory with constant */
  68.    eval();
  69.    fill = Result;
  70.    if( *Optr++ != ',' )
  71.     error("Bad fill");
  72.    else{
  73.     Optr = skip_white(Optr);
  74.     eval();
  75.     while( Result-- )
  76.      emit(fill);
  77.     }
  78.    break;
  79.   case FCB:                       /* form constant byte(s) */
  80.    do{
  81.     Optr = skip_white(Optr);
  82.     eval();
  83.     if( Result > 0xFF ){
  84.      if(!Force_byte)
  85.       warn("Value truncated");
  86.      Result = lobyte(Result);
  87.      }
  88.     emit(Result);
  89.    }while( *Optr++ == ',' );
  90.    break;
  91.   case FDB:                       /* form double byte(s) */
  92.    do{
  93.     Optr = skip_white(Optr);
  94.     eval();
  95.     eword(Result);
  96.    }while( *Optr++ == ',' );
  97.    break;
  98.   case FCC:                       /* form constant characters */
  99.    if(*Operand==EOS)
  100.     break;
  101.    fccdelim = *Optr++;
  102.    while( *Optr != EOS && *Optr != fccdelim)
  103.     emit(*Optr++);
  104.    if(*Optr == fccdelim)
  105.     Optr++;
  106.    else
  107.     error("Missing Delimiter");
  108.    break;
  109.   case ORG:                       /* origin */
  110.    if( eval() ){
  111.     Old_pc = Pc = Result;
  112.     f_record();     /* flush out any bytes */
  113.     }
  114.    else
  115.     error("Undefined Operand during Pass One");
  116.    break;
  117.   case EQU:                       /* equate */
  118.    if(*Label==EOS){
  119.     error("EQU requires label");
  120.     break;
  121.     }
  122.    if( eval() ){
  123.     install(Label,Result);
  124.     Old_pc = Result;        /* override normal */
  125.     }
  126.    else
  127.     error("Undefined Operand during Pass One");
  128.    break;
  129.   case OPT:                       /* assembler option */
  130.    P_force=0;
  131.    if( head(Operand,"l") )
  132.     Lflag=1;
  133.    else if( head(Operand,"nol"))
  134.     Lflag=0;
  135.    else if( head(Operand,"c")){
  136.     Cflag=1;
  137.     Ctotal=0;
  138.     }
  139.    else if( head(Operand,"noc"))
  140.     Cflag=0;
  141.    else if( head(Operand,"contc")){
  142.     Cflag=1;
  143.     }
  144.    else
  145.     error("Unrecognized OPT");
  146.    break;
  147.   case NULL_OP:                   /* ignored psuedo ops */
  148.    P_force=0;
  149.    break;
  150.   default:
  151.    fatal("Pseudo error");
  152.   }
  153. }
  154.