0
我是新來編寫彙編代碼的人,並且在使用循環打印出數組的值時遇到問題。我已經打印出了計數器的值,而不是數組中的值,有人可以解釋我做錯了什麼,還有我該如何指向數組的頂部?我曾嘗試使用不同的寄存器,但似乎沒有任何工作。我的教授問我這樣做(如果它看起來效率低下):在MASM程序集中打印數組的值
.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
任何建議表示讚賞。
謝謝,這麼簡單 - 我很生氣,我錯過了。 –