간단한 어셈블리 프로그래밍 질문 드립니다

mkdi123의 이미지

%include "asm_io.inc"
 
        segment .data
prompt1 db      "Enter a number (A) : ", 0      ;
prompt2 db      "Enter a number (B) : ", 0      ; initialized data is put in the data segment here
outmsg1 db      "A X B = ", 0
 
        segment .bss
input1  resb    0
input2  resb    1
result  resb    2
 
 
        segment .text
        global  main
main
        enter   0,0             ; setup stack frame
        pusha
 
        mov     eax, prompt1    ;
        call    print_string    ; code is put in the text segment. Do not modify the code before
        call    read_int        ; or after this comment.
        mov     [input1], eax   ;
        mov     eax, prompt2
        call    print_string
        call    read_int
        mov     [input2], eax
        mov     ecx, [input2]
 
while:
        add     eax, [input1]
        add     [result], eax
        sub     ecx, 1
        JECXZ   while
 
        mov     eax, outmsg1
        call    print_string
        mov     eax, [result]
        call    print_int
        call    print_nl
 
 
        popa
        mov     eax, 0  ; return value
        leave                   ; leave stack frame
        ret

두 수를 입력받아서 덧셈을 반복하는 식으로 곱을 계산하는 아주 간단한 문제입니다.

컴파일은 되는데 출력하면 값이 제대로 출력되지 않습니다ㅠㅠ

 의 이미지

컴파일은 되는데 값이 제대로 출력되지 않는 이유는 수도 없이 많을 수 있죠.

그 이전에, 아래 루프가 대체 뭘 하고 있는 건지 라인 단위로 해석해서 설명해보세요. 그러면 원인을 아시게 될 겁니다.

while:
add eax, [input1]
add [result], eax
sub ecx, 1
JECXZ while
Necromancer의 이미지

call print_int, call print_string 은 뭔가요? 정체불명 사제 라이브러리에 있는 코드를 call하는 것으로 보이는데 이런건 인수넘기는법, 반환값, 뭐하는지를 알아야 답줄수 있습니다. 경우에 따라서는 사제 라이브러리의 버그로 안돌 수 있고요.

어셈블리에서 레지스터나 메모리 값 텍스트 출력 그냥 안됩니다.
2진수 숫자를 화면에 표시할려는 진법의 숫자대로 ASCII코드 전환작업해서 출력할 string(다 만든뒤 마지막에 0 추가)을 만든 뒤에 보통은 OS에서 제공하는 텍스트 출력 서비스를 이용해서 출력 합니다. OS의 서비스 안쓰고 직접 하겠다면 비디오메모리 조작, GUI환경일때는 폰트를 이용한 drawing까지 파야 합니다.

Written By the Black Knight of Destruction

댓글 달기

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