教授から 64 ビット アセンブリ用に提供されたテスト プログラムを実行しようとしていますが、適切に動作しません。
エラーは次のとおりです: エラー LNK2017: 'ADDR32' の 'naturals' への再配置は無効です /LARGEADDRESSAWARE:NO 致命的なエラー LNK1165: 修正エラーのためにリンクが失敗しました
コードは次のとおりです。
; no need for .386, .586, .MODEL directives in 64-bit programs
.DATA
sentence BYTE "Now is the winter of our discontent", 0h
firstWord BYTE 20 DUP (?)
space BYTE ' '
naturals QWORD 10 DUP (?)
sum QWORD ?
.CODE
main proc
; test out our getFirstWord procedure
; the second argument
mov rax, offset firstWord
push rax
; the first argument
mov rax, offset sentence
push rax
call getFirstWord
; initialize our 'naturals' array
mov rcx, 1
mov rdi, 0
nextNumber:
mov naturals[rdi*8], rcx
inc rcx
cmp rcx, 10
jg initializationComplete
inc rdi
jmp nextNumber
initializationComplete:
; test out our sumArray procedure
; second argument (number of elements in array)
mov rax, 10
push rax
; first argument (array address, alternative to offset)
lea rax, naturals
push rax
call sumArray
; store the result in memory
mov sum, rax
; exit
mov rax, 0
ret
main endp
getFirstWord proc
;pop rax ; address of sentence
;pop rbx ; address of firstWord
mov rax, [esp+8]
mov rbx, [esp+16]
mov rcx, 0
mov cl, [space]
nextCharacter:
cmp [rax], byte ptr 0 ; check for a null-terminator in the sentence
je allDone
cmp cl, [rax] ; check for a space in the sentence
je nullTerminate
mov dl, [rax] ; copy the current character
mov [rbx], dl
inc rax
inc rbx
jmp nextCharacter
nullTerminate:
inc rbx
mov byte ptr [rbx], 0
allDone:
ret 16
getFirstWord endp
sumArray proc
; get the address of the array
mov rax, [rsp+8]
; get the number of elements in the array
mov rcx, [rsp+16]
xor rbx, rbx ; initialize sum to zero
xor rsi, rsi ; initialize counter to zero
nextArrayElement:
add rbx, [rax]
add rax, 8
inc rsi
cmp rsi, rcx
je finishedSum
jmp nextArrayElement
finishedSum:
mov rax, rbx
ret 16
sumArray endp
END
LARGEADDRESSAWARE を NO に設定してみました。プログラムはコンパイルおよびビルドされますが、出力はありません。出力はないと思われ、実行する必要があるだけですか? それとも、その設定が何かを台無しにしていますか?ナチュラルの動かし方も変えてみたのですが、アドレスの設定を変えただけで何とか動きました。