디시인사이드 갤러리

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

갤러리 본문 영역

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

질문있슴다(220.149) 2010.12.02 09:11:47
조회 120 추천 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/09/23 - -
267327 형들 1학기때 배운 sql이랑 html로 사이트 만들어봄.. [2] 점술가2갤로그로 이동합니다. 11.08.27 96 0
267326 대구육상선수권대회 개막식이 너무 저렴한듯... 컴돌이(180.227) 11.08.27 75 0
267325 너님들 외모에 투자해라 [2] 분당살람갤로그로 이동합니다. 11.08.27 104 0
267323 http://android-opencv.googlecode.com/svn ㅁㄴㅇㄹ(115.137) 11.08.27 107 0
267322 너님들아 외모에 투자해라 (119.149) 11.08.27 59 0
267321 일본의 어긋난 창의력 [2] ㅇㅇ(61.77) 11.08.27 109 0
267320 자료구조 공부해서 모하냐 ㅋㅋㅋ [3] 약초식남(219.251) 11.08.27 139 0
267319 안드로이드 opencv 해보신분 한번만 도와주세요 ㅠㅠ 제발 ㅠㅠ ㅁㄴㅇㄹ(115.137) 11.08.27 55 0
267318 라이언을 깔았다 [3] ㄹㅇㄴㅁㄹㅈ(211.109) 11.08.27 69 0
267317 도와주세요 확장자 병1신됨 ㅜㅜ [7] ㅁㄴㅇ(123.109) 11.08.27 145 0
267316 void call(int count) 겜프로그래밍(111.118) 11.08.27 45 0
267314 이쯤에서 실력이 뭔지 알려주마. [7] 개발자(115.23) 11.08.27 207 0
267313 님들 실전들어가면 비주얼 씨쁘쁠 같은 컴파이러 사용안하나요? [1] 김씨발(223.222) 11.08.27 68 0
267311 삼성,LG 태생이 장사꾼 기업인데 sw에 대해 몰알겠냐 ㅋㅋㅋ 약초식남(219.251) 11.08.27 59 0
267310 왜 한국 IT는 엔지니어와 테크니션의 구분이 없는거냐? [4] (118.176) 11.08.27 303 0
267308 파포 잘하시는분.ㅠㅠㅠㅠ [2] 슈퍼주니없갤로그로 이동합니다. 11.08.27 55 0
267307 대한민국 백엔드에 경쟁력따윈 애시당초 없었던 거다. 약초식남(219.251) 11.08.27 54 0
267306 공시)징징에서 약초식남으로 닉을 변경함을 공시함. [1] 약초식남(219.251) 11.08.27 59 0
267305 2014년에 html5 표준이 정해진다. 미리미리 준비해서 취업준비해라. [2] 징징(219.251) 11.08.27 152 0
267304 머리가 좋아질려면 평소 운동을 하라. [5] 징징(219.251) 11.08.27 124 0
267303 ┌ 빅맥 삼성 세트, NHN 웹퍼 세트, SI을고기 버거 세트 [4] ㅇㅇ(222.107) 11.08.27 125 0
267302 소인배.jpg ㅇㅇ(222.107) 11.08.27 129 0
267301 127.0.0.1 의 의문 [8] 천재해커(175.196) 11.08.27 188 0
267300 님들 군인임 [2] 면섬유갤로그로 이동합니다. 11.08.27 76 0
267299 아 그만 퇴근해버릴까.. [1] blackd갤로그로 이동합니다. 11.08.27 84 0
267298 고졸들 nhn학원들어갈대 수능점수 제출하냐? ㅋㅋㅋ [4] 징징(219.251) 11.08.27 238 0
267297 아웃사이더들은 개발일이랑 안맞나 [4] ㅇㅇ(61.77) 11.08.27 106 0
267296 nhn의 행동이 이해가 간다 [3] 분당살람갤로그로 이동합니다. 11.08.27 235 0
267295 IOS개발, C C++ 오브젝티브-C 다 배워야 하나요? [18] 4학년(122.108) 11.08.27 258 0
267291 nhn학원의 학비는 연간 천만원 [3] ㅇㅇ(61.77) 11.08.27 288 0
267290 형들 C언어 어려워? 나 프로그래머 되려고 하는데... y녀6디리(218.146) 11.08.27 64 0
267289 횽들 나 새내기 대학생인데 프로그래밍 공부말이야~ [6] 미쥬마루갤로그로 이동합니다. 11.08.27 146 0
267288 학사출신이 nhn 학원가면 제대로 호구 인증 [2] 징징(219.251) 11.08.27 236 0
267287 이런회사에서 일하면 야근도 재미있을거같아 [4] ㅇㅇ(61.77) 11.08.27 163 0
267286 [C++] 객체의 모든 메서드가 객체 내부의 상태를 바꾼다면... [2] 궁금이(121.129) 11.08.27 71 0
267285 여성 프로그래머라... 상상만 해도 부왘!!! [10] 천재해커(175.196) 11.08.27 311 0
267284 spring framework 라고 들어나 봤냐? ㅄ드라 [8] 징징(219.251) 11.08.27 111 0
267283 배고프다 ㅠㅜ... 뭘 먹어야지 맛있을까? [3] 쿄스케갤로그로 이동합니다. 11.08.27 45 0
267281 구글에서 보내온 메일인데 [5] 야갤러(59.187) 11.08.27 191 0
267280 지금 회사에서도 그녀 처럼 독특한 캐릭 여자애가 하나 있긴 해. [4] 물속의다이아(211.49) 11.08.27 130 0
267277 얘들아... [4] 물속의다이아(211.49) 11.08.27 89 0
267275 후움 열심히 해볼려고 회사 나온건데.. [2] blackd갤로그로 이동합니다. 11.08.27 100 0
267274 프로그래밍 공부하는 사람치고 내 닉넴 모르면 [7] dijkstra(222.233) 11.08.27 142 0
267273 페르마 진짜 간지나지 않냐? [3] blackd갤로그로 이동합니다. 11.08.27 142 0
267270 횽들 박사학위따서 교수하는건 어떰? [14] Ing여(110.13) 11.08.27 247 0
267268 형들 질문! [4] 초보(126.10) 11.08.27 72 0
267267 애시당초 처음접하는 언어로 C#이 어떨까 하는 생각이 들어여 [4] dijkstra(222.233) 11.08.27 122 0
267265 클린턴 전 대통령이 회고록에서 발킨 바에 따르면 [1] 분당살람갤로그로 이동합니다. 11.08.27 49 0
267264 천재해커처럼 해커가 되고 싶은 늅늅이들은 봐라. [7] 천재해커(175.196) 11.08.27 213 0
267263 프로그래밍에 흥미가 있어서 [9] ㅇㅇㅇ(123.111) 11.08.27 117 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2