Let’s read from a text file named new_file.txt with an assembler program.
1 2 3 4 5 6 | [mythcat@desk fasm]$ vim read_file.fasm [mythcat@desk fasm]$ ./fasm.x64 read_file.fasm flat assembler version 1.73.16 (16384 kilobytes memory, x64) 2 passes, 261 bytes. [mythcat@desk fasm]$ ./read_file FASM : Hello, world![mythcat@desk fasm]$ |
The source code is easy to understand.
This source code shows you how you can use a macro for print.
The base of this source code use INT 0x80 with a rax register for many functions like open, read and close.
I used a buffer with a length of 30 (see the manual of FASM Table 1.3 Data directives).
This is the source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | format ELF64 executable entry _start buffsize equ 30 buffer rb buffsize filename db "new_file.txt", 0 macro print msg, len { mov rax, 4 mov rbx, 1 mov rcx, msg mov rdx, len int 0x80 } _start: ; use open mov rax, 5 mov rbx, filename mov rcx, 0 int 0x80 push rax ; use the read mov rax, 3 pop rbx mov rcx, buffer mov rdx, buffsize int 0x80 ; use close mov rax, 6 int 0x80 print buffer, buffsize call exit exit: mov rax, 1 mov rbx, 0 int 0x80 |