我正在尝试运行教授为我们提供的用于 64 位汇编的测试程序,但它不能正常工作。
错误是:错误 LNK2017:“ADDR32”重定位到“自然”无效,没有 /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,程序将编译和构建,但没有输出。是否假设没有任何输出,它只需要运行?还是那个设置搞砸了?我也尝试改变自然的移动方式,但唯一有效的是改变地址设置。