in black and white
Main menu
Home About us Share a book
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

Linux for dummies - Klimas M.

Klimas M. Linux for dummies - Wiley publishing , 2002. - 169 p.
Download (direct link): linuxfordummies2002.pdf
Previous << 1 .. .. 104106 107 108 109 110 111 < 112 > 113 114 115 116 117

Linux Newbie Guide by Stan, Peter and Marie Klimas 01/08/2003
dRadius = dDiameter * 0.5;
dDrop = dRadius - sqrt( (dRadius*dRadius)-(0.25*dGap*dGap) );
return (dDrop);
} //end of the function
//The function main is the entry point to the program void main(void) {
double dGap, dDiameter, dDrop, dRadius, dNotDrop; //variables
for (;;) { //infinite loop
cout << "Please enter gap between track segments and \n"
<< "diameter of train wheel in inches (-1 -1 to exit): "; cin >> dGap >> dDiameter;
if ((dGap == -1) && (dDiameter == -1)) break;
else if (dGap < dDiameter) { //do calculations dDrop = wheeldrop (dGap, dDiameter);
printf ("The wheel will drop %f inches.\n\n", dDrop);
else {
printf ("Error, your train is going to crash.\n Gap bigger then wheel!\n\n");
I save the source to the file "train.c", and then invoke the GNU C++ compiler to compile the file "train.c" to an
executable called "traincalc":
g++ -o traincalc train.c
I can then run the executable by typing:
(type in X-terminal) Integrated development environment for K. It is really worth downloading (if it does not come with your distribution).
(type in X-terminal) A graphical builder of user interfaces.
"Glade is an interface builder developed by Damon Chaplin. It allows graphical and interactive construction of Gnome/Gtk graphical user interfaces. From Glade, the generated interface can be saved in a xml file or directly exported to C code to be included in a C source tree. Glade also allows to define the name of the handlers -functions - to be attached to the various event of the interface. For example the function (name) to be called when a specific menu item is pressed." (From:
What "C" functions are available for programming under Linux?
Too many for a newbie like myself. I started by studying the header files (*.h) in the directory /usr/include and all its subdirectories. To find a header file that contains a prototype for a given function (e.g., cosh) I would do something like:
cd /usr/include grep -H "cosh" *.h
There are also many interesting libraries that are not a part of a typical distribution, e.g., GNU libraries for scientific computing (GSL): Also check:
(3 commands). Assembler, an alternative "native assembler" and a disassembler. Send in your newbie examples how to use those :)
Part 7: Learning with Linux
Linux Newbie Guide by Stan, Peter and Marie Klimas
E.g.: ndisasm /bin/sh |more produces a long output of "assembler mnemonics" from a binary on my system (/bin/sh in this example) but I cannot understand it anyway :( To learn more about nasm, you may want to see: file:///usr/share/doc/nasm-doc-0.98/html/nasmdoc0.html
Example Intel assembly for Linux 2.2.17 or higher:
;; hello.asm: Copyright (C) 2001 by Brian Raiter, under the GNU ;; General Public License (version 2 or later). No warranty.
org 0x05936000
db 0x7F, "ELF"
dd 1
dd 0
dd $$
dw 2
dw 3
start: inc eax ; 1 == exit syscall no.
mov dl, 13 ; set edx to length of message
cmp al, _start - $$
pusha ; save eax and ebx
xchg eax, ebx ; set ebx to 1 (stdout)
add eax, dword 4 ; 4 == write syscall no.
mov ecx, msg ; point ecx at message
int 0x80 ; eax = write(ebx, ecx, edx)
popa ; set eax to 1 and ebx to 0
int 0x80 ; exit(bl)
dw 0x20
dw 1
msg: db 'hello, world', 10
After saving this to a plain-text file hello.asm, I can build it to an output file "hello" and make the output executable using the command:
nasm -f bin -o hello hello.asm && chmod +x hello
and execute it using:
The example above is borrowed from
Why would somebody use assembler? After building from assemebler, this example executable is 56 bytes on my system. The "C" language example with identical functionality (see one page above) is 13.7 kB.
Here is brief info to help me understand the above program:
";" marks comments (to the end of the line).
"msg:" — is an example of a label (like in fortan).
org (="origin")--declares where in the memory the program begins (after it is loaded to memory for execution). db, dd, dw are nasm "pseudoinstructions" used to insert initialized data into the output file.
"$" evaluates to the assembly position at the beginning of the line containing the expression; so you can code an infinite loop using "JMP $". "$$" evaluates to the beginning of the current section.
The general-purpose 32-bit registers in the 80x86 ("Intel") processor are: EAX, EBX, ECX, EDX, ESI, EDI, EBP, and ESP. (The "E" stands for extended. It is there because the processor can instead "overlay" the registers and treat them as 16-bit registers with names: AX, BX, CX, CX, SI, DI, BP, and SP. Still underlying those, there are also eight 8-bit registeres: AL, AH, BL, BH, CL, CH, DL, DH. Here, the "L" and "H" stand for "high" and "low" byte.).
Previous << 1 .. .. 104106 107 108 109 110 111 < 112 > 113 114 115 116 117