정수 문자 공백 정수 형식으로 파일에서 3 개의 값을 읽으려고합니다. 예를 들면 :nasm을 사용하여 어셈블리에서 fscanf 호출
5, 그 정확한 형식, 즉 3
: 5 후 어떤 공백, 내가 성공적으로 열 수는 fopen라는 쉼표 뒤에 공백과 3
후 어떤 공백 파일과 나는 fgetc를 사용하여 동일한 파일에 액세스하고 내용을 인쇄했습니다. 지금은, 스택에 반대 순서로 매개 변수를 밀어 어셈블리에서 C 함수를 호출하는
내가 그것을 읽기) (당신이 한 fscanf 사용하려고 아래이lea eax, [xValue]
push eax
lea eax, [comma]
push eax
lea eax, [yValue]
push eax
mov eax, [format] ;defined as [format db "%d %c %d", 0] in the data section
push eax
mov eax, ebx ; move handle to file into eax
push eax
call _fscanf
을 내 코드입니다 그것이 내가 값이 읽기 액세스 어떻게, 위의에 해당하는 경우
fscanf(fp, "%d %c %d", &yValue, &comma, &xValue);
:이 시점에서 나는 위의 가정하고는 동일하다? 내가는 fgetc를 호출하여 개별 문자를 인쇄 할 수 때부터 올바르게 파일에 액세스하고있어 알고 있지만, 명확성을 위해 아래의 파일
mov eax, fileMode
push eax
mov eax, fileName
push eax
call _fopen
mov ebx, eax ;store file pointer
어떤 도움/조언이 많이 감사를 엽니 다 내 코드입니다. 감사.
추가 편집
...대답은 솔루션을 제공했다. 이 문제가있는 다른 사용자를 위해 아래 코드를 게시하십시오.
section .data
fname db "data.txt",0
mode db "r",0 ;;set file mode for reading
format db "%d%c %d", 0
;;--- end of the data section -----------------------------------------------;;
section .bss
c resd 1
y resd 1
x resd 1
fp resb 1
section .text
extern _fopen
global _main
_main:
push ebp
mov ebp,esp
mov eax, mode
push eax
mov eax, fname
push eax
call _fopen
mov [fp] eax ;store file pointer
lea eax, [y]
push eax
lea eax, [c]
push eax
lea eax, [x]
push eax
lea eax, [format]
push eax
mov eax, [fp]
push eax
call _fscanf
;at this point x, y and c has the data
mov eax,0
mov esp,ebp
pop ebp
ret
어셈블러가 작동하는 방식, 대괄호 사용 – Mark
"오피 코드와 피연산자의 유효하지 않은 조합"을 제공 – Christo