인라인 어셈블리에서 라인 구분자에 대한 질문..

choco6의 이미지

리눅스에서 인라인 어셈블리에 대한 질문입니다.
저는 gcc 2.96을 사용하는 리눅스 박스에서 인라인 어셈코드를 작성할 때 가령 다음과 같이 짰습니다.

asm("
movl %eax, %ebx
movl $56, %esi
movb %ah, (%ebx)
");

그런데 이 코드를 gcc 3.4.2 이상 사용하는 리눅스 박스에 가서 컴파일 하면 다음과 같은 에러가 발생합니다.

[leedw@choco test]$ gcc mycode.c
shell.c: In function 'getprocaddr':
shell.c:12: error: missing terminating " character
shell.c:13: error: expected string literal before '.' token
shell.c:15: error: missing terminating " character

인라인 어셈블리 하우투에서는 다음과 같이 코드를 짤 것을 권고하더군요.

asm ("movl %eax, %ebx\n\t"
"movl $56, %esi\n\t"
"movb %ah, (%ebx)");

그런데 제가 이해할 수 없는 것은 gcc 2.96에서는 \n\t 문자를 집어넣지 않아도 잘만 되던 것이 왜 3.x.x 버전 이상에서는 에러를 발생시키느냐 입니다. 현재 코딩된 많은 소스들이 맨 위의 코드처럼 코딩되어 있어서 라인 하나 하나 컨버전하는게 만만치 않은 작업이네요. 혹시 3.x.x 버전 이상에서 코드를 바꾸지 않고도 컴파일 할 수 있는지...
고수분들의 조언 부탁드립니다.

kewlbear의 이미지

C언어에서 따옴표를 아래처럼 사용하면 안됩니다.

Quote:

"....
....
..."

아래처럼 사용해야합니다.
Quote:

"..."
"..."
"..."

이러면 따옴표로 묶은 것들이 모두 합쳐져서 하나의 문자열 상수가 됩니다.

물론 어셈블리 명령을 구분하려면 구분자를 넣어주셔야합니다.

choco6의 이미지

글세요 c언어하고는 상관이 있는 문제인가요..
asm이나 __asm__ 키워드에서 어떻게 처리하느냐인데... 문제는 gcc 2.96 이하버전에서는 잘 돌아가던 소스가 gcc 3.x.x 이상대에서 갑자기 에러로 빠져버리느냐에요.. 정책이 바뀐건지....

kslee80의 이미지

kewlbear 님께서 쓰신글처럼 작성해야 문법에 맞게 작성한 것입니다.
gcc 3.x.x 가 gcc 2.96 에 비해서 문법 체크가 더 까다로워졌다고 생각하시면 됩니다.

그리고 만약에 님께서 의심하는것처럼 인라인 어셈블리 라인구분자로 인한 컴파일 에러라고 한다면,
어셈블러의 에러 메세지가 출력되어야 합니다.
저 에러 메세지는 컴파일러의 에러 메세지죠.

kewlbear의 이미지

인라인 어셈블리를 C에서 사용하시는 것 아닌가요?

sephiron의 이미지

컴파일과정 이후 as를 호출하여 한꺼번에 어셈블하기 때문에 컴파일과정 도중 as를 호출하는 것은 아닙니다.
----
Forensic Computing On Linux

아직 멀었어

kewlbear의 이미지

바로 그 컴파일 과정때문에 C문법에 맞아야하는 것이죠.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.