디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

이 오류 어떻게 처리하는 지 좀 알려주세요

질문있슴다(220.149) 2010.12.02 09:11:47
조회 116 추천 0 댓글 4

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>

struct reg{
char reg_name[3];
char reg_num[4];
}Reg[20];//레지스터에 대한 이름과 번호를 저장하는 구조체

struct ins{
char instruct[6];
char dest[2];
char sour[2];
char word_type[2];
char ins_code[3];
char ins_len[2];
char mod_reg[9];
}Instr[100];//각 인스트럭션의 정보를 보관하는 구조체
int MaxI;

struct symbol_tbl{
char symbol[10];
char word_type[2];
int lc;
char data[10];
}Symbol[30];//심볼테이블
int MaxS;

struct sentence{
char label[10];
char _operator[10];
char operand[3][10];
}Sen;
int LC;

//화일에서 레지스터와 인스트럭션의 정보를 읽는다
void Initialize()
{
int i=0,j=1;
FILE *regi,*inst;

regi=fopen("reg.tbl","r");
inst=fopen("inst.tbl","r");
while(!feof(regi)){
fscanf(regi,"%s %s\\n",Reg[i].reg_name,Reg[i].reg_num);
i++;
}//레지스터 테이블을 작성한다
while(!feof(inst)){

fscanf(inst,"%6s%2s%2s%4s%3s%2s%9s\\n",
Instr[j].instruct,
Instr[j].dest,
Instr[j].sour,
Instr[j].word_type,
Instr[j].ins_code,
Instr[j].ins_len,
Instr[j].mod_reg);
j++;
}//명령어 테이블을 작성한다
MaxI=j-1;
fclose(regi);
fclose(inst);
}

int Analyze(char *operand)
{
int i=0;
char *regist[]={"AX","BX","CX","DX","AL","BL","CL","DL","AH","BH","CH","DH",0x00};//레지스터의 이름을 저장

if(isdigit(operand[0])) return 0;

else
while(regist[i]!=0x00)
if(!strcmp(operand,regist[i])){
if(i<4)
return 1;
else
return 2;
}
else i++;
return 3;
}
#define MAX_INS 1//명령어의 최대 개수를 지정

int Add_Chk(char *sen)
{
register k=MaxI;
int i=0,j=0,l=0,wp=0;
char op[5][10],*opcode[]={"mov",""};

while(sen[wp]!=\'\\n\'){
while(sen[wp]==\' \'||sen[wp]==\'\\t\'||sen[wp]==\',\')
wp++;
while(sen[wp]!=\' \'&&sen[wp]!=\'\\t\'&&sen[wp]!=\'\\n\'&&sen[wp]!=\',\'){
*(op[j]+i)=sen[wp];
i++;
wp++;
}
*(op[j]+i)=\'\\0\';
i=0;
j++;
}
i=0;
while(strcmp(opcode[i],""))
if(stricmp(opcode[i],op[0]))
i++;
else{
strcpy(Sen._operator,op[0]);
for(l=1;l<j;l++)
strcpy(Sen.operand[l-1],op[l]);
break;
}
if(i==MAX_INS){
strcpy(Sen.label,op[0]);
strcpy(Sen._operator,op[1]);
for(l=2;l<j;l++) strcpy(Sen.operand[l-2],op[l]);
}
strcpy(Instr[0].instruct,op[0]);
switch(Analyze(op[1])){
case 0: strcpy(Instr[0].dest,"i");
break;
case 1: strcpy(Instr[0].dest,"r");
strcpy(Instr[0].word_type,"w");
break;
case 2: strcpy(Instr[0].dest,"r");
strcpy(Instr[0].word_type,"b");
break;
case 3: strcpy(Instr[0].dest,"m");
break;
}
switch(Analyze(op[2])){
case 0: strcpy(Instr[0].sour,"i");
break;
case 1: strcpy(Instr[0].sour,"r");
strcpy(Instr[0].word_type,"w");
break;
case 2: strcpy(Instr[0].sour,"r");
strcpy(Instr[0].word_type,"b");
break;
case 3: strcpy(Instr[0].sour,"m");
break;
}

while(stricmp(Instr[k].instruct,Instr[0].instruct)||strcmp(Instr[k].dest,Instr[0].dest)||strcmp(Instr[k].sour,Instr[0].sour)||strcmp(Instr[k].word_type,Instr[0].word_type))
k--;
return k;
}

void PassI(char *buf)
{
int i;
static int j=0;
i=Add_Chk(buf);
if(i){
printf("%04X: %s",LC,buf);
LC+=atoi(Instr[i].ins_len);
}
else{
if(!stricmp(Sen._operator,"dw"))
strcpy(Symbol[j].word_type,"w");
else if(!stricmp(Sen._operator,"db"))
strcpy(Symbol[j].word_type,"b");
strcpy(Symbol[j].symbol,Sen.label);
strcpy(Symbol[j].data,Sen.operand[0]);
Symbol[j].lc=LC;
printf("%04X: %s",LC,buf);
if(*Symbol[j].word_type == \'w\')
LC+=2;
else if(*Symbol[j].word_type == \'b\')
LC+=1;
j++;
}
}
int btoi(char *dig)
{
register i=0,ret =0;


while(*(dig+i)!=\'\\0\'){
if(*(dig+i)==\'1\')
ret+=pow(2,strlen(dig+i)-1);
i++;
}
return ret;
}
void PassII(char *buf)
{
int i,j=0,k=0;

i=Add_Chk(buf);
if(i){
printf("%04x: %03s",LC,Instr[i].ins_code);
if(!strcmp(Instr[i].dest,"r")){
while(stricmp(Reg[j].reg_name,Sen.operand[0]))
j++;
strncpy(strchr(Instr[i].mod_reg,\'?\'),Reg[j].reg_num,3);
}
j=0;
if(!strcmp(Instr[i].sour,"r")){
while(stricmp(Reg[j].reg_name,Sen.operand[1]))
j++;
strncpy(strchr(Instr[i].mod_reg,\'?\'),Reg[j].reg_num,3);
}
if(strcmp(Instr[i].dest,"m")&&strcmp(Instr[i].sour,"m"))
printf("%02X %s",btoi(Instr[i].mod_reg),buf);
else{
if(!strcmp(Instr[i].dest,"m"))
while(strcmp(Symbol[k].symbol,Sen.operand[0]))
k++;
else if(!strcmp(Instr[i].sour,"m"))
while(strcmp(Symbol[k].symbol,Sen.operand[1]))
k++;
printf("%02X %04X %s",btoi(Instr[i].mod_reg),Symbol[k].lc,buf);
}
LC+=atoi(Instr[i].ins_len);
}
else{
k=0;
while(strcmp(Symbol[k].symbol,Sen.label))
k++;
if(!strcmp(Symbol[k].word_type,"w"))
printf("%04X:%04X %20s",LC,atoi(Symbol[k].data),buf);
if(!strcmp(Symbol[k].word_type,"b"))
printf("%04X:%20X %20s",LC,atoi(Symbol[k].data),buf);
if(*Symbol[k].word_type == \'w\') 
LC+=2;
else if(*Symbol[k].word_type == \'b\')
LC+=1;
}
}

void main()
{
char buf[50];
FILE *in;

in=fopen("test1.asm","r");
Initialize();
printf("\\nPass1:\\n");
while(1){
fgets(buf,30,in);
if(feof(in))
break;
PassI(buf);
}
rewind(in);
LC=0;
printf("\\nPass2:\\n");
while(1){
fgets(buf,30,in);
if(feof(in))
break;
PassII(buf);
}
fclose(in);
}

복사 붙여넣기햇더니 탭되어있던거 다 사라졌네;;

굵은 표시한 부분에

warning C4244: \'+=\' : conversion from \'double \' to \'int \', possible loss of data

에러 나는데 왜 이럴까요

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
등록순정렬 기준선택
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 연예인 안됐으면 어쩔 뻔, 누가 봐도 천상 연예인은? 운영자 24/06/17 - -
235535 헤헤. 형들은 이런 동생 있어? [2] SODmaster갤로그로 이동합니다. 11.02.22 102 0
235533 김상형저자가 쓰신 api정복에서 다 좋은데 한가지 [3] ㅋㅋ(220.120) 11.02.21 182 0
235532 웹백신이라는 걸 만들 수 있을까?? [2] SODmaster갤로그로 이동합니다. 11.02.21 109 0
235531 형들 이거 좀 보래요 ㅋㅋㅋㅋㅋ [7] 할리의본링갤로그로 이동합니다. 11.02.21 131 0
235530 어제 서울 코믹 다녀왔는데 [7] 아주아슬갤로그로 이동합니다. 11.02.21 175 0
235529 자바는 플렛폼에 자유로운 언어라고 한다. [2] 생각놀이갤로그로 이동합니다. 11.02.21 168 0
235528 MFC를 익히고 싶은데요 [5] 금고래갤로그로 이동합니다. 11.02.21 140 0
235527 풋고추 존나 잘생겼다 (냉無) 김늅늅(175.198) 11.02.21 124 0
235526 그나저나 나의 추종자가 생긴 모양이군.... [1] 땡칠도사갤로그로 이동합니다. 11.02.21 87 0
235525 c언어 extern 안써줘도 죄다 호출 된다는거 오늘 처음암. [3] rr(116.45) 11.02.21 346 0
235524 금융.... [9] 꼬꼬마질문..(59.15) 11.02.21 146 0
235522 웬지 이바보님을 사랑할거같다 [3] 풋고추(112.148) 11.02.21 133 0
235520 야심한 밤 갑자기 쿼터파운드 버거가 땡긴다 [6] 계백(61.255) 11.02.21 92 1
235517 후후 더블릿 저번에 프개럴들한테 클리닉받은 뒤로.. [2] 뇌자알(220.69) 11.02.21 102 0
235516 좍이님 소환. [4] Ynobe갤로그로 이동합니다. 11.02.21 77 0
235514 게임프로그래머가 고급스킬을 요구하는 개발자인가요?????????? [7] ㅁㄴㅇ(121.162) 11.02.21 274 0
235513 이바보 여자야 이것들아. 글싸는거 보면 모름? [4] 계백(61.255) 11.02.21 123 0
235512 앞면 얼굴 투척하고 c언어 하러감요 ㅋ [8] 풋고추(112.148) 11.02.21 163 0
235511 머리 잘랐는데 위가 괜찮나요 아래가 괜찮나요 [4] 풋고추(112.148) 11.02.21 106 0
235510 비즈폼트레이드 같은 사이트 더 업나? [4] 할리의본링갤로그로 이동합니다. 11.02.21 428 0
235509 이바보 님 [5] 첫사랑(112.148) 11.02.21 69 0
235508 도와주십시오 컴퓨터사운드쪽 처리잘하시는분 사례금드리겟습니다 [3] 조남희(116.32) 11.02.21 132 0
235507 형들 이것좀 봐줘. [1] 풋고추(183.105) 11.02.21 62 0
235506 내 첫사랑 썰 풀어봄...txt [4] 첫라앙(112.148) 11.02.21 119 0
235504 메모리매핑파일 질문좀. [3] ㅇㅇ(211.117) 11.02.21 110 0
235503 대학교 학사 이후 진학을 하는게 좋겠나요? [5] 11학번~(59.27) 11.02.21 132 0
235501 솔까말 인맥 제로면 학원인맥도 괜찮아 [2] 계백(61.255) 11.02.21 189 0
235500 시간이 넘쳐나면 독학을 하겠죠 학원을 왜다님?? [3] 쿄스케갤로그로 이동합니다. 11.02.21 166 0
235499 돈 넘쳐나고 시간넘쳐나면 학원 다녀 [5] 계백(61.255) 11.02.21 161 0
235497 어설프게 학원다녀서 취업할쉑이들은 걍 웹퍼나 해 [3] 계백(61.255) 11.02.21 302 0
235496 미친척하고 art of computer programming 전3권 지름 [7] asdfs(180.65) 11.02.21 152 0
235495 도대체 gvim으로 새로만들기 어케 하는거임?? [8] 마우슼(175.116) 11.02.21 131 0
235494 형님들 궁금합니다!! [2] 말숡(222.98) 11.02.21 85 0
235493 제가 비트교육센터를 다니려구 하는데용.. [9] ㅋ-ㅋ(222.106) 11.02.21 284 0
235492 혹시 QT하는 횽 있음? [2] AFV CLUB(115.138) 11.02.21 137 0
235491 세마포어랑 모니터랑 뭐가 다른지 정확히좀 알려주실분 있나요ㅠㅠ [2] dddd(203.246) 11.02.21 1387 5
235490 병특 면접 가면 뭐 물어보나여 [9] Ynobe갤로그로 이동합니다. 11.02.21 157 0
235489 이바보오빠는 아얄 안해요? [4] elwlwlwk갤로그로 이동합니다. 11.02.21 111 0
235487 플밍갤에 이거 가는사람있음 ? [5] ㄷㅈ(121.88) 11.02.21 123 0
235485 디씨 메신저 개발할라구 [12] 계백(61.255) 11.02.21 198 0
235483 예전에 검색엔진 회사 다닐 때 고객이 항상 하는 요구가... [3] 물속의다이아갤로그로 이동합니다. 11.02.21 204 0
235482 Flex에서 다수 파일 다운로드 할 수 있는 방법 없어? [3] 쇼키(112.136) 11.02.21 144 0
235481 횽들 전국일주 컨셉을 정했는데 [10] 미클갤로그로 이동합니다. 11.02.21 144 0
235480 밑에 게시판 새글 알리미 [4] 윗휴갤로그로 이동합니다. 11.02.21 166 0
235479 이바보 소환!! [9] 시계태엽갤로그로 이동합니다. 11.02.21 92 0
235478 컴파일러 어렵나여 ㅎㄷㄷ [5] 116.44(116.44) 11.02.21 124 0
235475 MFC나 C++, C 쪽 연봉이... [5] ㅇㅇ(118.36) 11.02.21 312 0
235474 여행 같이 가실 남자분~ [7] 미클갤로그로 이동합니다. 11.02.21 184 0
235473 정보 보안 공부하는데 텍스트북 추천 좀 [2] 구루구루(115.145) 11.02.21 111 0
235472 이바보님 실례를 무릅쓰고 여쭤 볼게요 [6] 미클갤로그로 이동합니다. 11.02.21 171 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2