64位程序集修复错误

时间:2016-04-16 18:09:42

标签: assembly 64-bit fixup

我正在尝试运行教授为64位汇编提供的测试程序,而且工作正常。

错误是: 错误LNK2017:'ADDR32'重定位到'自然'无效/ LARGEADDRESSAWARE:否 致命错误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,程序将编译和构建,但没有输出。有没有假设是任何输出,它只需要运行?或者那个设置搞砸了什么?我也尝试改变自然的移动方式,但唯一有效的方法是更改​​地址设置。

0 个答案:

没有答案