디시인사이드 갤러리

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

갤러리 본문 영역

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

질문있슴다(220.149) 2010.12.02 09:11:47
조회 123 추천 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
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 끝까지 다 본 걸 후회하게 만든 용두사미 드라마는? 운영자 25/07/07 - -
AD 디지털 액세서리 기간한정 세일! 운영자 25/07/11 - -
350123 안녕하십니까 프갤형님들 좋은 밤입니다. [3] ㅎㅋㅋㅋ(59.152) 13.03.17 123 0
350122 삼성전자 소프트웨어 R&D센터 서초구에 착공했음여 [5] 수수(220.117) 13.03.17 281 0
350119 자칭 왕의 소유자 백왕님의 위치를 밝혀보자 [8] 에어로홍갤로그로 이동합니다. 13.03.17 151 0
350118 형들 개발자 커뮤니티 사이트 만들었어 평가좀요ㅠㅠ [19] ㅠㅠ우잉(203.250) 13.03.17 241 0
350114 ㅇㅇ형 파일 다 보냈어요 [4] 징기스칸4(112.140) 13.03.17 78 0
350111 ㅇㅇ형 파일 보낸거 사용법 [10] 징기스칸4(112.140) 13.03.17 141 0
350110 백왕님 마포구 사시나요? [3] 에어로홍갤로그로 이동합니다. 13.03.17 88 0
350109 웹에서 특정영역만 화면 움직일수잇게 하는법좀 [3] wefw(175.215) 13.03.17 73 0
350108 16년 전에 여자친구랑 통화할때 [10] ㅇㅇ(119.203) 13.03.17 214 0
350107 아니시발아아아ㅏ tcp인데 왜패킷이 증발하는거야 ㅅㅂㅅㅂ [3] ttp(110.47) 13.03.17 70 0
350105 ㅇㅇ형 정말 감사합니다. 통한의 눈물을흘립니다 [7] 징기스칸4(112.140) 13.03.17 143 0
350103 4명이서 할 프로젝트좀 추천해줭 [5] 미드고구마갤로그로 이동합니다. 13.03.17 113 0
350102 ㅇㅇ형 제발 제 부탁 한번만 들어주세요 [5] 징기스칸4(112.140) 13.03.17 105 0
350101 북한 네트워크 다운됨 ㅋㅋㅋㅋㅋㅋ [1] 입에붙는거갤로그로 이동합니다. 13.03.17 93 0
350099 4명이서 할 프로젝트 추천점 [2] aa(1.235) 13.03.17 58 0
350098 c언어 일차원배열 관한문제인데ㅠ [4] 으악(49.143) 13.03.17 55 0
350097 요즘 황사임? [3] LastCorona갤로그로 이동합니다. 13.03.17 41 0
350096 형님들 제발 도와주세요 이제 갓 컴퓨터 공학에 입학한 신입생인데 시작부터 [5] 입문자임니다(183.91) 13.03.17 312 0
350094 ㅇㅇ횽한테 궁금한게 한가지 있는데,, [2] ㅁㄴㅇ(211.211) 13.03.17 77 0
350093 어제 본 직무테스트에 C언어 문제가 나왔는데 [4] qwerty(118.34) 13.03.17 98 0
350092 ㅠㅠ [2] 루비•‿•갤로그로 이동합니다. 13.03.17 57 0
350091 정지 마찰력과 운동마찰력, 백래쉬(Backlash) 에 대해 [11] ㅇㅇ(119.203) 13.03.17 246 0
350090 xp 에서 JDK 안됨요? [6] asd(211.48) 13.03.17 69 0
350089 징기스칸 여기 있는것보다 네이버 크랙카페 찾아가는게 더 빠를듯 [6] adobe(124.197) 13.03.17 89 0
350088 nhn next 하고 서울게임아카데미 하고 차이가머냐 [1] 케마(116.123) 13.03.17 183 0
350087 vmware에 mac osx 설치 해 본 형들 있어? [7] mac(1.252) 13.03.17 81 0
350085 tcp 패킷이 증발한다 [7] ttp(110.47) 13.03.17 85 0
350083 이번에 삼성채용이 좀 늦자나? [8] ㅋㄱ(183.96) 13.03.17 172 0
350082 SRM 한 번 자작해보고싶다. dot(113.30) 13.03.17 41 0
350080 탈북하고 왔다. 질문받는다. [2] wefw(175.215) 13.03.17 66 0
350079 피자인증샷을 찍었는데 폰에서 사진을 어디다저장해놨는지 찾기너무어렵당 삐쭊이(39.7) 13.03.17 1527 0
350078 얼마전에 프갤에서눈팅하다 알게됀 공룡책에대해서좀알려주세요... [2] 나라용갤로그로 이동합니다. 13.03.17 84 0
350077 nhn next 저기는 1년텀으로 신입생 뽑는겨??? dd(118.221) 13.03.17 43 0
350076 어제 airwig 이 낸 문제 해설 [10] ㅇㅇ(119.203) 13.03.17 202 0
350074 아 알겠다 징기스칸4의 검은 속내를 [1] dd(1.214) 13.03.17 87 0
350073 ㅇㅇ형 제발 제 부탁 하나만 들어주시면 안될까요? [1] 징기스칸4(112.140) 13.03.17 63 0
350072 삼성전자 s직군 괜춘하나여 [7] 수수(220.117) 13.03.17 410 0
350071 c언어 300제... [2] 백이.갤로그로 이동합니다. 13.03.17 95 0
350070 ㅇㅇ성님 임베디드가 주전공임? [3] ㅇㅇ(115.41) 13.03.17 124 0
350069 싱글 게임의 제한을 깨주시면 현금 3만원 드립니다. 쉬운 크랙미 수준이래 징기스칸4갤로그로 이동합니다. 13.03.17 48 0
350068 NHN 졸업장 안나옴 가지마셈 1234124213(211.189) 13.03.17 76 0
350067 군 제대후에 nhn next 여기 준비해볼 가치있음??? [4] dd(118.221) 13.03.17 161 0
350066 C언어를 씨발 2주만에 한 권 다 떼려니까 좆도 안된다 [2] 1234(211.189) 13.03.17 98 0
350064 av신작 보는법.txt wefw(175.215) 13.03.17 41 0
350062 백이님아 [2] 2ㄷ1(175.215) 13.03.17 51 0
350060 장애인입니다...제발 피자 한 판만 시켜주십쇼... [5] 불구(211.189) 13.03.17 91 0
350059 하루에 한번.jpg [1] dd(1.214) 13.03.17 91 0
350058 니들 어제 먹은거 시켜먹어보는데, [2] ㅇㅇ(119.203) 13.03.17 91 0
350055 jquery javascript 배울필요잇냐 12e2(175.215) 13.03.17 34 0
350053 나에게 도움을 좀만주라 ㅠㅠ 개초보라그래 [3] ss(114.203) 13.03.17 48 0
뉴스 '전국노래자랑', 7/13(일) 충남 홍성군 편! 신흥 트롯황태자 김용빈 출격! 디시트렌드 07.11
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2