Assembly? why? why not?

Questions about programming languages and debugging
Post Reply
pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Assembly? why? why not?

Post by pseudo_opcode »

I m very surprised by the fact that how much people hate assembly.There have been lot of myths and misconceptions about assembly and high level languages,
Also most of the people wonder if assembly programs are really faster, smaller than their HLL(high level languages) counterparts.
Basically assembly is a low level language which is very close to machine language, which has its own set of rules.Every processor has its own instruction set, and the most common processor family we use is x86 (e.g. pentium) and AMD, more or less has the same instruction set.
When you write a program in any HLL, the compiler creates the equivalent code in assembly obviously after linking the required files and libraries.
Most of the people say that modern compilers can create code as efficient as assembly code, thats not completely true, it just depends upon the coder.
A compiler will always create the same code for same program, but if someone choses to directly write a program in assembly, he can really create highly optimized code.

The computers we use have RISC(reduced instruction set computer), the instructions are relatively fewer and simpler and in this all operations are done within the registers of CPU.

Also nowadays newer processors have more number of registers for advanced vector and floating point calculations, so if you still use the old compiler and most of the “robust” code wont utilize them, so you spend so much on your processor with cool features like hyper threading and dual core, it still functions like your previous one, without any significant performance boost, the reason is the software isnt optimized for your processor.

So if you know assembly and know exactly what you want and what all available resources you have, you can create much better programs, also you can tweak some of your programs for better performance.

Though like any other programming language, it takes a while for you to start writing efficient code, but surely its worth it.

A lot of people say that assembly is very hard. The fact is that it is not hard to learn, the only thing which makes it difficult to learn is the fact that you need to know your processor very well.
Basically if you want to code in assembly you need to learn all the available registers(including stack pointers, flags etc), you need to know the instruction set, addressing modes, and basic syntax of instructions and a general program.

Also the fact that assembly programs are not written similar to HLLs, makes it a little difficult.
So efficiency of a program depends upon the programmer. The modern compilers are very efficent but they cant beat human brain yet.
Also assembly gives you the power to crack programs, write shellcode, and create really small and fast keyloggers :P.
So i get the question, is assembly a good option for a begginer?
Well, assembly is really different from HLLs so if begginers want to learn a programming language they should not chose assembly but if they are interested in knowing more about there computer and how things work under the hood and not afraid of a little hard work, they should definitely go for assembly. However after assembly when you go on to HLLs, you'll say, omg thats so simple!!

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

Good read and good points =)
"The best place to hide a tree, is in a forest"

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Post by Gogeta70 »

I definately agree, pseudo. I've been debating whether to learn C++ again, or ASM, but i can't decide. Assembly gives me the power I want, but also lacks basic programming structure. Alongside of that, it also is pretty hard to find tutorials for assembly that don't use Windows API, which isn't what i want. I want to learn how assembly works, then implement WIndows (or linux?) API. With C++, it's a powerful programming language, but creates bulkier and somewhat slower programs.

So basically, i'm wanting the power of ASM, but the simplicity (in the terms of structure) of C++.

If i can find a good tutorial for ASM, then i'll happily start up on that again.
¯\_(ツ)_/¯ It works on my machine...

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

i have some good resources for asm for linux..like ebooks, if you want i can pm you the links.. you will also learn to debug your applications using gdb, last night.. while running the infamous game torcs on the linux, it had a segmentation violation, i was just working to inject some asm code to have fun.. just like you exploit buffer overflows in servers..lol, so learning asm can really be fun

Also i would like to point out, then at first asm seems like a bitch, but imagine every single thing running on your hardware is asm... just a few instructions can do so much.. the possibiliities are endless....
once you learn it well... you'll be addicted to it..lol

I've reached to a point where i can even write programs in binary..like 000 0101 etc...lol
As i've already said, its worth the hard work, but i would strongly recommend that you should know your processor really well..

User avatar
RNA
suck-o-fied!
suck-o-fied!
Posts: 95
Joined: 23 Nov 2006, 17:00
17
Location: A bit to the right of null
Contact:

Post by RNA »

I'll take ebooks :D Ive been collecting as many as I can

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Post by Gogeta70 »

Hell yeah man, i'll take the ebooks! Thanks a lot, dude!
¯\_(ツ)_/¯ It works on my machine...

User avatar
Nerdz
The Architect
The Architect
Posts: 1127
Joined: 15 Jun 2005, 16:00
18
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:

Post by Nerdz »

Same for me! If you want to... :)
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

alright.. i'll zip my favourite books and upload it somewhere? want hacking, security, exploiting, shellcoding books too? :-99

toast
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 188
Joined: 12 Aug 2006, 16:00
17
Contact:

Post by toast »

Omg, just to say- I LOVE ASM.

Its the cutest out of all lingos. And I can relate it to my mainframe programming. Even thought they are 2 different things.....

^.^ Toast

User avatar
RNA
suck-o-fied!
suck-o-fied!
Posts: 95
Joined: 23 Nov 2006, 17:00
17
Location: A bit to the right of null
Contact:

Post by RNA »

pseudo_opcode wrote:alright.. i'll zip my favourite books and upload it somewhere? want hacking, security, exploiting, shellcoding books too? :-99
I'll take any ebooks ya got :)

I'll never say no to something that might contain new information

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

toast wrote:Omg, just to say- I LOVE ASM.

Its the cutest out of all lingos. And I can relate it to my mainframe programming. Even thought they are 2 different things.....

^.^ Toast
lol i never knew that languages are cute too.. :D

User avatar
floodhound2
∑lectronic counselor
∑lectronic counselor
Posts: 2117
Joined: 03 Sep 2006, 16:00
17
Location: 127.0.0.1
Contact:

Post by floodhound2 »

Nice reading pseudo, but I want to make it clear that even assembly is compiled down to binary. Binary is the lowest level machine code you can reach, some of us use to code in binary. You can imagine how freaky it becomes when the world is all 1’s and 0’s.

Just know people that that the computer runs in binary and assembly needs to be compiled to binary.
₣£ΘΘĐĦΘŮŇĐ

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

since you mentioned binary, actually you cant use the word "compiled" assembly instructions are assembled.. (that's why they call the program assembler) where as compiling includes, linking of libraries and other files, and usually is a 3-4 stage process.
in assembly you have the binary equivalent of instructions and all, and some more little stuff.. (like indirect addresssing bit) and adressing modes...

Thats why i said assembly is very close to machine language and its not the machine language..
pseudo_opcode wrote:Basically assembly is a low level language which is very close to machine language,
Usually i've seen that sometimes the fact that assembly is architecture dependent scares off many people. But its not as complex as they think...

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Post by Gogeta70 »

Hey, pseudo, when are you going to PM those e-books? Not rushing you, i'm just curious...
¯\_(ツ)_/¯ It works on my machine...

User avatar
floodhound2
∑lectronic counselor
∑lectronic counselor
Posts: 2117
Joined: 03 Sep 2006, 16:00
17
Location: 127.0.0.1
Contact:

Post by floodhound2 »

I am not going to argue but assembly is compiled to binary.

I know for a fact that binary is the only thing a machine can run on. So it might not be labeled "compiled" but it is translated to binary. Yes assembly is written in hex but still needs to be converted and tweaked a little by the assembler.
₣£ΘΘĐĦΘŮŇĐ

Post Reply