C++공부하는 학생입니다 어셈블리 기능을 구현하는 프로그램을 작성하는데 질문좀 드릴께요 ㅠㅠ

ind6450의 이미지

우선 텍스트 파일로 불러온 명령어가 있습니다.
(심볼/ 명령어/ 주소 ) 순서입니다... 예를들어
----------------------------------
ORG 100
LDA ADS
LDA NBR
STA CTR
CLA
LOP, ADD PTR I
ISZ PTR
ISZ CTR
BUN LOP
DTA SUM
HLT
ADS, HEX 150
PTR, HEX 0
NBR, DEL -100
CTR, HEX 0
SUM, HEX 0
ORG 150
DEC 75
END
----------------------------------

이런식의 텍스트 파일을 불러오면

ORG는 주소 100번지부터 시작하라는 의미의 명령어이고
100 LDA ADS 0010 0001 0000 0101
LDA NBR 0011 0001 0000 1011
STA CTR 0010 0001 0000 1100
CLA 0111 0100 0000 0000
LOP, ADD PTR I 1001 0001 0000 1011

이런식의 결과값을 출력해야 하는데요...
간단히 말씀드리면 텍스트 파일로 불러온 16진수로된 명령어들을 기계어인 2진수로 출력하는 프로그램입니다 ...

워낙 초짜라 엄청 무식한 방법으로 하고 있는데 불러온 값들을 어떻게 이진수로 바꿔야 할지를 에서 해매고 있습니다 ㅠㅠ
길을 알려주세요....
아래는 제가 현제까지 해본 코딩입니당 ㅠㅠ 보고 욕하지 말아주세요 ㅠㅠㅠ

//////////////////////////////////////////////////////// CODING ///////////////////////////////////////////////////////////////////////////

#include
#include
#include
#include

using namespace std;

int Assembly(char *as);
int Display(char *dis);

int main()
{
char Buffer[100];
char n;

for(;;)
{
cout cout

cin>>n;

if(n == '1')
{
Assembly((char *)Buffer);
}
else if(n == '2')
{
Display((char *)Buffer);

//break;
}
else
{
cout }
}

return 0;

}

int Assembly(char *as)
{
ifstream inputFile("assembly.txt");

if(!inputFile)
{
cout return 1;
}

cout cout

while(!inputFile.eof())
{
inputFile.getline(as, 100);
//cout

Display(as);
}
inputFile.close();

cout cout cout return 0;
}

int Display(char *assemblyLine)
{
//cout char code;
cout //cout char AND = 0000;
char ADD = 0001;
char LDA = 0002;
char STA = 0003;
char BUN = 0004;
char BSA = 0005;
char ISZ = 0006;
char CLA = 7800;
char CLE = 7400;
char CMA = 7200;
char CME = 7100;
char CIR = 7080;
char CIL = 7040;
char INC = 7020;
char SPA = 7010;
char SNA = 7008;
char SZA = 7004;
char SZE = 7002;
char HLT = 7001;
int F800 = 1111100000000000;
char INP = F800;
int F400 = 1111010000000000;
char OUT = F400;
int F200 = 1111001000000000;
char SKI = F200;
int F100 = 1111000100000000;
char SKO = F100;
int F080 = 1111000001000000;
char ION = F080;
int F040 = 1111000001000000;
char IOF = F040;

//code=assemblyLine;

for(int i=0; i {
code=assemblyLine[i];
//cout

/*if(code==AND)
{
if(I==1)
{
cout }
else
{
cout }
}

else if(code==ADD)
{
if(I==1)
{
cout }
else
{
cout }
}

else if(code==LDA)
{
if(I==1)
{
cout }
else
{
cout }
}

else if(code==STA)
{
if(I==1)
{
cout }
else
{
cout }
}

else if(code==BUN)
{
if(I==1)
{
cout }
else
{
cout }
}

else if(code==ISZ)
{
if(I==1)
{
cout }
else
{
cout }
}*/

if(code==CLA)
{
cout }

else if(code==CLE)
{
cout }

else if(code==CMA)
{
cout }

else if(code==CME)
{
cout }

else if(code==CIR)
{
cout }

else if(code==CIL)
{
cout }

else if(code==INC)
{
cout }

else if(code==SPA)
{
cout }

else if(code==SNA)
{
cout }

else if(code==SZA)
{
cout }

else if(code==SZE)
{
cout }

else if(code==HLT)
{
cout }

else if(code==INP)
{
cout }

else if(code==OUT)
{
cout }

else if(code==SKI)
{
cout }

else if(code==SKO)
{
cout }

else if(code==ION)
{
cout }

else if(code==IOF)
{
cout }

}

return 0;
}

/*int Coding(char *str)
{
int number[200]
int
*/

mirheekl의 이미지

http://www.cplusplus.com/reference/cstdlib/itoa/

베이스를 2로 주시면 됩니다. stdlib 펑션을 써도 되는지 교수님께 여쭤보세요. 2진 변환과정을 꼭 연습해야 한다면 아마 안된다 하시겠지만.. 그런경우에는 배우신대로 직접 itoa와 같은 동작을 하는 펑션을 구현하시면 됩니다. 이미 배우셨겠지만 혹시 기억이 안 나시면.. http://math88.com.ne.kr/crypto/isan/jinbup.html 이런거 보시고 참고하시면..

--

익명 사용자의 이미지

우선 답변 감사드립니다!
텍스트에서 불러온 명령어가 문자인데 저걸 숫자로 번저 바꾸고나서 2진수로 나타내야 할것 같은데
텍스트에서 불러온 값들을 어떻게 숫자로 바구는지... 말씀하신대로 itoa동작구연을 하는 방법을좀
알려주셧으면///

mirheekl의 이미지

strtol이 여러 진법들을 지원합니다.

--

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.