diff options
| -rw-r--r-- | 3/6_control/24_while_loop.c | 8 | ||||
| -rw-r--r-- | 3/6_control/25_while_guard.c | 13 |
2 files changed, 17 insertions, 4 deletions
diff --git a/3/6_control/24_while_loop.c b/3/6_control/24_while_loop.c index a3367fc..18a6c70 100644 --- a/3/6_control/24_while_loop.c +++ b/3/6_control/24_while_loop.c @@ -11,10 +11,10 @@ short loop_while(short a, short b) { - short result = ; - while () { - result = ; - a = ; + short result = 0; + while (a > b) { + result = result + a*b; + a = a - 1; } return result; } diff --git a/3/6_control/25_while_guard.c b/3/6_control/25_while_guard.c new file mode 100644 index 0000000..ad33917 --- /dev/null +++ b/3/6_control/25_while_guard.c @@ -0,0 +1,13 @@ +// %rdi <- a +// %rsi <- b +// loop: +// testq %rsi, %rsi +// jle .L8 +long loop_while2(long a, long b) { + long result = b; + while (b > 0) { + result = result * a; + b = b - a; + } + return result; +} |
