x86 어셈블리 질문 (far call, ret imm16)

blkstorm의 이미지

x86 어셈블리를 공부하다가 call/return에서 의문점이 있어서 질문올립니다.

1. far call
이건 어떤 경우에 사용되는건지요? Pseudocode라도 좋으니 예제가 있으면 도와주시면 고맙겠습니다.

2. ret중에서 imm16또는 imm32가 붙어있는게 있던데, imm16/32의 용도가 어떻게 되는지요?

감사합니다.

simpid의 이미지

10년전쯤에 x86 어셈블러 열심히 썼었는데...
안쓴지 오래되서 잘 기억은 안나는군요.

1) far call
16비트 CPU 시절에는 메모리 주소를 지정할때 SEGMENT:OFFSET 구조를 사용했었습니다.
FAR CALL 은 SEGMENT가 다른것을 의미합니다.
NEAR CALL은 OFFSET만 있어도 되지만
FAR CALL 은 SEGMENT, OFFSET 이 있어야 되겠죠.
참고로 32비트 시대에는 메모리가 LINEAR 해서 FAR CALL 같은 개념은 없습니다.
그냥 OFFSET 만 존재하는게 32비트 CPU죠.

2) imm16, imm32
imm이 immediate 를 의미하는걸로 기억합니다.
그냥 숫자 데이터라는 의미입니다.
16, 32는 비트수 입니다.

익명 사용자의 이미지

1. far call
16비트의 경우에는 simpid님이 잘 설명해 주셨으니 참고하시고요. 32비트 환경에서는 segment 대신
selector의 개념이 나타나게 되므로 지정한 selector에 대한 segment descriptor를 참조하여 호출이
일어납니다. 일반적으로 현재의 운영체제에서 flat memory model을 사용하므로 far call을 일반 응용
프로그램에서 사용하는 예는 없으며 사용할 경우 priviledge level의 문제로 exception이 발생할 수
있습니다. 운영체제에서는 far call을 사용할 수 있습니다. (자세한 내용은 intel의 data sheet를
참조하시기 바랍니다)

2. ret imm16 or imm32
ret 뒤에 붙는 immediate 값은 해당 숫자 만큼 스택을 비우는 용도입니다. 호출전에 사용한 parameter
가 stack에 push 되어 있을 것이므로 이 값을 ret 명령의 수행 이후에 비우는 것입니다. 일반적으로
pascal 호출 규약이나 윈도우즈의 stdapi 호출 규약에서 사용됩니다. (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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.