github.com/cloudwego/iasm@v0.2.0/example/helloworld.s (about)

     1  //
     2  // Copyright 2024 CloudWeGo Authors
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  #define STDOUT      $1
    18  #define IMAGE_BASE  0x04000000
    19  
    20  #ifdef __Linux__
    21  #define SYS_exit    $1
    22  #define SYS_write   $4
    23  #elif defined(__Darwin__)
    24  #define SYS_exit    $0x02000001
    25  #define SYS_write   $0x02000004
    26  #else
    27  #error Unsupported operating system.
    28  #endif
    29  
    30  .org   IMAGE_BASE
    31  .entry start
    32  
    33  start:
    34      movq    STDOUT, %rdi
    35      leaq    msg(%rip), %rsi
    36      movq    $13, %rdx
    37      movq    SYS_write, %rax
    38      syscall
    39      xorl    %edi, %edi
    40      movq    SYS_exit, %rax
    41      syscall
    42  
    43  msg:
    44      .ascii "hello, world\n"