contributed by <HotMercury>
第 3 週測驗題
isqrt1: bitwise 操作
在執行第一版 i_sqrt 時嘗試使用 gcc 編譯,有以下錯誤,但如果把 n 變成常數,就可以正常執行,error In using math function in gcc? 可以知道如果使用的是 const 編譯器會最佳化成對應的值,如果要正確執行要加上 -lm link math library.
- int msb = (int)log2(n);
+ int msb = (int)log2(16);
$ gcc sqr_t.c
/usr/bin/ld: /tmp/ccmYLpqw.o: in function i_sqrt:
HotMercury changed a year agoView mode Like Bookmark
contributed by < Hotmercury >
we can find instruction reference
code on github
Find the position 0 the most close to LSB, and then make the position left to this postion become 0.
we can use this to compute the carry flag.
:::success
example
mask = 1010 0111
1010 0111 -> 0000 0111
HotMercury changed 2 years agoView mode Like Bookmark