1

I have successfully compiled an assembly tutorial for NASM:

global _start            ; global entry point export for ld
section .text
_start:
    ; sys_write(stdout, message, length)
    mov eax, 4        ; sys_write syscall
    mov ebx, 1        ; stdout
    mov ecx, message    ; message address
    mov edx, length        ; message string length
    int 80h
    ; sys_exit(return_code)
    mov eax, 1        ; sys_exit syscall
    mov ebx, 0        ; return 0 (success)
    int 80h
section .data
    message: db 'Hello, world!',0x0A    ; message and newline
    length: equ $-message            ; NASM definition pseudo-instruction

How to call sys_write procedure, using special SYSENTER instruction?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
user4035
  • 22,508
  • 11
  • 59
  • 94
  • 2
    Look at: `/usr/src/linux/arch/x86/vdso/vdso32/sysenter.S` (modulo the final `ret`). Before calling that, everything is setup as for int 80h. – ninjalj Nov 28 '12 at 01:08
  • 2
    Also note the recommended way is to call the kernel-provided entry code in the `linux-gate.so` that is mapped into every process. See [here for details](http://www.trilithium.com/johan/2005/08/linux-gate) – Jester Nov 28 '12 at 01:27
  • There are tons of similar questions: http://stackoverflow.com/questions/15598700/syscall-or-sysenter-on-32-bits-linux?lq=1 http://stackoverflow.com/questions/4526424/writing-to-a-file-in-nasm-using-system-calls?rq=1 http://stackoverflow.com/questions/17436752/linux-x86-nasm-subroutine-print-a-dword-from-eax?rq=1 – Peter Teoh Feb 12 '15 at 01:52
  • Don’t you mean "lea ecx, message" ? (or rcx if in long mode in a 64-bit o/s.) – Cecil Ward May 24 '23 at 00:30

0 Answers0