mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 04:16:01 +00:00
Merge pull request #420 from whtiehack/patch-4
Update ch3-05-control-flow.md
This commit is contained in:
commit
cd7b74f7d6
@ -213,8 +213,10 @@ LOOP_END:
|
||||
下面用汇编语言重新实现LoopAdd函数
|
||||
|
||||
```
|
||||
#include "textflag.h"
|
||||
|
||||
// func LoopAdd(cnt, v0, step int) int
|
||||
TEXT ·LoopAdd(SB), NOSPLIT, $0-32
|
||||
TEXT ·LoopAdd(SB), NOSPLIT, $0-32
|
||||
MOVQ cnt+0(FP), AX // cnt
|
||||
MOVQ v0+8(FP), BX // v0/result
|
||||
MOVQ step+16(FP), CX // step
|
||||
@ -225,12 +227,12 @@ LOOP_BEGIN:
|
||||
LOOP_IF:
|
||||
CMPQ DX, AX // compare i, cnt
|
||||
JL LOOP_BODY // if i < cnt: goto LOOP_BODY
|
||||
goto LOOP_END
|
||||
JMP LOOP_END
|
||||
|
||||
LOOP_BODY:
|
||||
ADDQ $1, DX // i++
|
||||
ADDQ CX, BX // result += step
|
||||
goto LOOP_IF
|
||||
JMP LOOP_IF
|
||||
|
||||
LOOP_END:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user