2007年10月25日 星期四

2007/1025 如何放置機器碼到ROM內

從PCSpim中抓取機器碼


基本上,以下的指令可以從ROM[0]開始放置


但是我們可以從指令中看到0x0c100009 jal 0x00400024 [main]
這個指令是跳躍到主程式所在ROM內執行
所以必須將主程式以後的指令放置到他所要跳躍的ROM內
從0x0c100009 jal 0x00400024 [main] 中解碼
0c100009 ==> 0000 1100 0001 0000 0000 0000 0000 1001
需要跳躍到100009轉成十進制1048585,必須將主程式放置在ROM[1048585]以後

部份程式碼如下

while(!feof(fi))
{
cf=fgetc(fi);
if (cf!='\n') i=i+1;
if ((cf=='\n')&&(k<=39)) {k=4*j-1; j=j+1;continue;} //0~35
if (k==39){
k=1048588;
j=262148; }
if ((cf=='\n')&&(k>39)) {k=4*j; j=j+1;continue;} //1048588~
if ((i%8)==1) {
printf("rom[%2d]= ",k);fprintf(fo,"rom[%d]=",k);k=k-1;}
if ( (i%8)==0 ) {
fprintf(fo,"%c;\n",cf);printf("%c;\n",cf);}
else {fprintf(fo,"%c",cf);printf("%c",cf);}
}

經過擷取與轉換後最後結果
rom[3]=10001111;
rom[2]=10100100;
rom[1]=00000000;
rom[0]=00000000;
rom[7]=00100111;
rom[6]=10100101;
rom[5]=00000000;
rom[4]=00000100;
rom[11]=00100100;
rom[10]=10100110;
rom[9]=00000000;
rom[8]=00000100;
rom[15]=00000000;
rom[14]=00000100;
rom[13]=00010000;
rom[12]=10000000;
rom[19]=00000000;
rom[18]=11000010;
rom[17]=00110000;
rom[16]=00100001;
rom[23]=00001100;
rom[22]=00010000;
rom[21]=00000000;
rom[20]=00001001;
rom[27]=00000000;
rom[26]=00000000;
rom[25]=00000000;
rom[24]=00000000;
rom[31]=00110100;
rom[30]=00000010;
rom[29]=00000000;
rom[28]=00001010;
rom[35]=00000000;
rom[34]=00000000;
rom[33]=00000000;
rom[32]=00001100;
rom[1048588]=00100111;
rom[1048587]=10111101;
rom[1048586]=11111111;
rom[1048585]=11100000;
rom[1048592]=11110111;
rom[1048591]=10111100;
rom[1048590]=00000000;
rom[1048589]=00000000;
rom[1048596]=11110111;
rom[1048595]=10111110;
rom[1048594]=00000000;
rom[1048593]=00001000;
rom[1048600]=00111100;
rom[1048599]=00000001;
rom[1048598]=00010000;
rom[1048597]=00000001;
rom[1048604]=11000100;
rom[1048603]=00111110;
rom[1048602]=00000000;
rom[1048601]=00000100;
rom[1048608]=00111100;
rom[1048607]=00000001;
rom[1048606]=00010000;
rom[1048605]=00000001;
rom[1048612]=11000100;
rom[1048611]=00111100;
rom[1048610]=00000000;
rom[1048609]=00000000;
rom[1048616]=01000110;
rom[1048615]=00011100;
rom[1048614]=11110100;
rom[1048613]=10000000;
rom[1048620]=11100111;
rom[1048619]=10110010;
rom[1048618]=00000000;
rom[1048617]=00011100;
rom[1048624]=01000110;
rom[1048623]=00011110;
rom[1048622]=11100100;
rom[1048621]=10000001;
rom[1048628]=11100111;
rom[1048627]=10110010;
rom[1048626]=00000000;
rom[1048625]=00011000;
rom[1048632]=00000000;
rom[1048631]=00000000;
rom[1048630]=00010000;
rom[1048629]=00100001;
rom[1048636]=11010111;
rom[1048635]=10111100;
rom[1048634]=00000000;
rom[1048633]=00000000;
rom[1048640]=11010111;
rom[1048639]=10111110;
rom[1048638]=00000000;
rom[1048637]=00001000;
rom[1048644]=00100111;
rom[1048643]=10111101;
rom[1048642]=00000000;
rom[1048641]=00100000;
rom[1048648]=00000011;
rom[1048647]=11100000;
rom[1048646]=00000000;
rom[1048645]=00001000;

沒有留言: