Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"runtime"
)
func main() {
fmt.Println("Hello, 世界!")
fmt.Println("GOOS:", runtime.GOOS)
package main
import (
"fmt"
"log"
"net"
"net/http"
"os"
)
// RemoteAddr allows HTTP servers and other software to record
// the network address that sent the request, usually for
// logging. This field is not filled in by ReadRequest and
// has no defined format. The HTTP server in this package
// sets RemoteAddr to an "IP:port" address before invoking a
// handler.
// This field is ignored by the HTTP client.
RemoteAddr string
@billglover
billglover / example2.nasm
Last active September 18, 2018 15:25
Increment an integer 1000 times (with a function call and no inlining)
; inc(n int) int
00000 TEXT "".inc(SB), $32-16 ; function definition
00000 MOVQ (TLS), CX ; move TLS to register CX
00009 CMPQ SP, 16(CX) ; compare SP with part of CX
00013 JLS 88 ; go to line 88 if 'less than'
00015 SUBQ $32, SP ; increase stack size by 32-bytes
00019 MOVQ BP, 24(SP) ; move BP to the stack
00024 LEAQ 24(SP), BP ; update BP to new location
; --- ---
00029 XORL AX, AX ; zero out register AX
@billglover
billglover / example2.go
Last active September 18, 2018 15:23
Increment an integer 1000 times (with a function call and no inlining)
package main
func main() {
n := inc(1000)
println(n)
}
func inc(n int) int {
for i := 0; i < 1000; i++ {
n = add(n)
@billglover
billglover / example2.nasm
Last active September 18, 2018 15:20
Increment an integer 1000 times (with a function call)
; inc(n int) int
00000 TEXT "".inc(SB), NOSPLIT, $0-16 ; function definition
00000 MOVQ "".n+8(SP), AX ; move parameter from stack to AX
00005 XORL CX, CX ; zero out register CX
00007 JMP 15 ; go to line 15
00009 INCQ CX ; increment register CX
00012 INCQ AX ; increment register AX
00015 CMPQ CX, $1000 ; compare register CX with 1000
00022 JLT 9 ; go to line 9
00024 MOVQ AX, "".~r1+16(SP) ; move AX to stack return value
@billglover
billglover / example1.nasm
Last active September 18, 2018 15:17
Increment an integer 1000 times
; inc(n int) int
00000 TEXT "".inc(SB), NOSPLIT, $0-16 ; function definition
00000 MOVQ "".n+8(SP), AX ; move parameter from stack to AX
00005 XORL CX, CX ; zero out register CX
00007 JMP 15 ; go to line 15
00009 INCQ CX ; increment register CX
00012 INCQ AX ; increment register AX
00015 CMPQ CX, $1000 ; compare register CX with 1000
00022 JLT 9 ; go to line 9
00024 MOVQ AX, "".~r1+16(SP) ; move AX to stack return value
@billglover
billglover / example1.nasm
Created September 18, 2018 15:11
Increment an integer 1000 times
0x0000 00000 (inline.go:8) TEXT "".inc(SB), NOSPLIT, $0-16
0x0000 00000 (inline.go:8) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0000 00000 (inline.go:8) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0000 00000 (inline.go:8) FUNCDATA $3, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0000 00000 (inline.go:9) PCDATA $2, $0
0x0000 00000 (inline.go:9) PCDATA $0, $0
0x0000 00000 (inline.go:9) MOVQ "".n+8(SP), AX
0x0005 00005 (inline.go:9) XORL CX, CX
0x0007 00007 (inline.go:9) JMP 15
0x0009 00009 (inline.go:9) INCQ CX
@billglover
billglover / example2.go
Created September 18, 2018 15:09
Increment an integer 1000 times (with a function call)
package main
func main() {
n := inc(1000)
println(n)
}
func inc(n int) int {
for i := 0; i < 1000; i++ {
n = add(n)
@billglover
billglover / example1.go
Created September 18, 2018 14:54
Increment an integer 1000 times
package main
func main() {
n := inc(1000)
println(n)
}
func inc(n int) int {
for i := 0; i < 1000; i++ {
n = n + 1