Skip to content

Commit

Permalink
add quicksort test
Browse files Browse the repository at this point in the history
  • Loading branch information
edadma committed Apr 2, 2018
1 parent 92a354c commit 1f42cbf
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/test/scala/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object Main extends App {
add( new StdIOChar(0x20000) )
add( new RAM("stack", 0, 0xFFFF) )
add( new RAM("bss", 0x1000000, 0x100FFFF) )
addHexdump( io.Source.fromFile("tests/armstrong.hex") )
addHexdump( io.Source.fromFile("tests/quicksort.hex") )
}
} )

Expand Down
103 changes: 103 additions & 0 deletions tests/quicksort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
void
out( char c ) {
*((char*) 0x20000) = c;
}

//#include <stdio.h>
//#define out( c ) putchar( c )

void
print( char* s ) {
while (*s)
out( *s++ );
}

void
println( char* s ) {
print( s );
out( '\n' );
}

char*
bin2str( int n, int radix, char* buf ) {
char digits[] = "0123456789ABCDEF";
char* p = &buf[33];
int quo = n;

if (n < 0)
quo = -quo;

*p-- = 0;

while (quo >= radix) {
*p-- = digits[(quo%radix)];
quo /= radix;
}

*p = digits[quo];

if (n < 0)
*--p = '-';

return p;
}

void
sort( int a[], int left, int right ) {
if (right > left) {
int i = left;
int j = right;
int tmp = 0;
int p = a[right];

do {
while (a[i] < p)
i++;

while (a[j] > p)
j--;

if (i <= j) {
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
i++;
j--;
}
} while (i <= j);

if (left < j)
sort( a, left, j );

if (i < right)
sort( a, i, right );
}
}

void
run( int array[], int size ) {
sort( array, 0, size - 1 );
print( "[" );

for (int i = 0; i < size; i++) {
char buf[34];
char* s = bin2str( array[i], 10, buf );

print( s );

if (i < size - 1)
print( ", " );
}

println( "]" );
}

void
main() {
run( (int[]){10, 9, 8, 7, 7, 7, 7, 3, 2, 1}, 10 );
run( (int[]){10, 9, 8, 7, 7, 5, 7, 3, 2, 1}, 10 );
run( (int[]){10, 9, 8, 7, 5, 7, 4, 3, 2, 1}, 10 );
run( (int[]){10, 9}, 2 );
run( (int[]){10}, 1 );
run( (int[]){}, 0 );
}
115 changes: 115 additions & 0 deletions tests/quicksort.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

Hex dump of section '.text':
0x00010080 37010100 ef00c04c 73500000 00000000 7......LsP......
0x00010090 00000000 00000000 00000000 00000000 ................
0x000100a0 00000000 00000000 00000000 00000000 ................
0x000100b0 00000000 00000000 00000000 00000000 ................
0x000100c0 130101fe 233c8100 13040102 93070500 ....#<..........
0x000100d0 a307f4fe b7070200 0347f4fe 2380e700 .........G..#...
0x000100e0 13000000 03348101 13010102 67800000 .....4......g...
0x000100f0 130101fe 233c1100 23388100 13040102 ....#<..#8......
0x00010100 2334a4fe 6f00c001 833784fe 13871700 #4..o....7......
0x00010110 2334e4fe 83c70700 13850700 eff05ffa #4............_.
0x00010120 833784fe 83c70700 e39007fe 13000000 .7..............
0x00010130 83308101 03340101 13010102 67800000 .0...4......g...
0x00010140 130101fe 233c1100 23388100 13040102 ....#<..#8......
0x00010150 2334a4fe 033584fe eff09ff9 1305a000 #4...5..........
0x00010160 eff01ff6 13000000 83308101 03340101 .........0...4..
0x00010170 13010102 67800000 130101fc 233c8102 ....g.......#<..
0x00010180 13040104 93070500 13870500 2330c4fc ............#0..
0x00010190 2326f4fc 93070700 2324f4fc b7070100 #&......#$......
0x000101a0 03b7076a 2338e4fc 1387076a 03378700 ...j#8.....j.7..
0x000101b0 233ce4fc 9387076a 83c70701 2300f4fe #<.....j....#...
0x000101c0 833704fc 93871702 2334f4fe 8327c4fc .7......#4...'..
0x000101d0 2322f4fe 8327c4fc 9b870700 63d80700 #"...'......c...
0x000101e0 832744fe bb07f040 2322f4fe 833784fe .'D....@#"...7..
0x000101f0 1387f7ff 2334e4fe 23800700 6f000004 ....#4..#...o...
0x00010200 032744fe 832784fc bb67f702 1b870700 .'D..'...g......
0x00010210 833784fe 9386f7ff 2334d4fe 930604ff .7......#4......
0x00010220 3387e600 034707fe 2380e700 032744fe 3....G..#....'D.
0x00010230 832784fc bb47f702 2322f4fe 032744fe .'...G..#"...'D.
0x00010240 832784fc 1b070700 9b870700 e35af7fa .'...........Z..
0x00010250 832744fe 130704ff b307f700 03c707fe .'D.............
0x00010260 833784fe 2380e700 8327c4fc 9b870700 .7..#....'......
0x00010270 63de0700 833784fe 9387f7ff 2334f4fe c....7......#4..
0x00010280 833784fe 1307d002 2380e700 833784fe .7......#....7..
0x00010290 13850700 03348103 13010104 67800000 .....4......g...
0x000102a0 130101fd 23341102 23308102 13040103 ....#4..#0......
0x000102b0 233ca4fc 93870500 13070600 232af4fc #<..........#*..
0x000102c0 93070700 2328f4fc 032704fd 832744fd ....#(...'...'D.
0x000102d0 1b070700 9b870700 63d0e718 832744fd ........c....'D.
0x000102e0 2326f4fe 832704fd 2324f4fe 232204fe #&...'..#$..#"..
0x000102f0 832704fd 93972700 033784fd b307f700 .'....'..7......
0x00010300 83a70700 2320f4fe 6f000001 8327c4fe ....# ..o....'..
0x00010310 9b871700 2326f4fe 8327c4fe 93972700 ....#&...'....'.
0x00010320 033784fd b307f700 03a70700 832704fe .7...........'..
0x00010330 9b870700 e34cf7fc 6f000001 832784fe .....L..o....'..
0x00010340 9b87f7ff 2324f4fe 832784fe 93972700 ....#$...'....'.
0x00010350 033784fd b307f700 03a70700 832704fe .7...........'..
0x00010360 9b870700 e3cce7fc 0327c4fe 832784fe .........'...'..
0x00010370 1b070700 9b870700 63cae706 8327c4fe ........c....'..
0x00010380 93972700 033784fd b307f700 83a70700 ..'..7..........
0x00010390 2322f4fe 832784fe 93972700 033784fd #"...'....'..7..
0x000103a0 3307f700 8327c4fe 93972700 833684fd 3....'....'..6..
0x000103b0 b387f600 03270700 23a0e700 832784fe .....'..#....'..
0x000103c0 93972700 033784fd b307f700 032744fe ..'..7.......'D.
0x000103d0 23a0e700 8327c4fe 9b871700 2326f4fe #....'......#&..
0x000103e0 832784fe 9b87f7ff 2324f4fe 0327c4fe .'......#$...'..
0x000103f0 832784fe 1b070700 9b870700 e3dee7f0 .'..............
0x00010400 032744fd 832784fe 1b070700 9b870700 .'D..'..........
0x00010410 635ef700 032784fe 832744fd 13060700 c^...'...'D.....
0x00010420 93850700 033584fd eff09fe7 0327c4fe .....5.......'..
0x00010430 832704fd 1b070700 9b870700 635ef700 .'..........c^..
0x00010440 032704fd 8327c4fe 13060700 93850700 .'...'..........
0x00010450 033584fd eff0dfe4 13000000 83308102 .5...........0..
0x00010460 03340102 13010103 67800000 130101fa .4......g.......
0x00010470 233c1104 23388104 13040106 2334a4fa #<..#8......#4..
0x00010480 93870500 2322f4fa 832744fa 9b87f7ff ....#"...'D.....
0x00010490 9b870700 13860700 93050000 033584fa .............5..
0x000104a0 eff01fe0 b7070100 1385876b eff05fc4 ...........k.._.
0x000104b0 232604fe 6f008006 8327c4fe 93972700 #&..o....'....'.
0x000104c0 033784fa b307f700 83a70700 130784fb .7..............
0x000104d0 13060700 9305a000 13850700 eff0dfc9 ................
0x000104e0 2330a4fe 033504fe eff09fc0 832744fa #0...5.......'D.
0x000104f0 9b87f7ff 1b870700 8327c4fe 9b870700 .........'......
0x00010500 63d8e700 b7070100 1385076c eff05fbe c..........l.._.
0x00010510 8327c4fe 9b871700 2326f4fe 0327c4fe .'......#&...'..
0x00010520 832744fa 1b070700 9b870700 e346f7f8 .'D..........F..
0x00010530 b7070100 1385876c eff09fc0 13000000 .......l........
0x00010540 83308105 03340105 13010106 67800000 .0...4......g...
0x00010550 130101f6 233c1108 23388108 1304010a ....#<..#8......
0x00010560 b7070100 83b5076d 1387076d 03368700 .......m...m.6..
0x00010570 1387076d 83360701 1387076d 03378701 ...m.6.....m.7..
0x00010580 9387076d 83b70702 2334b4f6 2338c4f6 ...m....#4..#8..
0x00010590 233cd4f6 2330e4f8 2334f4f8 930784f6 #<..#0..#4......
0x000105a0 9305a000 13850700 eff05fec b7070100 .........._.....
0x000105b0 83b5876f 1387876f 03368700 1387876f ...o...o.6.....o
0x000105c0 83360701 1387876f 03378701 9387876f .6.....o.7.....o
0x000105d0 83b70702 2338b4f8 233cc4f8 2330d4fa ....#8..#<..#0..
0x000105e0 2334e4fa 2338f4fa 930704f9 9305a000 #4..#8..........
0x000105f0 13850700 eff09fe7 b7070100 83b50772 ...............r
0x00010600 13870772 03368700 13870772 83360701 ...r.6.....r.6..
0x00010610 13870772 03378701 93870772 83b70702 ...r.7.....r....
0x00010620 233cb4fa 2330c4fc 2334d4fc 2338e4fc #<..#0..#4..#8..
0x00010630 233cf4fc 930784fb 9305a000 13850700 #<..............
0x00010640 eff0dfe2 9307a000 2320f4fe 93079000 ........# ......
0x00010650 2322f4fe 930704fe 93052000 13850700 #"........ .....
0x00010660 eff0dfe0 9307a000 2324f4fe 930784fe ........#$......
0x00010670 93051000 13850700 eff05fdf 93050000 .........._.....
0x00010680 130504ff eff09fde 13000000 83308109 .............0..
0x00010690 03340109 1301010a 67800000 .4......g...


Hex dump of section '.rodata':
0x000106a0 30313233 34353637 38394142 43444546 0123456789ABCDEF
0x000106b0 00000000 00000000 5b000000 00000000 ........[.......
0x000106c0 2c200000 00000000 5d000000 00000000 , ......].......
0x000106d0 0a000000 09000000 08000000 07000000 ................
0x000106e0 07000000 07000000 07000000 03000000 ................
0x000106f0 02000000 01000000 0a000000 09000000 ................
0x00010700 08000000 07000000 07000000 05000000 ................
0x00010710 07000000 03000000 02000000 01000000 ................
0x00010720 0a000000 09000000 08000000 07000000 ................
0x00010730 05000000 07000000 04000000 03000000 ................
0x00010740 02000000 01000000 ........

0 comments on commit 1f42cbf

Please sign in to comment.