2014-11-13 1 views
0

x86-64 Intel 어셈블리의 배열에 값을 입력하려고하는데이를 이해할 수 없습니다.x86-64 배열 입력 및 인쇄

세그먼트를 .bss로 배열을 만듭니다. 그런 다음 r15를 사용하여 배열의 주소를 다른 모듈로 전달하려고합니다. 그 모듈 안에 배열에 삽입 할 번호를 물어 봅니다. 그러나 그것은 효과가 없습니다. 내가 inputqarary의 내부 다음

segment .bss 
dataArray resq 15          ; Array that will be manipulated 

segment .text 
mov rdi, dataArray          ; Store memory address of array so the next module can use it. 
call inputqarray          ; Calling inputqarray module 

을 할 노력하고있어

나는이 :

mov r15, rdi           ; Move the memory address of the array into r15 for safe keeping 

push qword 0           ; Make space on the stack for the value we are reading 
mov rsi, rsp           ; Set the second argument to point to the new locaiton on the stack 
mov rax, 0            ; No SSE input 
mov rdi, oneFloat          ; "%f", 0 
call scanf            ; Call C Standard Library scanf function 
call getchar           ; Clean the input stream 

pop qword [r15] 

그때

push qword 0 
mov rax, 1 
mov rdi, oneFloat 
movsd xmm0, [dataArray] 
call printf 
pop rax 
을 수행하여 출력을 이용하여 입력 한 값을 시도

불행히도 출력물을 얻는 건 0.00000

입니다.

답변

1

잘못된 형식 지정자를 사용하고 있으므로 출력이 0입니다. "%lf" 다음으로 프로 시저를 밀고 팝 할 필요가 없습니다. 데이터 배열의 주소를 scanf으로 전달하면 rsi이되므로 rsi으로 전달하십시오. 하나는 덜 움직입니다.

어레이를 15 QWORDS로 선언하셨습니까? 120 바이트입니까? 또는 resb 15을 의미 했습니까?

이 작동하고 당신의 방법에 당신을 얻을해야합니다

extern printf, scanf, exit 
global main 

section .rodata 
fmtFloatIn  db "%lf", 0 
fmtFloatOut  db `%lf\n`, 0 

section .bss 
dataArray  resb 15 

section .text 
main: 
    sub  rsp, 8       ; stack pointer 16 byte aligned 

    mov  rsi, dataArray 
    call inputqarray 

    movsd xmm0, [dataArray] 
    mov  rdi, fmtFloatOut 
    mov  rax, 1 
    call printf 

    call exit 

inputqarray: 
    sub  rsp, 8       ; stack pointer 16 byte aligned 

    ; pointer to buffer is in rsi 
    mov  rdi, fmtFloatIn 
    mov  rax, 0 
    call scanf 

    add  rsp, 8 
    ret 

enter image description here

당신은 C 함수에 RDI에 PARAMS 전달되기 때문에,이 윈도우에 없습니다.

+0

정말 고마워요. 나는 네가 나보다 다르게 한 것을 정말로 모르지만 지금은 효과가있다. 나는 모르는 것이 불편하다. '% f'에서 '% lf'(으)로 서식을 수정했습니다. 바로 그 문제를 해결하지 못했습니다. 나는 코드를 지우고 거기에있는 것을 천천히 만들었고 나에게도 똑같이 보였다. 팁을 어레이에 직접로드하는 것에 대해 감사드립니다. 그리고 네, 그렇게 많은 기억을 할당하려고했습니다. 어셈블리에서 직접 배열을 만드는 중입니다. – RNikoopour