0

我是编写汇编代码的新手,我无法使用循环打印出我的数组的值。我的代码打印出计数器的值而不是数组中的值,有人可以解释我做错了什么,还有我如何指向数组的顶部?我尝试过使用不同的寄存器,但似乎没有任何效果。我的教授要求我这样做(如果它看起来效率低下):

           .386
           .model flat
ExitProcess PROTO NEAR32 stdcall, dwExitCode:dword
Include io.h
cr         equ 0DH
Lf         equ 0AH
           .stack 4096
           .data
newline    byte CR, LF, 0
whitespace byte 32,32,0     
arr        dword 10 dup(?)
n          dword 2
string     byte  40 dup(?)
prompt     byte "Please enter a value: ", 0
origArr    byte "Original Array", 0
           .code
_start:
           mov    ecx,n         ; number of values in the array
           lea    ebx,arr       ; address of the array
           sub    edi, edi
top:       cmp    ecx, 0
           je     done
           output prompt
           input  string, 40
           atod   string
           mov    [arr+edi], ecx
           add    edi, 4
           loop   top
done:      output origArr
           mov    ecx, n
           call   myproc

         INVOKE ExitProcess, 0

PUBLIC  _start
myproc proc near32
       .data
val_str byte 11 dup(?), 0
       .code
        push eax
        push edi 
        push ecx
        sub edi,edi              ; index register
top2:   mov eax, [ebx+edi]
        dtoa val_str, eax
        output val_str
        add edi,4                ; modify esi rather than ebx
        loop top2
        pop ecx 
        pop edi
        pop eax
        ret
myproc endp

         END    

任何建议表示赞赏。

4

1 回答 1

2
mov    [arr+edi], ecx

您正在存储循环计数器,而不是atod.

于 2012-05-05T19:39:09.110 回答