# Golang defer in ASM (2025-09-02)

**URL:** <https://pluralist.net/t/golang-defer-in-asm-2025-09-02/313>\
**Category:** Code Reading\
**Tags:** asm, golang\
**Created:** [September 2, 2025, 5:22am UTC](https://pluralist.net/t/golang-defer-in-asm-2025-09-02/313 "2025-09-02T05:22:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![delyan](https://pluralist.net/user_avatar/pluralist.net/delyan/32/245_2.png) [@delyan](https://pluralist.net/u/delyan)\
**Post date:** [September 2, 2025, 5:22am UTC](https://pluralist.net/t/golang-defer-in-asm-2025-09-02/313/1 "2025-09-02T05:22:01Z")

</div>

This is the beginning of an exploration of what Golang’s `defer` keyword does to the final ASM produced by our Go compiler. We are using [Godbolt.org](http://Godbolt.org) for this.

> **[Compiler Explorer - Go](https://godbolt.org/z/c8xqrcc4s)**
>
> // Type your code here, or load an example.
> package p
> import "fmt"
> 
> func square(x int) int {
> defer fmt.Println("Good Bye!")
> return x \* x
> }

# Without `defer`:

```go
package p
import "fmt"

func square(x int) int {
    fmt.Println("Good Bye!")
    return x * x
}

```

 ![image](https://pluralist.net/uploads/default/original/1X/a060f26a90a3f7b0be7acb94207b602bfbb6e59d.png)

# With `defer`

```auto
package p
import "fmt"

func square(x int) int {
    defer fmt.Println("Good Bye!")
    return x * x
}

```

 ![image](https://pluralist.net/uploads/default/original/1X/0a9dd2401fb69c8e81a4ba9a977608f9c8cb8d03.jpeg)
