diff options
| author | Cliff Click <cliffc@acm.org> | 2025-05-09 21:05:24 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-05-09 21:05:24 -0700 |
| commit | 05afabd5152b06295e16c65b5a249229a4ead996 (patch) | |
| tree | f6083c53c7519e516db18e3ec5ab895a15b585e1 /chapter22/docs/examples | |
| parent | 05c529f379c9c82387916aba7f83f7a215829e37 (diff) | |
| download | Simple-05afabd5152b06295e16c65b5a249229a4ead996.tar.gz Simple-05afabd5152b06295e16c65b5a249229a4ead996.zip | |
Bugs for BubbleSort
Encoding picking up extra function padding if needing another round for X86 short jumps.
GCM failed to late schedule around loop backedges.
X86 Div was using AX/DX as *source* registers.
X86 kills more flags.
Diffstat (limited to 'chapter22/docs/examples')
| -rw-r--r-- | chapter22/docs/examples/BubbleSort.smp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/chapter22/docs/examples/BubbleSort.smp b/chapter22/docs/examples/BubbleSort.smp index 70f45717..f6b30752 100644 --- a/chapter22/docs/examples/BubbleSort.smp +++ b/chapter22/docs/examples/BubbleSort.smp @@ -14,7 +14,7 @@ struct Scan { // Skip whitespace val skip = { Scan s -> - while( s.buf[s.x] <= 32 ) + while( s.buf[s.x] <= ' ' ) s.x++; }; @@ -53,7 +53,6 @@ val main = { -> // Parse "123, " until a something else while( s.x < s.buf# ) { int n = number(s); - i32 q=n; ns[num++] = n; if( !peek(s,',') ) break; @@ -63,24 +62,23 @@ val main = { -> // Print a list of numbers sys.io.p("[ "); - u8[] !buf = new u8[20]; + u8[] !junk = new u8[1]; for( int i=0; i<num; i++ ) { int x = ns[i]; if( !x ) { sys.io.p("0, "); continue; } - u32 log=0, q=x; - while( q>0 ) - { q/=10; log++; } - i32 raw=log; - sys.libc._exit(raw); - // for( int j=0, a=x; j<log; j++ ) { - // q = x/10; - // buf[log-j] = '0'+(x-q*10); - // x = q; - // } - // int raw = buf; - // sys.libc.write(1,raw,log); - // sys.io.p(", "); + int ten = 1, log = 0; + while( ten <= x ) { ten *= 10; log++; } + ten /= 10; + for( int i=0; i<log; i++ ) { + int q = x/ten; + int r = x - q*ten; + junk[0] = q+'0'; + sys.io.p(junk); + x = r; + ten /= 10; + } + sys.io.p(", "); } sys.io.p("]"); |
