亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? pcasm5b.c

?? 這是8位微處理器的Verilog源代碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
**
**  PCASM
**  Assembler for the PC (PopCorn) 8 bit CISC processor
**
**
**  1/23/99
**  o added command line interfacing
**
**  1/19/99
**  o added ability to tell in which line unresolved labels occurs
**  o had the output file be dumped to a file
**
**  1/18/99
**  o a whole lot of things works now.  See 'rules.dat'
**  o fixed a bug in reg_find() routine. It used to get stuck in infite
**    loop if no valid register mnemonic is found
**  o added error list
**
**  1/11/99
**  Started work on the assembler
**
*/


#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <math.h>

#define     BUFFSIZE    512
#define     CODESIZE    4096
#define     LABEL_SIZE  2048
#define     BL          25          // length of line buffer
#define     NL         '\n'
#define     CR         '\r'
#define     TAB        '\t'
#define     FORMFEED   '\f'
#define     MODE_BYTE   0
#define     MODE_ADDX   1
#define     LINE_BUFF_SIZE 100
#define     ERROR_LIST_SIZE 100

#define     debug
#define     debug2      0

#define     filedebug

main (int argc, char *argv[])
//main ()
{

  // Vars and etc
  FILE            *fp, *fopen(), *fp_opcode, *exec_file, *list_fp;
  int             fclose(),c,tt;
  unsigned char   *c_buffer,d,*file_name, *c_code, *binary_name, *list_file;
  unsigned char   *str_label1, *line_lab;
  unsigned int    result_buffer[BL];
  int             source_line_count,i,j,c_code_ptr,k;
  int             mnemonic_line_count;
  int             line_start,line_end;
  char            line_buff[LINE_BUFF_SIZE],ca,cb,cc,cd,ce,cf;
  char            mnemonic[7],mychar;
  int             value,qq,x,y,z,word_len,word_len2,ptr,ptr2,match;
  int             label_addx;
  unsigned int    label_index1[100], line_lab_index[100];
  unsigned int    label_line[100];
  unsigned int    str_label1_ptr, str_label2_ptr, line_lab_ptr;
  unsigned int    label_index1_ptr, line_lab_index_ptr;
  unsigned int    error_counter, labels_matched;
  unsigned char   nextlabel[BL], nextlabel2[BL];
  unsigned int    error_list[ERROR_LIST_SIZE];

  // Prototype declaration
  unsigned int    count_line();
  void            find_mnemonic();
  void            find_immed();
  int             find_word();
  int             find_reg();

/*
  printf("argument count =%d\n",argc);
  for(i=0;i<argc;i++)
  { myargv[i] = argv[i];
    printf("Arguments = %s\n",myargv[i]);
  }
*/


  file_name = "xx.asm";
  //binary_name = "out.bin";
  //list_file = "out.lst";

  // a note about the error list
  // the even location 0,2,4, ... contains the source line
  // where the error is
  // the odd locations 1,3,5, ... contains the error code
  //
  // error code:
  //        00 = unresolved label
  //



  // A word about labels
  // there are two labels:
  //  - opcode label, which is the address in the branching opcode in
  //       text form
  //  - line libel, which is the 'word' a line of code starts with
  //
  // During pass 1, both of these labels are stored, literally, along
  // with the address where they are located.  There are 5 arrays
  // associated with this:
  //
  // unsigned char str_label1[]
  //   this array holds the literal characters making up the label
  //   found in an instruction.  It is space (0x20) terminated
  //
  // unsigned int label_index1[]
  //   this array holds the address where the label in str_label1[] was
  //   found.  The indexes of this array and the str_label1 array are
  //   the same
  //
  // unsigned int label_line[]
  //   this array holds the line in which the opcode label was found.
  //   it is used for error purposes
  //
  //
  // unsigned char line_lab[]
  //   this array holds the literal characters making up the line label
  //   it is space ' ' terminated
  //
  // unsigned int line_lab_index[]
  //   array holding the address of the opcode following this label
  //
  //
  // During pass2, the two arrays are compared to resolve the addresses
  //
  //


  label_index1_ptr = 0;
  line_lab_ptr = 0;
  str_label1_ptr = 0;
  line_lab_index_ptr = 0;
  error_counter = 0;

  
  /* open the source file .. to be replaced by command argument */
/*  if( (fp=fopen(file_name,"r+")) == NULL )
	{ printf("error opening file\n");
	  exit(-1);
	}
*/
  if(argc<4) {
    printf("Usage\n");
	printf("pcasm [sourcefile] [binaryfile] [listfile]\n");
	printf("where:\n");
	printf("sourcefile = the assembler code file\n");
	printf("binaryfile = compiled file name\n");
	printf("listfile   = debug listing file name\n");
    exit(-1);
  }
  if( (fp=fopen(argv[1],"r+")) == NULL )
	{ printf("error opening file\n");
	  exit(-1);
	}

// Open the listing file
  if( (list_fp=fopen(argv[3],"w")) == NULL )
	{ printf("error opening list file\n");
	  exit(-1);
	}

  source_line_count = count_line(fp);
  fprintf(list_fp,"\nSource File: \t%s\n",argv[1]);
  fprintf(list_fp,"Dest File: \t%s\n",argv[2]);
  fprintf(list_fp,"Listing File: \t%s\n",argv[3]);
  fprintf(list_fp,"\nTotal line count in source file= %d\n",source_line_count);


  /* open the opcode definition file */
  if( (fp_opcode=fopen("opcode.dat","r+")) == NULL )
	{ printf("error opening 'opcode.dat'\n");
	  exit(-1);
	}
  mnemonic_line_count = count_line(fp_opcode);
  fprintf(list_fp,"Total line count in opcode.dat= %d\n",mnemonic_line_count);

  // dump file for debug
  #if(debug2)
  c=10;
  while( c!=EOF)
   { c=fgetc(fp);
     if (c==TAB)
	printf(".TAB.");
     else if(c==NL)
	printf("..NL\n");
     else
	printf("%c",c);
   }
  rewind(fp);

  // dump opcode.dat
  for(j=0;j<mnemonic_line_count;j++)
  {  fscanf(fp_opcode,"%s %x",mnemonic,&value);
     fprintf(list_fp,"%s %x\n",mnemonic,value);
  }
  #endif


  //
  // Request memory space for buffer (type char)
  //
  if ( (c_buffer=(unsigned char *)malloc(BUFFSIZE)) == NULL)
	{ printf("error reserving memory space\n");
	  exit(-1);
	}
  //
  // Request 4Kb of memory space to hold the compiled code
  //
  if ( (c_code=(unsigned char*)malloc(CODESIZE)) == NULL )
	{ printf("could not reserve 4Kb of code space\n");
	  exit(-2);
	}
  //
  // Request 4Kb of memory space to hold labels on Pass 1
  //
  if ( (str_label1=(unsigned char*)malloc(LABEL_SIZE)) == NULL )
	{ printf("could not reserve 4Kb of label pass 1 space\n");
	  exit(-3);
	}
  //
  // Request 4Kb of memory space to hold labels on Pass 2
  //
  if ( (line_lab=(unsigned char*)malloc(LABEL_SIZE)) == NULL )
	{ printf("could not reserve 4Kb of label pass 2 space\n");
	  exit(-4);
	}




  //
  // Pass 1:
  // Go through the code "line-by-line" e.i. between CR's and
  // scan for valid opcode, translate it and write the opcode byte(s)
  // into the c_code buffer.
  //
  rewind(fp); // reset source file pointer to beginning
  line_end = -1; // initial value of line_end
  c_code_ptr=0;
  for (i=0;i<source_line_count;i++)
  {
	//flush line buffer
	for(j=0;j<LINE_BUFF_SIZE;j++) line_buff[j]=NULL;

	// mark the beginning of present line. I.E. loc of last NL + 1
	line_start = line_end+1;

	// find end of present line.  I.E. where NL is found
	// and copy the line into a buffer
	j=0;
	while( (c=fgetc(fp)) != NL )
	{ line_buff[j]=c;             // copy chars into line buffer
	  j++;
	}
	line_end = line_start + j;
	line_buff[j]==NULL;           // stuff null to end of line buffer

	fprintf(list_fp,"line %d %s\n",i,line_buff);  // print source line
	fprintf(list_fp,"\t");

	// find opcode in the present line
	find_mnemonic(fp_opcode,line_buff,j,mnemonic_line_count,&result_buffer,list_fp);

	// if there is an error, record it in error_list[]
	if((result_buffer[0]&0x0f)==2)
	{ error_list[2*error_counter]   = i+1;
	  error_list[2*error_counter+1] = result_buffer[0];
	  error_counter++;
	}

	// if a valid opcode was found , update c_code buffer
	if ( (result_buffer[0]&(0x7f))==0 || (result_buffer[0]&(0x7f))==3 )
	{  fprintf(list_fp,"\t%X: ",c_code_ptr);
	   for(qq=0;qq<result_buffer[1];qq++) {
	     c_code[c_code_ptr+qq]=result_buffer[qq+2];
		 fprintf(list_fp,"%X ",c_code[c_code_ptr+qq]);
       }
	   c_code_ptr=c_code_ptr+qq;
	   fprintf(list_fp,"\n");
	}
	else
	 fprintf(list_fp,"\n");

	// if a label was found within the instruction..
	if( (result_buffer[0]&(0x7f)) == 3)
	{ x=result_buffer[1]+2;
	  y=result_buffer[x];
	  for(tt=0;tt<y;tt++)
	  { mychar=result_buffer[x+tt+1];
	    *(str_label1+str_label1_ptr)=mychar;
	    str_label1_ptr++;
	  }
	  *(str_label1+str_label1_ptr)=' ';   // insert a blank at the end
	  str_label1_ptr++;

	  // save the addx of this label
	  label_index1[label_index1_ptr]=c_code_ptr-result_buffer[1]+1;

	  // save the line where this label occurred
	  label_line[label_index1_ptr] = i+1;

	  label_index1_ptr++;  // point to next label

	}


	// if a line starts with a label ..
	if( (result_buffer[0]&(0x80)) != 0 )
	{ ptr=0;   // we're still in the same line, so get the first word
	  word_len=find_word(line_buff,&ptr,BL,nextlabel2);
	  // copy the label into the str_label2 buffer
	  for(tt=0;tt<(word_len-1);tt++)
	  {  mychar = *(nextlabel2+tt);
	     *(line_lab+line_lab_ptr) = mychar;
	     line_lab_ptr++;
	  }
	  *(line_lab+line_lab_ptr)=' ';   // insert a blank at the end
	  line_lab_ptr++;

	  // if the line has label and opcode, mark the addx of the opcode
	  // as the address of label
	  if( ( (result_buffer[0]&(0x8F)) == 0x80 ) || \
		( (result_buffer[0]&(0x8F)) == 0x83 )      )
	  {  line_lab_index[line_lab_index_ptr]=c_code_ptr-result_buffer[1];
	     line_lab_index_ptr++;
	  }
	  // else if this line only has label, mark present c_code_ptr + 1
	  // as the address of the label
	  else if( (result_buffer[0]&(0x8F)) == 0x81 )
	  {  line_lab_index[line_lab_index_ptr]=c_code_ptr ;
	     line_lab_index_ptr++;
	  }

	}

  } // pass 1


  /*
  ** PASS 2
  **
  ** Resolve labels from the two label arrays:
  **    str_label1 array which hold the literal label names from
  **               opcodes
  **    line_lab   array which holds the literal label names from
  **               line beginning
  **
  ** Store the line# of the unresolved label in the error_table
  **
  */
  // scan through howmany opcode labels there are
  ptr=0;
  match=1;
  labels_matched=0;
  for(i=0;i<label_index1_ptr;i++)
  {
    // get opcode label
    word_len = find_word(str_label1,&ptr,LABEL_SIZE,nextlabel);
    ptr2=0;
    for (j=0;j<line_lab_index_ptr;j++)
    {
	word_len2 = find_word(line_lab,&ptr2,LABEL_SIZE,nextlabel2);
	if((match=strcmp(nextlabel,nextlabel2))==0)
	  break;  // break out of this loop if match is found
    }

   // in the event match is found..
   if(match==0)
   { label_addx = line_lab_index[j];  // get line label addx
     c_code[label_index1[i]]  = label_addx%256;
     c_code[label_index1[i]+1]= label_addx/256;
     labels_matched++;
   }

   // if no match is found, store this line number in the error_list
   // array. the error code for unresolved label is 0
   else
   {
     error_list[error_counter*2]   = label_line[i];
     error_list[error_counter*2+1] = 0;
     error_counter++;
   }

  }  // pass2



  /*
  ** SAVE RESULT
  */

  /* open the opcode definition file */
  if( (exec_file=fopen(argv[2],"w")) == NULL )
	{ fprintf(list_fp,"error opening opcode.bin\n");
	  exit(-1);
	}
  for(i=0;i<CODESIZE;i++)
    { fprintf(exec_file,"%X ",c_code[i]);
	if( (i%8) == 0 )
	  fprintf(exec_file,"\n");
    }

  fclose(exec_file);


  // Print error list
  tt=label_index1_ptr-labels_matched;
  fprintf(list_fp,"\nTotal Errors = %d \n",error_counter+tt);
  i=0;
  while(i!=error_counter)
  {
    j=error_list[2*i];
    k=error_list[2*i+1];
    fprintf(list_fp,"error in line %d : ",j);
    if(k==0)
	fprintf(list_fp," unresolved label\n");
    else
	fprintf(list_fp," code %d\n",k);
    i++;
  }
  if (labels_matched==label_index1_ptr)
    fprintf(list_fp,"All labels resolved\n");
  else
    fprintf(list_fp,"Error: there are %d label(s) unresolved\n",tt);



  // opcode label table
  ptr=0;
  fprintf(list_fp,"\nOpcode Label Table\n");
  fprintf(list_fp,"==================\n");
  fprintf(list_fp,"addx \t label\n\n");
  for(i=0;i<label_index1_ptr;i++)
  { word_len=find_word(str_label1,&ptr,LABEL_SIZE,nextlabel);
    fprintf(list_fp,"%d \t %s\n",label_index1[i],nextlabel);
  }

  // pass 1 :: line label table
  ptr=0;
  fprintf(list_fp,"\nLine Label Table\n");
  fprintf(list_fp,"==================\n");
  fprintf(list_fp,"addx \t label\n\n");
  for(i=0;i<line_lab_index_ptr;i++)
  { word_len=find_word(line_lab,&ptr,LABEL_SIZE,nextlabel);
    fprintf(list_fp,"%d \t %s\n",line_lab_index[i],nextlabel);
  }


  // Raw hex dump of data
  for(i=0;i<50;i++)
  { if(i%10==0)
     fprintf(list_fp,"\n");
    fprintf(list_fp,"%x ",c_code[i]);
  }





  // free-up all allocated memory and close all opened files
  free(c_buffer);
  free(c_code);
  free(str_label1);
  free(line_lab);
  fclose(fp);
  fclose(fp_opcode);
  fclose(list_fp);

}


/*
** Determine the number of lines
**
** This subroutine DESTROYS the current location of file pointer
** and resets it to the beginning of the file
*/
unsigned int count_line(FILE *fp)
{
  unsigned int    line_count=0;
  unsigned int    c;

  while((c=fgetc(fp))!=EOF)
   if (c==NL)
	 line_count++;

  rewind(fp);
  return(line_count);
}


/*
** find_mnemonic
**
**
** input:
**          unsigned char *line_buffer    pointer to line_buffer
**          unsigned int  length          length of line_buffer
**          FILE          *fp_opcode      file pointer to opcode.dat
**          unsigned int  mnemonic_lines  total lines in mnemonic file
**          unsigned int  *result_buffer  pointer to result buffer
**
**
** outputs:
**          unsigned int result_buffer[]
**                contains the following data:
**                      result_buffer[0] status:
**                            msb=1 the line starts with a label
**                            3     a branching opcode with label was found
**                            2     means error, opcode found, but
**                            1     means no opcode found
**                            0     means opcode found, and all is ok
**                      result_buffer[1]
**                            number of opcodes
**                      result_buffer[2 ~ N]
**                            opcodes making up the instruction
**                      result_buffer[N+1]
**                            the length of the label
**                      result_buffer[N+2 ~ M]
**                            label iff result_buffer[0]==3
**          N=length of opcode
**          M=length of label
**
*/

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美精品一二三区| 中文在线免费一区三区高中清不卡| 国产高清无密码一区二区三区| 麻豆久久久久久久| 男男视频亚洲欧美| 麻豆成人综合网| 精品一区免费av| 久久99精品久久久久婷婷| 久久国产成人午夜av影院| 激情综合网激情| 国产iv一区二区三区| 成人永久看片免费视频天堂| av在线这里只有精品| 97久久久精品综合88久久| 99久久99久久精品免费看蜜桃| 91蜜桃网址入口| 欧美亚洲精品一区| 7777精品伊人久久久大香线蕉的 | 国产女人18水真多18精品一级做| 久久久精品国产免大香伊| 中文字幕不卡在线播放| 国产精品国产a| 亚洲精品国产视频| 青青草一区二区三区| 国产一区二区三区香蕉| 成人激情开心网| 欧美午夜在线观看| 欧美成人综合网站| 国产午夜精品美女毛片视频| 亚洲欧洲三级电影| 亚洲一区二区欧美| 韩国精品一区二区| 99久久99久久精品国产片果冻| 欧美三级日本三级少妇99| 日韩一级完整毛片| 国产精品欧美精品| 亚洲444eee在线观看| 久久精品久久99精品久久| 成人午夜激情影院| 欧美喷水一区二区| 欧美成人一级视频| 中文字幕一区二区三区不卡在线| 亚洲一区二区中文在线| 国产毛片精品一区| 91猫先生在线| 亚洲精品在线一区二区| 亚洲品质自拍视频网站| 蜜臀久久久久久久| 成人av免费在线播放| 欧美一级免费观看| 亚洲天堂免费在线观看视频| 日产国产欧美视频一区精品| 成人av免费在线观看| 欧美一级片在线观看| 亚洲色图丝袜美腿| 精品制服美女丁香| 欧洲一区在线观看| 国产清纯美女被跳蛋高潮一区二区久久w| 亚洲日穴在线视频| 国产一区二区调教| 欧美浪妇xxxx高跟鞋交| 国产精品欧美极品| 国精品**一区二区三区在线蜜桃| 在线欧美小视频| 欧美国产欧美综合| 美女视频网站久久| 欧美三级在线播放| 亚洲蜜臀av乱码久久精品| 国产美女视频91| 欧美一区二区国产| 亚洲综合视频在线| av电影一区二区| xnxx国产精品| 青草av.久久免费一区| 欧美日韩一区二区在线观看视频| 国产精品成人一区二区三区夜夜夜| 狠狠色狠狠色综合系列| 777色狠狠一区二区三区| 一区二区三区精品久久久| 成人午夜激情视频| 久久久久久久久97黄色工厂| 免费人成黄页网站在线一区二区| 欧美色精品在线视频| 亚洲欧洲综合另类在线| 成人午夜碰碰视频| 欧美激情资源网| 高清在线成人网| 国产亚洲va综合人人澡精品| 久久99日本精品| 91精品国产欧美一区二区18| 亚洲国产va精品久久久不卡综合| 日韩精品在线网站| 91豆麻精品91久久久久久| 欧美日韩三级视频| 亚洲成年人网站在线观看| 欧美精品欧美精品系列| 日本不卡一区二区| 精品国产乱码久久久久久1区2区| 韩日av一区二区| 国产精品久久久久久久浪潮网站| 91在线视频18| 天堂蜜桃91精品| 欧美xingq一区二区| 国产婷婷色一区二区三区四区| 亚洲成人久久影院| 色悠悠久久综合| 婷婷激情综合网| 久久色在线观看| 91免费在线播放| 日韩中文字幕区一区有砖一区| 精品99999| 一本一道波多野结衣一区二区| 视频一区视频二区在线观看| 久久婷婷色综合| 色欧美乱欧美15图片| 裸体在线国模精品偷拍| 亚洲视频综合在线| 欧美一级专区免费大片| 99国产精品久久久久久久久久久| 婷婷久久综合九色国产成人 | 亚洲激情校园春色| 成人高清免费观看| 欧美日韩精品欧美日韩精品| 精品一区免费av| 亚洲视频狠狠干| 欧美一区二区三区免费| 成人美女在线视频| 日韩成人精品在线| 中文字幕欧美一区| 一区二区免费在线| 久久久久国产精品厨房| 成人av电影在线网| 日韩中文字幕亚洲一区二区va在线| 国产清纯白嫩初高生在线观看91 | 一区二区三区在线播放| 日韩欧美国产综合| 一本久久a久久免费精品不卡| 国产真实乱对白精彩久久| 亚洲精品乱码久久久久久久久| 精品国产区一区| 欧美唯美清纯偷拍| 不卡的av在线播放| 精品无人码麻豆乱码1区2区| 亚洲国产精品一区二区久久恐怖片| 国产欧美日韩视频在线观看| 欧美一区二区视频网站| 色欧美乱欧美15图片| 成人深夜福利app| 精品一区二区三区视频在线观看 | 欧美一级欧美一级在线播放| 一本到三区不卡视频| 国产精品综合av一区二区国产馆| 三级精品在线观看| 亚洲黄色av一区| 国产精品美女一区二区| 精品捆绑美女sm三区| 欧美日韩精品电影| 欧洲一区在线观看| 91美女福利视频| av亚洲精华国产精华精华| 激情综合色丁香一区二区| 日韩中文字幕区一区有砖一区 | 欧美系列亚洲系列| 色综合激情久久| 成人sese在线| 成人一级视频在线观看| 裸体一区二区三区| 日本免费新一区视频| 亚洲午夜免费电影| 亚洲精品综合在线| 中文字幕一区二区三区在线不卡| 国产偷国产偷精品高清尤物 | 国产精品一区在线观看乱码| 免费亚洲电影在线| 日韩黄色小视频| 视频一区国产视频| 亚瑟在线精品视频| 午夜伊人狠狠久久| 亚洲午夜国产一区99re久久| 一区二区三区中文字幕精品精品| 亚洲乱码国产乱码精品精的特点 | 欧美人成免费网站| 欧美日韩视频一区二区| 欧美午夜影院一区| 欧美日韩免费观看一区二区三区| 欧美在线视频全部完| 在线欧美日韩国产| 在线观看视频一区二区| 91农村精品一区二区在线| 色天天综合色天天久久| 色老汉av一区二区三区| 欧美性生活影院| 4438x亚洲最大成人网| 欧美高清一级片在线| 欧美一区二区三区视频免费播放| 91精品欧美一区二区三区综合在| 日韩一本二本av| 久久久影院官网| 国产精品久久福利| 亚洲精品水蜜桃|