0
파이썬 배경에서 왔기 때문에 일부 어셈블리에 직접 문의하려고합니다.사용자 입력 읽기 및 인쇄 문제가 발생했습니다.
지금까지 아주 잘 해왔지만 지금은 문제가 있습니다. 아래에있는 자습서에서는 사용자에게 인사하고 뭔가를 입력 한 다음 콘솔에이 텍스트를 표시하는 코드를 작성하도록 요청합니다.
그래서 나는 기본적으로이 작업을 수행하기 위해 관리하지만, 스크립트는 무작위로 특정 길이 후 출력의 일부를 차단 -Finee, thanks!
다시
Fineeanks!e
나에게 제공,
Fine
의 입력은 완벽하게 밖으로 작동하지만,
Fine, thanks!
나에게 다시
nks!,
을 제공합니다. 이 동작은 또한 한 문자열에 대해 항상 동일합니다. (모든 코드를 게시 미안하지만, 나는 오류가있을 수 아무 생각이 없다) (32 비트를
.section .data
hi: .ascii "Hello there!\nHow are you today?\n"
in: .ascii ""
inCp: .ascii "Fine"
nl: .ascii "\n"
inLen: .long 0
.section .text
.globl _start
_start:
Greet: # Print the greeting message
movl $4, %eax # sys_write call
movl $1, %ebx # stdout
movl $hi, %ecx # Print greeting
movl $32, %edx # Print 32 bytes
int $0x80 # syscall
Read: # Read user input
movl $3, %eax # sys_read call
movl $0, %ebx # stdin
movl $in, %ecx # read to "in"
movl $10000, %edx # read 10000 bytes (at max)
int $0x80 # syscall
Length: # Compute length of input
movl $in, %edi # EDI should point at the beginning of the string
# Set ecx to highest value/-1
sub %ecx, %ecx
not %ecx
movb $10, %al
cld # Count from end to beginning
repne scasb
# ECX got decreased with every scan, so this gets us the length of the string
not %ecx
dec %ecx
mov %ecx, (inLen)
jmp Print
Print: # Print user input
movl $4, %eax
movl $1, %ebx
movl $in, %ecx
movl (inLen), %edx
int $0x80
Exit: # Exit
movl $4, %eax
movl $1, %ebx
movl $nl, %ecx
movl $1, %edx
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80
내가 데비안 리눅스에서 GNU 어셈블러를 사용하고을 :
이
내 코드입니다), 이것은 AT & T 문법으로 작성되었습니다.왜 이런 이상한 오류가 발생했는지 알 수 있습니까?
이것은 완벽하게 작동, 감사합니다! 동적 메모리 할당에도 너무 익숙해 보였습니다. – jazzpi