IA32汇编语言从文件中读取整数

时间:2014-11-25 18:33:29

标签: linux assembly ia-32

我正在尝试从文件中读取整数,然后将它们输出到新文件。我猜我最困惑的地方是读整数时。请看一下我的代码,以及我只是汇编语言的初学者。

.data
filename:
.asciz "indata.txt"
out:
.asciz "outdata.txt"
.bss
.lcomm num, 5
.lcomm filehandle, 4
.text
.globl _start
_start:

# Open input file
movl $5, %eax #open file
movl $filename, %ebx #filename
movl $00, %ecx #rd
movl $0444, %edx
int $0x80
test %eax, %eax #Test
js badfile
movl %eax, filehandle

# Open output file
movl $5, %eax
movl $out, %ebx
movl $01101, %ecx
movl $0644, %edx
int $0x80
test %eax, %eax
js badfile
movl %eax, out

readloop:
#Read and store input.
movl $3, %eax #Read
movl filehandle, %ebx   
movl $num, %ecx #memory adress of input string
movl $5, %edx #length
int $0x80       
test %eax, %eax #Test
jz done
js badfile
movl %eax, %edx

#Convert to number
subl $48, num


# Write output to file
movl $4, %eax
movl out, %ebx
movl $num, %ecx
int $0x80
test %eax,%eax
js badfile
jmp readloop

badfile:
movl %eax, %ebx
movl $1, %eax
int $0x80

done:

#Close file.
movl $6, %eax
movl filehandle, %ebx
int $0x80

#Close file.
movl $6, %eax
movl out, %ebx
int $0x80

movl $1, %eax
movl $0, %ebx
int $0x80

0 个答案:

没有答案