为什么我的代码只返回记录中的第一个数据项?

问题描述

我正在尝试编写一个程序,该程序使用循环将 30 条相同的记录写入一个文件

我只能让 Fredrick 的名字显示 30 次。
关于如何弄清楚如何显示其余记录的任何建议?


一个问题:

想象一下,我有多个与现有记录相似的记录,例如记录2、记录3...

我想从文件的给定记录中找到最大的年龄,并将该年龄作为程序的状态代码返回。

我如何看待这个问题?我尝试比较记录,但终端冻结。

.include "linux.s"
.include "record-def.s"

.section .data

#Constant data of the records we want to write
#Each text data item is padded to the proper
#length with null (i.e. 0) bytes.

#.rept is used to pad each item. .rept tells
#the assembler to repeat the section between
#.rept and .endr the number of times specified.
#This is used in this program to add extra null
#characters at the end of each field to fill
#it up
record1:
.ascii "Fredrick\0"
.rept 31 #Padding to 40 bytes
.byte 0
.endr

.ascii "Bartlett\0"
.rept 31 #Padding to 40 bytes
.byte 0
.endr

.ascii "4242 S Prairie\nTulsa,OK 55555\0"
.rept 209 #Padding to 240 bytes
.byte 0
.endr

.long 45

#This is the name of the file we will write to
file_name:
.ascii "test.dat\0"

.equ ST_FILE_DESCRIPTOR,-4
.globl _start
_start:
#copy the stack pointer to %ebp
movl %esp,%ebp
#Allocate space to hold the file descriptor
subl $4,%esp

#Open the file
movl $SYS_OPEN,%eax
movl $file_name,%ebx
movl $0101,%ecx       # This says to create if it
            # doesn't exist,and open for 
            # writing
movl $0666,%edx
int $LINUX_SYSCALL

#Store the file descriptor away         
movl %eax,ST_FILE_DESCRIPTOR(%ebp)

    movl $110,%ebx
    movl $140,%ecx
    
    start_loop: 
            cmpl $140,%ebx
            je loop_exit
            incl %ebx
            
            cmpl %ecx,%ebx
            
            #Write the first record
            pushl ST_FILE_DESCRIPTOR(%ebp)
            pushl $record1
            call write_record
            addl $8,%esp           
    
            jmp start_loop
            
    loop_exit:
            popl %ecx
            popl %ebx
        
    
#Close the file descriptor
movl $SYS_CLOSE,%eax
movl ST_FILE_DESCRIPTOR(%ebp),%ebx
int $LINUX_SYSCALL
    
#Exit the program
movl $SYS_EXIT,%eax
movl $0,%ebx
int $LINUX_SYSCALL

# To run:  From the command line (NOTE:  I'm using an x86-64 build so you may need to assemble   
# differently)
# Takes the file toupper.s,changes all lowercase to uppercase and saves as a new file 
# toupper.uppercase
#           as --32 write-records.s -o write-records.o
#           as --32 write-record.s -o write-record.o
#           ld -melf_i386 write-record.o write-records.o -o write-records
#           ./write-records

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)