.include "linux.s" .include "record-def.s" .section .data # Constant data of the records we want to write # Each 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 chars at the end of each field # to fill the record up to the record size. # START OF RECORDS record1: # First name .ascii "Fredrick\0" .rept 31 # Padding to 40 bytes .byte 0 .endr # Last name .ascii "Bardlet\0" .rept 31 # Padding to 40 bytes .byte 0 .endr # Address .ascii "4242 S Prairie\nTulsa, OK 55555\0" .rept 209 # Padding to 240 bytes .byte 0 .endr # Age .long 45 # Field is 8 bytes long (1 word) record2: # First name .ascii "Marilyn\0" .rept 32 # Padding to 40 bytes .byte 0 .endr # Last name .ascii "Taylor\0" .rept 33 # Padding to 40 bytes .byte 0 .endr # Address .ascii "2224 S Johannan St\nChicago, IL 12345\0" .rept 203 # Padding to 240 bytes .byte 0 .endr # Age .long 29 # Field is 8 bytes long (1 word) record3: # First name .ascii "Derrick\0" .rept 32 # Padding to 40 bytes .byte 0 .endr # Last name .ascii "McIntire\0" .rept 31 # Padding to 40 bytes .byte 0 .endr # Address .ascii "500 W Oakland\nSan Diego, CA 54321\0" .rept 206 # Padding to 240 bytes .byte 0 .endr # Age .long 36 # Field is 8 bytes long (1 word) # END OF RECORDS .section .text # File we'll be writing to file_name: .ascii "test.dat\0" .equ ST_FILE_DESCRIPTOR, -8 .globl _start .global write_record _start: movq %rsp, %rbp subq $8, %rsp # Allocate space in stack for FD # Open file movq $SYS_OPEN, %rax movq $file_name, %rdi movq $0101, %rsi # Open for writing, create if it doesn't exist movq $0666, %rdx syscall # Store FD: movq %rax, ST_FILE_DESCRIPTOR(%rbp) # Write first record pushq ST_FILE_DESCRIPTOR(%rbp) pushq $record1 call write_record addq $16, %rsp #cleanup stack # Write second record pushq ST_FILE_DESCRIPTOR(%rbp) pushq $record2 call write_record addq $16, %rsp # Write third record pushq ST_FILE_DESCRIPTOR(%rbp) pushq $record3 call write_record addq $16, %rsp # Close FD movq $SYS_CLOSE, %rax movq ST_FILE_DESCRIPTOR(%rbp), %rdi syscall # We are done, just exit movq $SYS_EXIT, %rax movq $0, %rdi syscall