Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6088419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:58:57+00:00 2026-05-23T11:58:57+00:00

Is it possible to include inline assembly in Go code? This blog post shows

  • 0

Is it possible to include inline assembly in Go code?

This blog post shows compiling Go to a separate .s file and editing it, but not inline asm as part of a Go function like many C compilers support.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:58:58+00:00Added an answer on May 23, 2026 at 11:58 am

    There is no support for inline assembly, but you can link with code written in assembly through C, compiling with cgo and using import "C", like in gmp.go. You could alternatively write in a style of assembly that is directly compatible with Go, like in asm_linux_amd64.s, that requires that function names start with “·”.

    Or, you can use nasm and gccgo, my favorite way so far. (Note that Nasm does not seem to support functions starting with “·”).

    Here’s a working “hello world” example:

    hello.asm:

    ; Based on hello.asm from nasm
    
        SECTION .data       ; data section
    msg:    db "Hello World",10 ; the string to print, 10=cr
    len:    equ $-msg       ; "$" means "here"
                    ; len is a value, not an address
    
        SECTION .text       ; code section
    
    global go.main.hello        ; make label available to linker (Go)
    go.main.hello:
    
        ; --- setup stack frame
        push rbp            ; save old base pointer
        mov rbp,rsp   ; use stack pointer as new base pointer
    
        ; --- print message
        mov edx,len     ; arg3, length of string to print
        mov ecx,msg     ; arg2, pointer to string
        mov ebx,1       ; arg1, where to write, screen
        mov eax,4       ; write sysout command to int 80 hex
        int 0x80        ; interrupt 80 hex, call kernel
    
        ; --- takedown stack frame
        mov rsp,rbp  ; use base pointer as new stack pointer
        pop rbp      ; get the old base pointer
    
        ; --- return
        mov rax,0       ; error code 0, normal, no error
        ret         ; return
    

    main.go:

    package main
    
    func hello();
    
    func main() {
        hello()
        hello()
    }
    

    And a handy Makefile:

    main: main.go hello.o
        gccgo hello.o main.go -o main
    
    hello.o: hello.asm
        nasm -f elf64 -o hello.o hello.asm
    
    clean:
        rm -rf _obj *.o *~ *.6 *.gch a.out main
    

    I call hello() twice in main.go, just to double check that hello() returns properly.

    Note that calling interrupt 80h directly is not considered good style on Linux, and calling functions written is C is more “future proof”. Also note that this is assembly specifically for 64-bit Linux, and is not platform-independent in any way, shape or form.

    I know it’s not a direct answer to your question, but it’s the easiest route I know for using assembly with Go, in lack of inlining. If you really need inlining, it’s possible to write a script that extracts inline assembly from source files and prepares it in a way that follows the pattern above. Close enough? 🙂

    Quick example for Go, C and Nasm: gonasm.tgz

    Update: Later versions of gccgo needs the -g flag and only “main.hello” is needed instead of “go.main.hello”. Here is an updated example for Go, C and Yasm: goyasm.tgz

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to include one CSS file in another?
Is it possible to include view code in a plugin, such that an app
We have a few places where we include inline <script> blocks which run code,
Possible Duplicates: Include a JavaScript file in a JavaScript file How to include a
Is it possible to include variables in a web.config transform file? For each environment,
Is it possible to include an existing pdf file in a JasperReport? We really
is it possible to include a servlet in a jsp page? if so how?
Is it possible to INCLUDE other mysql scripts in a composite script? Ideally I
Is it possible to include an alphabetic character in a SimpleDateFormat Pattern String? I
Is it possible to include custom data files in ClickOnce deployment? I couldn't find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.