Software Business Partners: .NET and C++ outsourcing company from Romania
 

The lost art of Assembly Programming

Sep 08, 2014 by AdrianC

Assembly is a low-level programming language for a computer or any other programmable device, which has a very strong (generally one-to-one) correspondence with the machine language instructions (basically, the programmer speaks with the device by using the device’s language).

Each assembly language is specific to a particular computer architecture, in contrast to most high-level programming languages, which are generally portable across multiple architectures.

Programming in Assembly

Writing code in assembly is way harder than in any other programming language, it takes way more time to write and it's not "forgiving" at all, any mistake will have a great impact on the code's execution. Take a peek below, where you'll see the Hello World! program written in Assembly, and the same program written in the Java language. It's obvious which of the two is the more complicated one, right?!

 

class HelloWorldApp {
	public static void main(String[] args) {
		System.out.println("Hello World!");
	}
}

vs.
 

section    .text
global 	   _start			;must be declared for linker (ld)

_start:				        ;tell linker entry point

    mov	  edx,len			;message length
    mov   ecx,msg			;message to write
    mov	  ebx,1				;file descriptor (stdout)
    mov	  eax,4				;system call number (sys_write)
    int	  0x80				;call kernel
	
    mov   eax,1				;system call number (sys_exit)
    int   0x80				;call kernel
	
section	  .data

msg   db 'Hello, world!',0xa            ;our dear string
len   equ $ - msg			;length of our dear string

The term "Assembly" seems very high-tech and scary, but don't be fearful, in reality the assembly language is more complicated than the term suggests :). But knowing this programming language is a must for compiler writers, and a good feat for all programmers who want to be skillful debuggers, or who are especially interested in code performance and efficiency.

Anyone who works with compiler design, binary arithmetic, memory allocation or character set encoding (and wants to go more in depth with this) has to take into consideration the assembly language, because it offers insight on how a computer works at hardware level. Also, this programming language will increase the programmer's knowledge about the inner workings of computers (things such as how the CPU/CPU registers work with memory addresses).

Where is the Assembly language being used?

Some may ask: why use assembly when we've got… Java (fast execution and easy programming) for example? I agree with easy programming, but I must disagree with fast execution. In this regard, no programming language can beat assembly, except coding by using 0 and 1, but good luck with that!

These are only a few areas were the assembly language is still being used:

  • A stand-alone executable that will execute without recourse to the run-time components, used in: automobile fuel and ignition systems, firmware for telephones, security systems, air-conditioning control systems
  • Code used in direct interaction with the hardware (device drivers or interrupt handlers)
  • Software that requires extreme optimization (an inner loop in a processor-intensive algorithm). In this category I'd like to mention game programming, which greatly benefits from assembly programming (if done well, of course!). Another area is the one of scientific simulation, which really needs highly optimized algorithms
  • Software which needs precise timing, software such as simulations, flight navigation systems, and medical equipment
  • Computer viruses, boot loaders, device drivers and items close to the low-level operating system or hardware
  • etc.

Considering that there are so many areas which are in need of this programming language, asking how long it is going to stick with us is like asking "how much time are computers going to be around?"... but we all know the answer to this. As long as there are device drivers and firmware to develop, software which needs precise timing or other high-performance software, programmers who know assembly will always find something to work on.

Have you ever tried programming using assembly language? If yes, what was your experience?


Tags: Programming 


Comments


mike commented on 9/17/2014 7:58:37 AM

>no programming language can beat assembly

Do you know how good c-compilers are these days ? It takes a damn good asm progammer to beat a c-compiler these days.
     

Adrian commented on 9/22/2014 9:49:47 AM

Compilers have improved over the years, however, when you develop an application written in C, when extra tweaks and speed improvements in specific areas of the code are needed, some programmers will still use assembly.
     

RobIII commented on 9/17/2014 8:24:49 AM

"I agree with easy programming, but I must disagree with fast execution. In this regard, no programming language can beat assembly, except coding by using 0 and 1, but good luck with that!"

There's no black-and-white; there is a whole lot of gray areas in-between. Some compilers / runtimes / interpreters can optimize for specific pipelines, caches, branch prediction and what-have-you's in CPU's that no sane human being would be able to 'foresee' when 'developing' an application in assembly. Sure, pure assembly wins over any language but not the hand-written (or hand-coded) type. Not always at least.
     

Adrian commented on 9/22/2014 9:50:05 AM

I agree with you, that’s why assembly is not used so often, for most times the effort is not worth it.
     

Madhur commented on 9/17/2014 9:12:34 AM

It is not lost. People still use it. Ask any game developer.

It's just that its use have been limited to game dev and system programming. Its not used any more in application development.

Have a look at http://masm32.com/
     

Adrian commented on 9/22/2014 9:50:59 AM

"It's just that its use have been limited to game dev and system programming." – And even in this areas, assembly is not being used very frequently, that’s why it has become a lost art.
     

Your Comment:






Blog Home   SBP Home
RSS Feed       Contact








 Blog Archives  |  Terms of Use  |  Privacy Policy
© 2017 SBP Romania. All rights reserved.