Feeds:
Posts
Comments

Archive for the ‘Programming in Linux’ Category

What is method?
In programming language, method is something that you do to an object.

For example, the object is ‘door‘ and you want to apply an action ‘open‘.

In python you can write as: door.open().

door = object

open = method

( ) = argument

Argument is the place for parameters that you apply to the method.

For example, you want to open your door half only or full open then changing the color painting to blue or red.

The syntax will be:

door.open(‘half)

door.open(‘full‘)

door.color(‘blue‘)

door.color(‘red‘)
In python, you can use built-in methods or create it manually.

Let me explain more details.
(more…)

Read Full Post »

If Statement is a conditional that python will check before taking a new action. If statement result is TRUE, python will process the command given otherwise it will ignore and execute the next step.

The syntax is:
if statement:
your_command

Let’s try.
—————————————————————
>>> myprogramming_language=’python’
>>> if myprogramming_language==’python’:
print “Python is my programming language”

Python is my programming language
>>>
—————————————————————

myprogramming_language=’python’ will tell python, please enter variable myprogramming_language with value python.

if myprogramming_language==’python’: will tell python, if myprogramming_language is equal with ‘python’ then execute the next line, otherwise just ignore and continue to the next step.

If it’s equal mean the condition is True.

If it’s not equal the condition is False.


(more…)

Read Full Post »

Strings is one or more combination of alphabet. Python will recognize double colon(“ ”) or single colon (‘ ‘) for string declaration.

For example, to declare ‘This is a string‘ as string, you can use double colon or single colon.

——————————-
>>> “This is a string”
‘This is a string’
>>> ‘This is a string’
‘This is a string’
>>>
——————————-

Very easy. How about to write Hii… I’m python. There is one single colon in the string.

You can’t write, ‘Hi.. I’m python’ because python will confuse to set the beginning and the end of the string because single colon in (I’m) will consider as end of string content.
——————————-
>>> “I’m python”
“I’m python”
>>> ‘I’m python’
SyntaxError: invalid syntax
>>>

But, with “double colon is fine.

——————————-
>>> “I’m python”
“I’m python”
——————————-

(more…)

Read Full Post »

Function is a built-in program that available in Python that we can use to simplify our programming code. Mostly every programming language provide their built-in function according to purpose why it’s created. Functions in C, python, pearl, vb, assembly will be different.

To use function in python, you have to write the function name then followed by the parameters that the function need. Parameter is the information that will be used by function to solve the problem.

Built-in Functions:
abs(), divmod(), input(), open(), staticmethod(), all(), enumerate(), int(), ord(), str(), any(), eval() isinstance(), pow(), sum(), basestring(), execfile(), issubclass(), print(), super(), bin(), file(), iter(), property(), tuple(), bool(), filter()
,len(), range(), type(), bytearray(), float(), list(), raw_input(), unichr(), callable(), format(), locals(), reduce(), unicode(), chr(), frozenset(), long(), reload(), vars(), classmethod(), getattr(), map(), repr(), xrange(), cmp(), globals(), max(), reversed(), zip(), compile(), hasattr(), memoryview(), round(), __import__(), complex(), hash(), min(), set(), apply(), delattr(), help(), next(), setattr(), buffer(), dict(), hex(), object(), slice(), coerce(), dir(), id(), oct(), sorted(), intern()

(more…)

Read Full Post »

Input is the entering data into the program and variable is temporary place for storing the data. There are 2 data that you can enter, string and number.

See the sample variables below:

a=12345

b=”I’m python

a is number and b is string.

 

See the sample input below:

my_string=raw_input(“What is your name?”)

my_number=input(“Enter your number?”)

raw_input() function will give a string and input() function will give a number.

 

Now, let’s try directly in the idle.

Open Idle editor.

Select File > New Window.

 

In the new window, type the codes below:
__________________________________________

print “Welcome to Python”

print “—————–”

print “”

s=raw_input(“Please, enter your name? “)

print “Hi..”,s,” Nice to meet you”

n=input(“Please, enter your favorite number? “)

print “Your favorite number + 3 =”,n+3
__________________________________________

In the ‘New window’, select ‘Run > Run Module‘.

If there is no error, you will see the result in the Idle main screen.

Read Full Post »

What is Python?

Python is a dynamic programming language that combine great power with very clear syntax. Guido Van Rossum began to work with python in late 1980 at National Research Institute for Mathematics and Computer science in Netherland (CWI). Before I read the history, I though it came from name of snake. But I was wrong. Guido named it when he saw ‘Monthy Python’s Flying Circus‘ comedy TV show in BBC.


Write your own first syntax

Well, no need to explain more details about python, you can find it in the Internet. Just let’s start.
Open Linux Terminal (Applications > Accessories > Terminal) then type: python.
You will get ‘>>>>’ prompt. It’s mean that python is ready to get any commands.

(more…)

Read Full Post »

At about 22 years ago, Assembly Language is my second language after BASICA. I used Borland Turbo Assembler and Microsoft Debug on that time. I think Debug one of the very powerful tools for hacking. I like hacking. With Assembly, you can order the machine to do anything you want and go directly to every ports in the machine.

I just figure out, is there any Assembly Language in Linux?

Because, usually Assembly Language use DOS Services. Meanwhile, there is no DOS in Linux.

I finally found a good application, named NASM (Net wide Assembler). It’s a Assembly Language compiler in Linux. I’m still new with NASM, so I just take the sample codes from http://leto.net/writing/nasm.php.

NASM doesn’t have a text editor, so you have to type your code using other text editor then save the file with .asm file extension.

There are few main differences to be considered when you use assembly language in Linux:

  • In DOS mostly you use interrupt int 21h, int 10h and int 16h. In Linux, everything is handled by kernel with int 80h.

  • Linux is a 32-bit protected mode operating system, so you have to use extended 32-bit registers, such as EAX, EBX, ECX and so on. In 16-bit register, you still use AX, BX,CX etc …. registers.

  • In 32-bit programming, you don’t have to think about segments at all because it runs in the flat memory model.

  • I think no body write DOS assembly anymore. Hey… it’s 16 bit.

How I can get Nasm?

NASM is listed in Ubuntu Repository, so just download it using apt.

taufanlubis@toshiba:~$ sudo apt-get install nasm

[sudo] password for taufanlubis:

Reading package lists… Done

Building dependency tree

Reading state information… Done

The following packages were automatically installed and are no longer required:

mplayer-skins mplayer libggi2 libgii1 libgii1-target-x youtube-dl

Use ‘apt-get autoremove’ to remove them.

The following NEW packages will be installed:

nasm

0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.

Need to get 1557kB of archives.

After unpacking 2855kB of additional disk space will be used.

Get:1 http://archive.ubuntu.com gutsy/main nasm 0.98.38-1.2build1 [1557kB]

Fetched 1557kB in 36s (42.8kB/s)

Selecting previously deselected package nasm.

(Reading database … 126048 files and directories currently installed.)

Unpacking nasm (from …/nasm_0.98.38-1.2build1_i386.deb) …

Setting up nasm (0.98.38-1.2build1) …

taufanlubis@toshiba:~$

Write your first Linux Assembly Language Application

When I learn a new computer language, the first thing I want to know is, how to display a ‘Hello World!!!’. I don’t want to know about the structure, variables, codes etc. Just do a simple thing, type, compile and see it run. That’s it. Then you can go further. It’s the same when you teach a baby to speak. We don’t teach any grammar. We give samples.

So, here it is.

Step 1. Type the code

You can use, vim, vi, gedit etc. The extension must be .asm.

taufanlubis@toshiba:~$ sudo vim hello.asm

[sudo] password for taufanlubis:

section .data

hello: db ‘Hello world!’,10

helloLen: equ $-hello

section .text

global _start

_start:

mov eax,4

mov ebx,1

mov ecx,hello

mov edx,helloLen

int 80h

mov eax,1

mov ebx,0

int 80h

Press ‘Esc‘ button and type ‘:wq‘ to save the file.

Actually, I’m new myself in Assembly Programming in Linux. I took the codes above from the NASM website. I just wanna show you that we can do Assembly Programming in Linux. If you want to know deeper you can go

to this link: ……………………..

Step 2. Compile .asm (source code) to .o (object)

taufanlubis@toshiba:~$ nasm -f elf hello.asm

Step 3. Link the object file to produce an executable file.

taufanlubis@toshiba:~$ ld -s -o hello hello.o

Now, you have 3 files, hello.asm (your source code), hello.o (your object file) and hello (your program).

taufanlubis@toshiba:~$ ls -l hello*

-rwxr-xr-x 1 taufanlubis taufanlubis 440 2008-01-17 20:38 hello

-rw-r–r– 1 root root 203 2008-01-17 20:33 hello.asm

-rw-r–r– 1 taufanlubis taufanlubis 736 2008-01-17 20:37 hello.o

Step 3. Ready to run

You can run your program by typing:

taufanlubis@toshiba:~$ ./hello

Hello world!

taufanlubis@toshiba:~$

Congratulations! You have just written your first assembly program in Linux.

If you want to know more details about nasm and ld, you can see the manual.

taufanlubis@toshiba:~$ man ld

taufanlubis@toshiba:~$ man nasm

 

 

Read Full Post »

Follow

Get every new post delivered to your Inbox.

Join 69 other followers