0

The program i'm making prints out a message, creates a file through the syscall (sys_creat) prints out another message and then exits. when compiled through these commands:

nasm -f elf32 -o makefile.o makefile.asm 
ld -m elf_i386 -o makefile makefile.o 
./makefile

the ./makefile spits out cryptic weird what appears to be raw binary everything executes to some extent like the file is created messages 1 and 2 are printed to the console. but in a very dirty and unclean way. heres my code for this:

global _start


_start:
    ; print out mkfile to stdo (msg1)
    mov eax, 4                
    mov ebx, 1
    mov ecx, msg1
    mov edx, msg1Len
    int 0x80        
    

    ; create file
    mov eax, 8    ; (Itworked)  eax register (sys_creat)
    mov ebx, name ; name of the file to be created
    mov ecx, 0777 ; file permissions
    int 0x80      ; syscall for sys_creat
    
  
    mov eax, 4      ; prints out second message (msg2)
    mov ebx, 1
    mov ecx, msg2
    mov edx, msg2Len
    int 0x80
    
    
    mov eax, 1    ; exit syscall for program
    int 0x80

.data 
    msg1 db "Making file" ; msg1 
    msg1Len equ -$msg1    ; msg1 length in chars
    
    msg2 db "File Made"   ; msg2
    msg2Len equ -$msg2    ; msg2 length in chars

    name db "Itworked"    ; file name


  • 2
    `-$msg1` is minus the literal symbol `msg1`. To get the length you should use `$ - msg1` instead. – ecm Oct 19 '21 at 17:45
  • 1
    And you should write `name db "Itworked",0` to include an explicit zero-value terminator byte. – ecm Oct 19 '21 at 17:46
  • 1
    By the way, `makefile` is not the best choice of name for your program, since it's also the filename that the `make(1)` utility looks for. You might want to pick a different name. – Nate Eldredge Oct 19 '21 at 18:19
  • @Nate Eldredge: How do you suppose the syscall interrupt 80h service 8 determines the length of the filename? I believe it is actually a zero-terminated string. – ecm Oct 19 '21 at 18:26
  • 2
    @ecm: Oh, you're right. I mixed up the variables and thought you were talking about the message, which should not be null terminated. But indeed, the filename should. – Nate Eldredge Oct 19 '21 at 20:11

0 Answers0