Append:

  49b4e8: c0 ae 47 00 00 00 00         shrb $0, 71(%rsi)

在2023年9月26日星期二 UTC+8 22:43:27<j2gg0s> 写道:

> How to understand assmbly code `  47ae26: 48 8d 0d bb 06 02 00         
>  leaq    132795(%rip), %rcx      # 0x49b4e8 <go:func.*+0x220>`
>
> Go code:
> ```
> //go:noinline
> func add(a, b int) int {
>         defer func() {
>                 fmt.Println(3)
>         }()
>         return a + b
> }
>
> func main() {
>         add(10, 20)
> }
> ```
>
> Build by `GOOS=linux GOARCH=amd64 GOSSAFUNC=main.add go21 build main.go`
>
> Assembly code
> ```
> objdump -D -S main | grep "main.add>:" -A 30
> 000000000047ae00 <main.add>:
> ; func add(a, b int) int {
>   47ae00: 49 3b 66 10                   cmpq    16(%r14), %rsp
>   47ae04: 76 5b                         jbe     0x47ae61 <main.add+0x61>
>   47ae06: 55                            pushq   %rbp
>   47ae07: 48 89 e5                      movq    %rsp, %rbp
>   47ae0a: 48 83 ec 18                   subq    $24, %rsp
>   47ae0e: 66 44 0f d6 7c 24 10          movq    %xmm15, 16(%rsp)
>   47ae15: c6 44 24 07 00                movb    $0, 7(%rsp)
>   47ae1a: 48 c7 44 24 08 00 00 00 00    movq    $0, 8(%rsp)
> ;       return a + b
>   47ae23: 48 01 d8                      addq    %rbx, %rax
> ;       defer func() {
>   47ae26: 48 8d 0d bb 06 02 00          leaq    132795(%rip), %rcx      # 
> 0x49b4e8 <go:func.*+0x220>
>   47ae2d: 48 89 4c 24 10                movq    %rcx, 16(%rsp)
>   47ae32: c6 44 24 07 01                movb    $1, 7(%rsp)
> ;       return a + b
>   47ae37: 48 89 44 24 08                movq    %rax, 8(%rsp)
>   47ae3c: c6 44 24 07 00                movb    $0, 7(%rsp)
>   47ae41: e8 7a 00 00 00                callq   0x47aec0 <main.add.func1>
>   47ae46: 48 8b 44 24 08                movq    8(%rsp), %rax
>   47ae4b: 48 83 c4 18                   addq    $24, %rsp
>   47ae4f: 5d                            popq    %rbp
>   47ae50: c3                            retq
>   47ae51: e8 8a 47 fb ff                callq   0x42f5e0 
> <runtime.deferreturn>
>   47ae56: 48 8b 44 24 08                movq    8(%rsp), %rax
>   47ae5b: 48 83 c4 18                   addq    $24, %rsp
>   47ae5f: 5d                            popq    %rbp
>   47ae60: c3                            retq
> ; func add(a, b int) int {
>   47ae61: 48 89 44 24 08                movq    %rax, 8(%rsp)
> ```
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/df511011-aab2-48c6-8de8-5c8a3c544a07n%40googlegroups.com.

Reply via email to