i test a assembly code in kali linux but i problem with output
this my code:
**`.section .data
.equ RECORD_FIRSTNAME, 0
.equ RECORD_LASTNAME, 40
.equ RECORD_ADDRESS, 80
.equ RECORD_AGE, 320
.equ RECORD_SIZE, 324
.equ SYS_EXIT, 1
.equ SYS_READ, 3
.equ SYS_WRITE, 4
.equ SYS_OPEN, 5
.equ SYS_CLOSE, 6
.equ SYS_BRK, 45
.equ LINUX_SYSCALL, 0x80
.equ STDIN, 0
.equ STDOUT, 1
.equ STDERR, 2
.equ END_OF_FILE, 0
.equ ST_WRITE_BUFFER, 8
.equ ST_FILEDES, 12
record1:
.ascii "Fredrick"
.rept 31 #Padding to 40 bytes
.byte 0
.endr
.ascii "Bartlett"
.rept 31 #Padding to 40 bytes
.byte 0
.endr
.ascii "4242 S PrairienTulsa, OK 55555"
.rept 209 #Padding to 240 bytes
.byte 0
.endr
.long 45
record2:
.ascii "Marilyn"
.rept 32 #Padding to 40 bytes
.byte 0
.endr
.ascii "Taylor"
.rept 33 #Padding to 40 bytes
.byte 0
.endr
.ascii "2224 S Johannan StnChicago, IL 12345"
.rept 203 #Padding to 240 bytes
.byte 0
.endr
.long 29
record3:
.ascii "Derrick"
.rept 32 #Padding to 40 bytes
.byte 0
.endr
.ascii "McIntire"
.rept 31 #Padding to 40 bytes
.byte 0
.endr
.ascii "500 W OaklandnSan Diego, CA 54321"
.rept 206 #Padding to 240 bytes
.byte 0
.endr
.long 36
file_name:
.ascii "test.dat"
.equ ST_FILE_DESCRIPTOR, -4
.section .text
.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)
#Write the first record
pushl ST_FILE_DESCRIPTOR(%ebp)
pushl $record1
call write_record
addl $8, %esp
#Write the second record
pushl ST_FILE_DESCRIPTOR(%ebp)
pushl $record2
call write_record
addl $8, %esp
#Write the third record
pushl ST_FILE_DESCRIPTOR(%ebp)
pushl $record3
call write_record
addl $8, %esp
#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
.globl write_record
.type write_record, @function
write_record:
pushl %ebp
movl %esp, %ebp
pushl %ebx
movl $SYS_WRITE, %eax
movl ST_FILEDES(%ebp), %ebx
movl ST_WRITE_BUFFER(%ebp), %ecx
movl $RECORD_SIZE, %edx
int $LINUX_SYSCALL
#NOTE - %eax has the return value, which we will
# give back to our calling program
popl %ebx
movl %ebp, %esp
popl %ebp
ret`**
This is the output that should be displayed:
Fredrick
Bartlett
4242 S Prairie
Tulsa, OK 55555
45
Marilyn
Taylor
2224 S Johannan St
Chicago, IL 12345
29
Derrick
McIntire
500 W Oakland
San Diego, CA 54321
36
But it displays the output:
Fredrick
Bartlett
4242 S Prairie
Tulsa, OK 55555
-MarMarilyn
Taylor
2224 S Johannan St
Chicago, IL 12345
DerrDerrick
McIntire
500 W Oakland
San Diego, CA 54321
$test
First, why does it not store the age, which was introduced as long
Second, why does it not follow formatting?
please help
thank you
i compile this command in linux
as –32 myapp.s -o myapp.o
ld -m elf_i386 myapp.o -o myapp
./myapp
user25018149 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1