-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
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() { | ||
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 | ||
printn( int n ) { | ||
char buf[34]; | ||
char* s = bin2str( n, 10, buf ); | ||
|
||
print( s ); | ||
} | ||
|
||
int | ||
abs( int x ) { | ||
const int bit31 = x >> 31; | ||
return (x ^ bit31) - bit31; | ||
} | ||
|
||
void | ||
main() { | ||
printn( abs(5) ); | ||
print( ", " ); | ||
printn( abs(0) ); | ||
print( ", " ); | ||
printn( abs(-5) ); | ||
println(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
Hex dump of section '.text': | ||
0x00010080 37010100 ef00c02a 73500000 00000000 7......*sP...... | ||
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 130101ff 23341100 23308100 13040101 ....#4..#0...... | ||
0x00010150 1305a000 eff0dff6 13000000 83308100 .............0.. | ||
0x00010160 03340100 13010101 67800000 130101fc .4......g....... | ||
0x00010170 233c8102 13040104 93070500 13870500 #<.............. | ||
0x00010180 2330c4fc 2326f4fc 93070700 2324f4fc #0..#&......#$.. | ||
0x00010190 b7070100 03b78738 2338e4fc 13878738 .......8#8.....8 | ||
0x000101a0 03378700 233ce4fc 93878738 83c70701 .7..#<.....8.... | ||
0x000101b0 2300f4fe 833704fc 93871702 2334f4fe #....7......#4.. | ||
0x000101c0 8327c4fc 2322f4fe 8327c4fc 9b870700 .'..#"...'...... | ||
0x000101d0 63d80700 832744fe bb07f040 2322f4fe c....'D....@#".. | ||
0x000101e0 833784fe 1387f7ff 2334e4fe 23800700 .7......#4..#... | ||
0x000101f0 6f000004 032744fe 832784fc bb67f702 o....'D..'...g.. | ||
0x00010200 1b870700 833784fe 9386f7ff 2334d4fe .....7......#4.. | ||
0x00010210 930604ff 3387e600 034707fe 2380e700 ....3....G..#... | ||
0x00010220 032744fe 832784fc bb47f702 2322f4fe .'D..'...G..#".. | ||
0x00010230 032744fe 832784fc 1b070700 9b870700 .'D..'.......... | ||
0x00010240 e35af7fa 832744fe 130704ff b307f700 .Z...'D......... | ||
0x00010250 03c707fe 833784fe 2380e700 8327c4fc .....7..#....'.. | ||
0x00010260 9b870700 63de0700 833784fe 9387f7ff ....c....7...... | ||
0x00010270 2334f4fe 833784fe 1307d002 2380e700 #4...7......#... | ||
0x00010280 833784fe 13850700 03348103 13010104 .7.......4...... | ||
0x00010290 67800000 130101fb 23341104 23308104 g.......#4..#0.. | ||
0x000102a0 13040105 93070500 232ef4fa 130704fc ........#....... | ||
0x000102b0 8327c4fb 13060700 9305a000 13850700 .'.............. | ||
0x000102c0 eff0dfea 2334a4fe 033584fe eff05fe2 ....#4...5...._. | ||
0x000102d0 13000000 83308104 03340104 13010105 .....0...4...... | ||
0x000102e0 67800000 130101fd 23348102 13040103 g.......#4...... | ||
0x000102f0 93070500 232ef4fc 8327c4fd 9bd7f741 ....#....'.....A | ||
0x00010300 2326f4fe 0327c4fd 8327c4fe b347f700 #&...'...'...G.. | ||
0x00010310 1b870700 8327c4fe bb07f740 9b870700 .....'.....@.... | ||
0x00010320 13850700 03348102 13010103 67800000 .....4......g... | ||
0x00010330 130101ff 23341100 23308100 13040101 ....#4..#0...... | ||
0x00010340 13055000 eff01ff5 b7070100 1385073a ..P............: | ||
0x00010350 eff01fda 13050000 eff0dff3 b7070100 ................ | ||
0x00010360 1385073a eff0dfd8 13055000 eff09ff2 ...:......P..... | ||
0x00010370 eff01fdd 13000000 83308100 03340100 .........0...4.. | ||
0x00010380 13010101 67800000 ....g... | ||
|
||
|
||
Hex dump of section '.rodata': | ||
0x00010388 30313233 34353637 38394142 43444546 0123456789ABCDEF | ||
0x00010398 00000000 00000000 2c2000 ........, . | ||
|