인사말,리눅스에서 NASM을 쓰고 있는데 다음과 같은 문제가 있습니다. 사용자가 문자열을 입력하고 크기를 반환하는 함수에 전달해야하는 간단한 프로그램을 작성해야합니다.NASM 세그멘테이션 결함 문제
%include "macros.inc"
section .data
prompt1 db "Enter string: ",0
prompt1len equ $-prompt1
prompt2 db "The size of string is: ",0
prompt2len equ $-prompt2
section .bss
string resb 20
section .text
global _start
_start: str_output prompt1len,prompt1
str_input string
mov ebx,string
call func
str_output prompt2len,prompt2
output eax
exit 0
func:
xor eax,eax
et **cmp byte [ebx],0h**
je end
inc eax
inc ebx
jmp et
end dec eax
ret
그리고 여기에 매크로 파일 :
코드는
%macro exit 1
mov eax,1
mov ebx,%1
int 80h
%endmacro
%macro int_input 1
mov eax,3
mov ebx,0
mov ecx,%1
mov edx,1
int 80h
and eax,0Fh
mov %1,eax
%endmacro
%macro str_input 1
mov eax,3
mov ebx,1
mov ecx,%1
mov edx,20
int 80h
% endmacro
%macro output 1
mov eax,%1
or eax,30h
mov %1,eax
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,1
int 80h
%endmacro
%macro str_output 2+
mov eax,4
mov ebx,1
mov ecx,%2
mov edx,%1
int 80h
%endmacro
내가 프로그램을 디버깅 및 문제는 [명령 CMP 바이트에 EB이다 x], 0h, 왜냐하면 내가 프로그램을 시작할 때 str_input 후에 segmentation fault를 출력하기 때문이다. 나는 틀린 것을 보지 못했지만 어쩌면 그 연설과 실수를했을 것이다.
ebx로 무엇을하고 있습니까?. [ebx]는 ebx에있는 주소의 메모리에있는 데이터에 액세스하는 것을 의미합니다. ebx에서 주소를로드하는 것을 보지 못합니다. 내가 잘못하면 올바른 주소가 표시됩니다. – Zimbabao
어떻게 컴파일합니까? 무슨 명령 줄? – BlackBear
@Zimbabao : 예, func – BlackBear