디시인사이드 갤러리

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

갤러리 본문 영역

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

질문있슴다(220.149) 2010.12.02 09:11:47
조회 122 추천 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/06/30 - -
AD 휴대폰 바꿀까? 특가 구매 찬스! 운영자 25/07/02 - -
349067 횽님들 이것좀 알려주세요 ㅠㅠ [5] 김삼디(110.9) 13.03.13 91 0
349064 지금 생각해보니깐 죤나 이해 안가는 이유가 있는것같음 [16] 야간편돌이(175.196) 13.03.13 228 0
349063 입에횽 늦었지만 올려봄;; [5] 야간편돌이(175.196) 13.03.13 109 0
349061 형들 C++너무 어려워요 도와주세요 [10] 야간편돌이(175.196) 13.03.13 428 0
349060 자라 루비•‿•갤로그로 이동합니다. 13.03.13 45 0
349058 지금까지 x86이 64bit이라고 생각하고살았음 [5] ㅁㅂ(203.241) 13.03.13 177 0
349057 형들..... 도와줘..... ㅠㅠ [12] ㅁㅂ(203.241) 13.03.13 122 0
349056 와 진짜 기분넘좋아요 ㅋㅋ 인생 3대 난제중 1개가 풀려서 ㅋㅋㅋㅋ [4] ddd(1.247) 13.03.13 199 0
349055 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ 루비•‿•갤로그로 이동합니다. 13.03.13 41 0
349054 프로그래밍하다, 코딩하다 이거두개 차이가뭐임? [9] ㅂㄷㅈㅈ(175.215) 13.03.13 275 0
349053 프갤형님들 정말 고맙습니다 열심히 공부하겠습니다ㅠㅠ [6] ddd(1.247) 13.03.13 105 0
349051 형들 1차원배열 공부하는중인데 뭐가 잘못됬는지 모르겠어요 [5] 늅늅(220.117) 13.03.13 100 0
349048 아 심심타. fm100(220.76) 13.03.13 42 0
349047 RGB 봐라 [18] 골쿵갤로그로 이동합니다. 13.03.13 178 0
349046 참 프로그래밍 모르겠네요 ㅠㅠ [1] 신입뉴비(115.126) 13.03.13 107 0
349044 아둔한 프로그래머가 이상한 도움을 요청한다!!! [7] LastCorona갤로그로 이동합니다. 13.03.13 156 0
349038 전산 병특 준비하는데 얼마나 걸릴까요? [6] 반헤일런갤로그로 이동합니다. 13.03.12 102 0
349037 아까 그거에 영어자막 달았음... 분당살람갤로그로 이동합니다. 13.03.12 42 0
349036 예전에 피쳐폰 프로그래밍 말야. [5] f(211.196) 13.03.12 169 0
349035 scanf입력받을때 한글자씩만 [5] 개발손(110.47) 13.03.12 105 0
349032 알바생 시급 만원 보장되야 합니다 [9] 에어로홍갤로그로 이동합니다. 13.03.12 108 0
349031 우리학교 1학년 과목인데 [2] aaaa(121.129) 13.03.12 96 0
349028 인생이 걸린 질문입니다 카투사 vs 병특 [24] 반헤일런갤로그로 이동합니다. 13.03.12 385 0
349024 쥐꼬리만큼 알고나니까 고민이생긴다 Firefish(110.15) 13.03.12 44 0
349023 모바일웹앱 php 데이터 목록 자르기 질문 [2] 햄버거11(124.49) 13.03.12 65 0
349022 이클립스 쓰다 비쥬얼 스튜디오쓰니까 지옥 [4] 개발손(110.47) 13.03.12 156 0
349020 얼래 하청기업일수록 낮에 근무하는 사람이 멍청함? [1] ㅇㅇ(1.214) 13.03.12 92 0
349019 춘곤증인가 백이(182.214) 13.03.12 29 0
349018 영어 공부만 하면 길이 활짝 열리는데 그 걸 못하냐?!! [3] 멍청닭(203.149) 13.03.12 123 0
349017 직장인인데 퀵소트 20분만에 못짜면 자살해라 [4] asdasd(112.172) 13.03.12 196 0
349015 오늘부터 헬스 다닌다 [4] 멍청닭(203.149) 13.03.12 82 0
349013 형님들 파일구조 넘 어렵네용 [3] ㅎㅋㅋㅋ(59.152) 13.03.12 119 0
349011 티맥스 사람들은 9시에도 퇴근안하네 [2] ㅁㅇㄴㅁㅇㄴ(59.11) 13.03.12 129 0
349009 어셈블리 한국어책 공룡책스러운책 있음? [1] 나리링갤로그로 이동합니다. 13.03.12 97 0
349008 codesafer님 프갤러 맞으신가요? ㅠㅠ 1149번 도움좀 주세요 ㅠ [1] ddd(222.114) 13.03.12 98 0
349007 내가 진짜 유용한 팁 가르쳐주지 에어로홍갤로그로 이동합니다. 13.03.12 53 0
349005 라즈베리파이 쓰는사람있나? [1] Margin Call갤로그로 이동합니다. 13.03.12 82 0
349004 오늘 회사에서 한일.. [2] ㅋㄱ(183.96) 13.03.12 113 0
349003 프로그래밍하는게 즐겁고 재밌으면 적성에맞는거임? [1] ㅂㄷㅈㅈ(175.215) 13.03.12 64 0
348999 안드로이드개발 강좌같은거 있는 포럼이나 카페같은데 좋은데없음? [1] ㄴㅅㄴ(222.233) 13.03.12 49 0
348998 연봉 1억 받는 개발자 인증해라. [1] ㅇㅇ(115.41) 13.03.12 117 0
348996 jdk 깔아서 cmd 로만 돌릴때exe파일 만드는법좀 알려주세옹 [3] 121(175.122) 13.03.12 76 0
348995 컴공이랑 컴과학과는 무슨차이냐 [7] 닉네임병맛갤로그로 이동합니다. 13.03.12 193 0
348994 새로 생긴 벌금 목록 [2] 멍청닭(182.211) 13.03.12 145 0
348993 새로 생긴 벌금들이다 숙지하도록 해 멍청닭(182.211) 13.03.12 56 0
348992 오늘의 명언 모음 [1] 멍청닭(182.211) 13.03.12 89 1
348991 더블포인터때문에 그러는데 이거좀 봐줘 [8] 으아(218.156) 13.03.12 112 0
348990 타이젠 언제출시됨? (211.237) 13.03.12 38 0
348989 개나소나 하는게 프로그래밍이지 씨 발 [2] asdasd(1.209) 13.03.12 117 0
348987 20대 후반인데 연봉 4천만원 이하인새 끼들은 자살해라 [8] asdasd(1.209) 13.03.12 264 0
뉴스 워터밤 여신 권은비, 베일듯한 콧날의 인형 비주얼 + 섹시한 볼륨감 몸매까지... 디시트렌드 07.03
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2