Skip to content

Instantly share code, notes, and snippets.

@billglover
Last active September 18, 2018 15:17
Show Gist options
  • Save billglover/ba4b09d811d1d0f024fc67819897cf32 to your computer and use it in GitHub Desktop.
Save billglover/ba4b09d811d1d0f024fc67819897cf32 to your computer and use it in GitHub Desktop.
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
00029 RET ; return from function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment