0

When I try to send the text to a file everything works correctly, but when I change the number 4 of RDX in "_edit", for the variable "counter" with the same value, instead of sending me the text to a file, it sends it to me through the linux terminal.

section .data
    file db "2file.asm", 0
    hola db 'hola'
    counter db 0
section .bss
    idfile resd 1
section .text
        global _start
_start:
    mov rax, 5
    mov rbx, file
    mov rcx, 0002h
    int 0x80
    cmp rax, 0
    jl _finalize
    mov [idfile], rax
_edit:
    mov qword[counter], 4
    mov rax, 4
    mov rbx, [idfile]
    mov rcx, hola
    mov rdx, counter
    int 0x80
_finalize:
    mov rax, 1
    mov rbx, 0
    int 0x80
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • 1
    `mov qword[counter], 4` stores 8 bytes (qword), but `counter` is only one byte. Likewise `mov [idfile], rax` stores 8 bytes where only 4 are allocated. – Nate Eldredge May 29 '22 at 22:18
  • 1
    Also, you can't safely use the int 0x80 interface in a 64-bit program. https://stackoverflow.com/questions/46087730/what-happens-if-you-use-the-32-bit-int-0x80-linux-abi-in-64-bit-code Convert it to use `syscall`, noting that the system call numbers and register usage is different. – Nate Eldredge May 29 '22 at 22:20
  • 1
    Finally, `mov rdx, counter` loads `rdx` with the address of `counter`, but I think you want the byte count instead. So something more like `mov rdx, [counter]` would be appropriate, again after you fix the sizes. – Nate Eldredge May 29 '22 at 22:22

0 Answers0