section .data
hello: db 'Hello world!',10 ; 'Hello world!' plus a linefeed character
helloLen: equ $-hello ; Length of the 'Hello world!' string
section .text
global _start
_start:
mov ecx,5 ; display the string 5 times_loop:Steps:
mov eax,4 ; The system call for write (sys_write)
mov ebx,1 ; File descriptor 1 - standard output
push ecx ; save ecx as it is gonna be used as param to sys_write
mov ecx,hello ; Put the offset of hello in ecx
mov edx,helloLen ; helloLen is a constant, so we don't need to say
; mov edx,[helloLen] to get it's actual value
int 80h ; Call the kernel
pop ecx ; restore ecx (counter)
loop _loop
mov eax,1 ; The system call for exit (sys_exit)
mov ebx,0 ; Exit with return code of 0 (no error)
int 80h
- Save the file as syscall.asm
- Execute: nasm -f elf syscall.asm
- Execute: ld -s -o syscall syscall.o
- run it as: ./syscall
- To check the object file, we can use objdump, elfdump, or readelf. For example:
$ readelf -a ./syscall.o
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 64 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 7
Section header string table index: 3
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .data PROGBITS 00000000 000160 00000d 00 WA 0 0 4
[ 2] .text PROGBITS 00000000 000170 00002b 00 AX 0 0 16
[ 3] .shstrtab STRTAB 00000000 0001a0 000031 00 0 0 1
[ 4] .symtab SYMTAB 00000000 0001e0 000080 10 5 7 4
[ 5] .strtab STRTAB 00000000 000260 000029 00 0 0 1
[ 6] .rel.text REL 00000000 000290 000008 08 4 2 4
$ readelf -a ./syscall.o
ELF Header:s:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32unknown)
Data: 2's complement, little endianpecific)
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: Intel 80386
Version: 0x1 0x290 contains 1 entries:
Entry point address: 0x0Value Sym. Name
Start of program headers: 0 (bytes into file)
Start of section headers: 64 (bytes into file)
Flags: 0x0e.
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0Vis Ndx Name
Size of section headers: 40 (bytes)UND
Number of section headers: 7DEFAULT ABS syscall.asm
Section header string table index: 3DEFAULT 1
3: 00000000 0 SECTION LOCAL DEFAULT 2
Section Headers: 0 NOTYPE LOCAL DEFAULT 1 hello
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .data PROGBITS 00000000 000160 00000d 00 WA 0 0 4
[ 2] .text PROGBITS 00000000 000170 00002b 00 AX 0 0 16
[ 3] .shstrtab STRTAB 00000000 0001a0 000031 00 0 0 1
[ 4] .symtab SYMTAB 00000000 0001e0 000080 10 5 7 4
[ 5] .strtab STRTAB 00000000 000260 000029 00 0 0 1
[ 6] .rel.text REL 00000000 000290 000008 08 4 2 4
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
There are no program headers in this file.
Relocation section '.rel.text' at offset 0x290 contains 1 entries:
Offset Info Type Sym.Value Sym. Name
00000011 00000201 R_386_32 00000000 .data
There are no unwind sections in this file.
Symbol table '.symtab' contains 8 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 FILE LOCAL DEFAULT ABS syscall.asm
2: 00000000 0 SECTION LOCAL DEFAULT 1
3: 00000000 0 SECTION LOCAL DEFAULT 2
4: 00000000 0 NOTYPE LOCAL DEFAULT 1 hello
5: 0000000d 0 NOTYPE LOCAL DEFAULT ABS helloLen
6: 00000005 0 NOTYPE LOCAL DEFAULT 2 _loop
7: 00000000 0 NOTYPE GLOBAL DEFAULT 2 _start
No version information found in this file.
Monday, August 8, 2011
Assembly in Linux
Tuesday, July 5, 2011
Relacing OpenJDK with Oracle/Sun Java SDK as default java
- Download the SDK from here
- Install the SDK. For example: sudo rpm -Uvih <sdk rpmfile> or sudo sh ./<sdk bin file>
- Once it is installed, copy-paste the following script and execute it
#!/bin/sh
for FP in /usr/java/default/bin/* ; do
NAME=${FP##*/}
echo installing $NAME
sudo alternatives --install /usr/bin/${NAME} ${NAME} /usr/java/default/bin/${NAME} 20000
alternatives --display "${NAME}" | grep "${NAME}"
done
Sunday, June 12, 2011
New Nook v.s. Amazon Kindle
For the resolution, Kindle is tad better. This is based on my visual check by starring at each screen very closely (I got to remove my glasses to get better visual). Letters on Kindle are darker and smoother (but not much better), but Nook screen is whiter. Screen refresh rate (refresh between page) is faster on the Nook. Page buttons are located the same as Kindle (page-up and page-down are on left and right edge of the body). For the weight, I guess Kindle is slightly lighter on my hand, but it's hard to make a correct and accurate judgment without put them on scale.
Something interesting is the power life. Nook is apparently is the winner, at least according to the sales person. It can last up to 2 months with Wi-Fi turned off, while on Kindle is about a month. Price wise, Kindle is a bit cheaper, especially if we're OK with ads-supplied screen-saver version of it. On Amazon website, the ads-supported version is $114 (with no sales tax if we buy from California, and no shipping cost), while the Nook is $139 + sales tax. The web browser on Nook is better.
For the collection of books available, Amazon seems has little bit more selection, but B&N is catching up quickly too. A feature that's not available on Kindle is "Rent" and "Read in store", and this would make Nook very appealing for some users who want to borrow a book from friend or just want to read a book in B&N store (although not all e-books can be read or rented). I hope Amazon will match it with the similar offering. Nook is also EPUB-compatible reader, while Amazon's Kindle uses a proprietary format (Mobile-pocket-based MOBI format with DRM added). While many books can be converted with a tool such as Calibre (EPUB to MOBI and vice versa), others are nonconvertible.
Internally, they both are based on Linux, although Nook is Android-base. No surprise the Nook is faster because it uses more recent hardware, while Kindle has been a year old in the market. I think Amazon is preparing a next gen one. Just wait and see a couple of months as rumors say the will introduce the new one. The rumor also says Kindle might have a touch screen too (some people in the internet forum wish Amazon not to arm it with a touch screen. I don't understand what's the reason behind it yet).
Overall, I guess they tie in many comparisons. Only our preferences can tell which one to buy. If I haven't had Kindle, I might buy this new Nook because it's cute (very portable and almost fit in my shirt pocket) and has some features not available on Kindle.
=-=-=-=-=
Powered by Blogilo
Thursday, June 9, 2011
Fedora 15 & GNOME 3 Crash.
The problem is that GNOME3 is not stable enough to be run on some machines/video cards with 3D (perhaps Nouveau driver unable to execute 100% of the required GNOME3 features?). Some people in the Internet said that by executing the following command it should fix the issue, but not in my case:
After googling around, I found a good solution:
This has fixed my GNOME problem. I could now login to the fallback mode (GNOME2-like)
Wednesday, May 25, 2011
PlayList format and translation
Sandisk Sansa mp3 player may have playlists of mp3 files. These files are stored in \PLAYLIST.
The format of playlist is actullay in UTF-16LE. In order to translate it to an ASCII (UTF-8) format, we can use a command line tool in Unix/Linux (available in Cygwin for Windows too).
Here's an example how to convert a playlist to a text format:
bash-3.2$ iconv -f UTF-16LE -t UTF-8 playlist.pla
PLP PLAYLIST
VERSION 1.20
HARP, MUSIC\James Blunt\All The Lost Souls\10_-_i_can't_hear_the_music_-_all_the_lost_souls.mp3
HARP, MUSIC\James Blunt\All The Lost Souls\09_-_annie_-_all_the_lost_souls.mp3
HARP, MUSIC\James Blunt\All The Lost Souls\04_-_same_mistake_-_all_the_lost_souls.mp3
HARP, MUSIC\James Blunt\All The Lost Souls\01_-_1973_-_all_the_lost_souls.mp3
HARP, MUSIC\Queen\Queen - Greatest Hits Cd1\01_-_bohemian_rhapsody_-_queen_-_greatest_hits_cd1.mp3
HARP, MUSIC\Queen\Queen - Greatest Hits Cd1\05_-_bicycle_race_-_queen_-_greatest_hits_cd1.mp3
HARP, MUSIC\Queen\Queen - Greatest Hits Cd1\16_-_we_will_rock_you_-_queen_-_greatest_hits_cd1.mp3
HARP, MUSIC\Queen\Queen - Greatest Hits Cd1\17_-_we_are_the_champions_-_queen_-_greatest_hits_cd1.mp3
HARP, MUSIC\Queen\Queen - Greatest Hits Cd2\07_-_it's_a_hard_life_-_queen_-_greatest_hits_cd2.mp3
HARP, MUSIC\Queen\Queen - Greatest Hits Cd2\11_-_the_miracle_-_queen_-_greatest_hits_cd2.mp3
HARP, MUSIC\Queen\Queen - Greatest Hits Cd2\15_-_friends_will_be_friends_-_queen_-_greatest_hits_cd2.mp3
HARP, MUSIC\Queen\Queen - Greatest Hits Cd2\16_-_the_show_must_go_on_-_queen_-_greatest_hits_cd2.mp3
HARP, MUSIC\Eric Clapton\Unplugged\07_-_layla_-_unplugged.mp3
HARP, MUSIC\Rihanna\Good Girl Gone Bad\{1]03_-_don't_stop_the_music_-_good_girl_gone_bad.mp3
HARP, MUSIC\OneRepublic\Dreaming Out Loud\{1]03_-_stop_and_stare_-_dreaming_out_loud.mp3
HARP, MUSIC\Colbie Caillat\Coco\{1]07_-_realize_-_coco.mp3
HARP, MUSIC\Timbaland\Shock Value\{1]16_-_apologize_(feat._one_republic)_-_shock_value.mp3
HARP, MUSIC\Ennio Morricone\Kill Bill Vol.2\03_-_il_tramanto_-_kill_bill_vol.2.mp3
HARP, MUSIC\Charlie Feathers\Kill Bill Vol.2\04_-_cant_hardly_stand_it_-_kill_bill_vol.2.mp3
HARP, MUSIC\Lole Y Manuel\Kill Bill Vol.2\05_-_tu_mira_(edit)_-_kill_bill_vol.2.mp3
HARP, MUSIC\Luis Bacalov\Kill Bill Vol.2\06_-_summertime_killer_-_kill_bill_vol.2.mp3
HARP, MUSIC\Alan Reeves Phil Steele And P\Kill Bill Vol.2\07_-_the_chase_-_kill_bill_vol.2.mp3
HARP, MUSIC\Ennio Morricone\Kill Bill Vol.2\09_-_l_arena_-_kill_bill_vol.2.mp3
HARP, MUSIC\Malcolm Mclaren\Kill Bill Vol.2\12_-_about_her_-_kill_bill_vol.2.mp3
HARP, MUSIC\Chingon\Kill Bill Vol.2\14_-_malaguena_salerosa_-_kill_bill_vol.2.mp3
HARP, MUSIC\Meiko Kaji\Kill Bill Vol.2\15_-_urami_bushi_-_kill_bill_vol.2.mp3
bash-3.2$
To create a playlist, we just reverse the format and redirect the output to a file (with extension pla) and then copy the generated file to Sansa's PLAYLIST folder. Just to remember, the path of each file is relative to MUSIC folder.
Tuesday, May 24, 2011
Script to find latitude and longitude
#!/bin/sh
converter="http://api.maps.yahoo.com/ajax/geocode?appid=onestep&qt=1&id=m&qs="
addr="$(echo $1 | sed 's/ /+/g')"
values="$(curl -s $converter$addr | cut -d\" -f13,15 |sed 's/[^0-9\.\,\-]//g; s/,$//')"
lat1=$(echo $values | cut -d, -f1)
long1=$(echo $values | cut -d, -f2)
echo "Lat=$lat1"
echo "Long=$long1"
(Save the above script to file and chmod to be executable).
For example:
>latlong 1465 mcdowell blvd, petaluma ca 94954
Lat=-33.869629
Long=151.206955
Tuesday, May 3, 2011
iMac v.s. AsusTek All-in-One PC
Price: $1,719.26 at 2020pc.com (free shipping + no tax)
| General | |
| Type | Personal computer |
| Product Form Factor | All-in-one |
| Built-in Devices | Touch screen |
| Width | 22.9 in |
| Depth | 2 in |
| Height | 19.5 in |
| Weight | 28.7 lbs |
| Color | Black |
| Bundled with | 3D glasses |
| Processor | |
| Type | Intel Core i7 740QM / 1.73 GHz |
| Multi-Core Technology | Quad-Core |
| 64-bit Computing | Yes |
| Installed Qty | 1 |
| Max Supported Qty | 1 |
| Mainboard | |
| Chipset Type | Mobile Intel HM55 Express |
| RAM | |
| Installed Size | 8 GB / 8 GB (max) |
| Technology | DDR3 SDRAM |
| Memory Speed | 1333 MHz |
| Form Factor | SO DIMM 204-pin |
| Configuration Features | 4 x 2 GB |
| Storage Controller | |
| Type | 1 x Serial ATA - integrated |
| Controller Interface Type | Serial ATA-300 |
| Storage | |
| Hard Drive | 1 x 1 TB - standard - Serial ATA-300 - 7200 rpm |
| Optical Storage | |
| Type | DVD-Writer / BD-ROM |
| Card Reader | |
| Type | Card reader |
| Supported Flash Memory Cards | SD Memory Card, SDXC Memory Card |
| Monitor | |
| Monitor Type | LCD display - 3D Ready - TFT active matrix - Multi-Touch |
| Diagonal Size | 23.6" |
| Max Resolution | 1920 x 1080 ( Full HD ) |
| Widescreen Display | Yes |
| Image Aspect Ratio | 16:9 |
| Graphics Controller | |
| Type | Plug-in card |
| Graphics Processor / Vendor | NVIDIA GeForce GTX 460M |
| Video Memory | 1.5 GB |
| Digital Video Standard | High-Definition Multimedia Interface (HDMI) |
| Multimedia Functionality | |
| TV Tuner Type | Digital TV |
| Digital TV Reception | ATSC |
| Audio Output | |
| Type | Sound card |
| Sound Output Mode | Stereo |
| Camera | |
| Form Factor | Integrated |
| Sensor Resolution | 1.3 Megapixel |
| Input Device | |
| Type | Mouse, keyboard |
| Keyboard | |
| Connectivity | Wireless |
| Mouse | |
| Connectivity | Wireless |
| Audio Input | |
| Type | Microphone |
| Networking | |
| Networking | Network adapter |
| Wireless LAN Supported | Yes |
| Data Link Protocol | Ethernet, Fast Ethernet, Gigabit Ethernet, IEEE 802.11b, IEEE 802.11g, IEEE 802.11n, Bluetooth 3.0 |
| Compliant Standards | IEEE 802.11b, IEEE 802.11g, IEEE 802.11n, Bluetooth 3.0 |
| Expansion / Connectivity | |
| Expansion Bays Total (Free) | Internal - 3.5" |
| Expansion Slots Total (Free) | 1 ( 0 ) x processor 4 ( 0 ) x memory - SO DIMM 204-pin |
| Interfaces | 4 x Hi-Speed USB - 4 pin USB Type A 1 x network - Ethernet 10Base-T/100Base-TX/1000Base-T - RJ-45 2 x SuperSpeed USB - 9 pin USB Type A 1 x microphone - input - mini-phone 3.5 mm 1 x headphones - output - mini-phone stereo 3.5 mm 1 x display / video - VGA input - 15 pin HD D-Sub (HD-15) 1 x audio / video - HDMI - 19 pin HDMI Type A 1 x display / video - TV-in |
| Miscellaneous | |
| Included Accessories | Remote control |
| Features | ASUS Super Hybrid Engine, ASUS SonicMaster |
| Power | |
| Device Type | Power adapter |
| Power Provided | 230 Watt |
| Operating System / Software | |
| OS Provided | Microsoft Windows 7 Home Premium 64-bit Edition |
| Microsoft Office Preloaded | Includes a pre-loaded image of select Microsoft Office 2010 suites. Purchase an Office 2010 Product Key Card or disc to activate preloaded software on this PC. |
| Environmental Standards | |
| ENERGY STAR Qualified | Yes |
| Manufacturer Warranty | |
| Service & Support | 1 year warranty |
| Service & Support Details | Limited warranty - 1 year |
| Universal Product Identifiers | |
| Brand | ASUSTeK COMPUTER |
| Part Number | ET2400XVT-B011E |
| GTIN | 00610839324255 |
Advantage: USB-3
21.5-inch iMac
- $1,899.00 at Apple Store/online (free shipping, but there's sales tax)
- $100 discount for students
21.5-inch iMac
- Ships: 1-3 business days
- Part number: Z0M5
- 2.8GHz Quad-Core Intel Core i7
- 8GB 1333MHz DDR3 SDRAM - 2x4GB
- 1TB Serial ATA Drive
- AMD Radeon HD 6770M 512MB GDDR5
- Apple Magic Mouse
- Apple Wireless Keyboard (English) & User's Guide
- Accessory Kit
At the end, almost-apple-to-apple comparison (for students) is: 1799+167.11% (CA sales tax) - 1719.25 = 1966.11 - about $250 difference (that's more than the cost for 2 TB USB-3.0 external Hard Drive )