디시인사이드 갤러리

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

갤러리 본문 영역

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

질문있슴다(220.149) 2010.12.02 09:11:47
조회 124 추천 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/14 - -
AD 디지털 액세서리 기간한정 세일! 운영자 25/07/11 - -
350758 dns 도메인 관련 [4] 난쟁이오크갤로그로 이동합니다. 13.03.20 75 0
350757 바야바 봤던 기억이 가물 가물 나는데. [3] ☎2.52™갤로그로 이동합니다. 13.03.20 80 0
350756 구현에 관심 없고 설계만 좋아하는 경우는 없나? [2] 토페갤로그로 이동합니다. 13.03.20 97 0
350755 아쉬파 애드센스로 부업 6개월간 목표 월 100으로 잡고 시작햇는데 [7] 얼룩돼지갤로그로 이동합니다. 13.03.20 153 0
350754 프갤에 늙다리 고수가 출현했다는게 레알? [5] 얼룩돼지갤로그로 이동합니다. 13.03.20 144 0
350751 유닉스랑 리눅스랑 쉘 스크립트는 똑같음? [5] 543543갤로그로 이동합니다. 13.03.20 121 0
350750 웹에서 소켓 제대로 구현하려면 플래시 말고 대안 없지? [9] ㅇㅇ(180.231) 13.03.20 178 0
350749 얘들아 이네모난박스 보면 모가생각나냐 [9] ㅋㄹ(223.62) 13.03.20 128 0
350744 프로그래머 전망이 어떠냐? [13] 리에갤로그로 이동합니다. 13.03.20 401 0
350742 님드라 컴퓨터는 언제쯤 01에서 벗어나나여?? [2] ?(175.203) 13.03.20 102 0
350739 진지한 진로고민.. [4] ㅇㅇ(14.32) 13.03.20 174 0
350738 맵리듀스랑 하둡을 공부하기위한 사이트가 어디있음? [1] 나리링갤로그로 이동합니다. 13.03.20 93 0
350737 XNA에서 3D 모션넣고 싶을때.... ㅁㅁㅁ(112.214) 13.03.20 36 0
350735 프갤형님들 프로그램배우면 취직되나요? [2] (175.114) 13.03.20 58 0
350734 하시는 말마다 명언.jpg [2] (1.214) 13.03.20 222 0
350733 이것도 간단한가여? ㅇㅇ(121.174) 13.03.20 50 0
350731 코드세이퍼 횽아~ 바야바 횽아 알어? [17] BabysBreath(175.121) 13.03.20 191 0
350730 CPU 양자 터널링 효과 - 현재는 신경 쓸 정도까진 아닌가요? [5] (211.196) 13.03.20 476 0
350729 씨발 ! 드디어 됬다! [1] go2(175.215) 13.03.20 69 0
350728 근데 이실력으로 회사들어간다 ㅋㅋㅋㅋㅋㅋㅋㅋ ㅇㅇ(121.174) 13.03.20 188 0
350727 심심하면 무료 지능검사 [1] ㅁㄴㅇ(1.245) 13.03.20 79 0
350726 조공과 함께 질문 - 회로에 대해서 [11] (211.196) 13.03.20 150 0
350724 오오 차칸 프갤러들 ㅠㅠ [5] ㅇㅇ(121.174) 13.03.20 137 0
350722 제가 오늘 거금을 쓰려합니다. [4] 야간편돌이(175.196) 13.03.20 81 0
350721 dot형 자나요. [4] ㅇㅇ(115.41) 13.03.20 50 0
350720 아까 lisp 물어본 놈인데 저거 말고 친절하게 설명해주면 안되냐 ㅇㅇ(110.12) 13.03.20 43 0
350719 플밍기초공부중인데 도저히 못풀겠다 ㅠㅠ [8] ㅇㅇ(121.174) 13.03.20 170 0
350717 지금 로지아 따라부르다간 [3] LastCorona갤로그로 이동합니다. 13.03.20 60 0
350716 일본노래 하니까 생각나는데... [16] LastCorona갤로그로 이동합니다. 13.03.20 120 0
350714 잠을 줄이는게 가능한가요 [11] (1.214) 13.03.20 124 0
350713 몇일전에 속도 비교 질문 올렸었는데요 다른질문 한개만더... [6] ㅅㅌㅇ(175.214) 13.03.20 101 0
350712 C++ 왜이리어렵냐 C++갤로그로 이동합니다. 13.03.20 48 0
350711 캐논변주곡-임정현 백이.갤로그로 이동합니다. 13.03.20 41 0
350710 벼래별 넘들이 다있구나... ㅁㄴㅇㄹ(182.208) 13.03.20 54 0
350709 프로그래머도 공업수학함?? ㅁㄴㅇ(1.245) 13.03.20 111 0
350708 기타하니까 생각났는데 [3] 백이.갤로그로 이동합니다. 13.03.20 63 0
350706 것보다 VC는 한글이 왜안되는거지 개빡치네 [2] 백이.갤로그로 이동합니다. 13.03.20 49 0
350705 듣고 정화하시죠 [3] 백이.갤로그로 이동합니다. 13.03.20 70 0
350704 과부하 걸리는데 [3] (211.196) 13.03.20 36 0
350701 화일처리 관련된 책 추천좀 부탁드립니다;; 신입뉴비(115.126) 13.03.20 33 0
350699 저 남잔데 컴퓨터 잘하는 사람들 보면 너무 섹시해 보임;; 앞잠금갤로그로 이동합니다. 13.03.20 57 0
350698 나도 성공하면 피자쏨 백이.갤로그로 이동합니다. 13.03.20 32 0
350696 님들아 저성공하면 피자함쏠게여 [3] go2갤로그로 이동합니다. 13.03.20 61 0
350695 개새끼들아 비쥬얼베이직6 몇일하면 마스터하냐고 [9] 앞잠금갤로그로 이동합니다. 13.03.20 118 0
350693 횽들 비쥬얼베이직6도 이 갤에서 얘기하면 되는거임? [6] 앞잠금갤로그로 이동합니다. 13.03.20 69 0
350689 카즈야님 해결함 ㅎㅎ [2] 야간편돌이(175.196) 13.03.20 42 0
350687 lisp 코드 저장좀 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ ㅇㅇ(110.12) 13.03.19 49 0
350686 오늘도 유통기한 지난 바나나우유를 먹는다. [6] 야간편돌이(175.196) 13.03.19 70 0
350685 요즘 열심히 C++ 배우는 초짜인데 [16] 쿠모링갤로그로 이동합니다. 13.03.19 186 0
350684 웹페이지 열떄 갑자기 하얗게 되는 현상 [3] ㄹㄹ(211.196) 13.03.19 57 0
뉴스 양세형, 부정행위로 한식조리사 2번째 시험 ‘탈락’ 디시트렌드 07.12
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2