Linux 简单上循环无限
简单上循环无限 我的代码怎么了 有什么建议吗 我的编程环境是linux、emacs、assembly、at&t语法Linux 简单上循环无限,linux,assembly,x86,infinite-loop,Linux,Assembly,X86,Infinite Loop,简单上循环无限 我的代码怎么了 有什么建议吗 我的编程环境是linux、emacs、assembly、at&t语法 .section .data .section .bss .lcomm buffer,1 .section .text .global _start _start: movl %esp,%ebp subl $8,%esp #8(%ebp) is 2nd arg == input #12(%ebp) is 3rd arg
.section .data
.section .bss
.lcomm buffer,1
.section .text
.global _start
_start:
movl %esp,%ebp
subl $8,%esp
#8(%ebp) is 2nd arg == input
#12(%ebp) is 3rd arg == output
#open,read,open,write,close
movl $5,%eax
movl 8(%ebp),%ebx
movl $0,%ecx
movl $0666,%edx
int $0x80
#%eax contains input's fd
#movl to first local var
movl %eax,-4(%ebp)
movl $5,%eax
movl 12(%ebp),%ebx
movl $03101,%ecx
movl $0666,%edx
int $0x80
#eax contains output's fd
#movl to second local var
movl %eax,-8(%ebp)
loop:
#read 1 byte from file 1st byte of data
movl $3,%eax
movl -4(%ebp),%ebx
movl $buffer,%ecx
movl $1,%edx
int $0x80
#buffer contains 1 byte of file
cmpb $0,buffer
je program_exit
pushl buffer
call convert #will return converted to %al
addl $4,%esp
movb %al,buffer
#write 1 byte from buffer to file
movl $1,%edx
movl $buffer,%ecx
movl -8(%ebp),%ebx
movl $4,%eax
int $0x80
jmp loop
program_exit:
movl buffer,%ebx
movl $1,%eax
int $0x80
.type convert,@function
convert:
pushl %ebp
movl %esp,%ebp
movb 8(%ebp),%al #1 byte data in the buffer
cmpb $'a',%al
jl convert_end
cmpb $'z',%al
jg convert_end
addb $32,%al #convert to upper
convert_end:
movl %ebp,%esp
popl %ebp
ret
请注意,read(2)
通过返回0
来表示文件结束状态。您试图通过查找asciiNUL
来查找文件的结尾,这在Unix派生系统中非常罕见。(如果您想要一种制作TB大小文件的简单方法,dd If=/dev/zero of=/tmp/gigab bs=1048576 seek=1048576 count=1
。整个过程将填充asciiNUL
字符。(或者整数0
,但您需要解释它。)
您需要通过比较read(2)
系统调用的返回值,而不是查看接收到缓冲区中的数据来修改代码以查找文件结尾。注意read(2)
通过返回0
来表示文件结束状态。您试图通过查找asciiNUL
来查找文件结束,这在Unix派生系统上非常罕见。(如果您想要一种制作TB大小文件的简单方法,dd If=/dev/zero of=/tmp/gigab bs=1048576 seek=1048576 count=1
。整个过程将填充asciiNUL
字符。(或者整数0
,但您需要解释它。)
您需要修改代码,通过比较
read(2)的返回值来查找文件结尾
系统调用,而不是通过查看接收到缓冲区中的数据。这是因为文件末尾没有空字符吗?我用鼠标垫创建了输入文件并键入abcdefghij。如果我将退出条件0更改为“j”,它不会无限循环。怎么了?是因为文件末尾没有空字符吗?我创建了输入fi用鼠标垫按住le键并键入abcdefghij。如果我将退出条件0更改为“j”,它不会无限循环。怎么了?