0

I'm trying to read the file starting from the fifth byte but its not working for some reason I know the problem is in the _seek procedure because the code works without it but now with it

here's the code

%include "macro.asm"

section .data
    filename db "first-names.txt"

section .bss
    buffer resb 7

section .text
    global _start

    _start:
        call _open  
        call _seek
        call _read
        call _print

        exit

    _open:
        mov eax, SYSOPEN
        mov edi, filename
        mov esi, 0
        mov edx, 0777
        syscall

        mov ecx, eax    ;store fd

        ret

    _read:
        mov edi, ecx
        mov eax, SYSREAD
        mov esi, buffer
        mov edx, 7
        syscall

        ret
    
    _print:
        mov eax, SYSWRITE
        mov edi, 1
        mov esi, buffer
        mov edx, 7
        syscall

        ret

    _seek:
        mov eax, SYSSEEK
        mov edi, ecx
        mov esi, 5
        mov edx, 0
        syscall

        ret
user259137
  • 85
  • 1
  • 1
  • 1
    What is the expected and actual output? What are the return values of open, seek, and read? Have you tried running it with strace? – prl Jun 01 '22 at 12:33
  • FYI, `0777` in NASM is decimal, unlike C where it's octal. To do that in NASM, `0q777`. Looks like the showstopper problem here is expecting ECX to survive across `syscall`, though. See the linked duplicate. – Peter Cordes Jun 01 '22 at 17:10

0 Answers0