NASM: System Calls

How to perform a system call?

  • system call num ⇒ eax
  • arguments ⇒ ebx, ecx, ...
  • call interrupt 80h
  • get result

example

section .data
        userMsg db 'Please enter a number: '
        lenUserMsg equ $-userMsg
        dispMsg db 'You have entered: '
        lenDispMsg equ $-dispMsg

section .bss                                    ;Uninitialized data
        num resb 5
section .text
        global _start
        _start:
        ;User prompt
        mov eax, 4
        mov ebx, 1
        mov ecx, userMsg
        mov edx, lenUserMsg
        int 80h

        ;Read and store the user input
        mov eax, 3
        mov ebx, 2
        mov ecx, num
        mov edx, 5                              ;5 bytes, 4 for value, 1 for sign
        int 80h
        ;Output disMsg
        mov eax, 4
        mov ebx, 1
        mov ecx, dispMsg
        mov edx, lenDispMsg
        int 80h
        ;OUtput the number entered
        mov eax, 4
        mov ebx, 1
        mov ecx, num
        mov edx, 5
        int 80h

; Exit code
        mov eax, 1
        mov ebx, 0
        int 80h

发表留言

本站启用了垃圾评论检测插件,如果误删请联系我~