Thursday, 6 October 2016

Technical Blog 2- Assembly and Assemblers

Introduction
Assembly is at its simplest the first computer programming language designed to be written by people. It generally translates to machine code on a one for one basis with very simple compilers called "assemblers" being used. The primary advantage of assembly over directly writing in machine code is the lack of requirement for remembering lots of long numerical codes for each action to be performed. Instead, assembly has a series of simple words which each correspond directly to a line of machine code. For example:
mov [2352], 245
For some assembly variants this small snippet of code tells the computer to transfer the number 245 to the memory location 2352. This is much more readable than the binary equivalent which is a simple string of ones and zeros. However this does translate directly to an operation in machine code which makes it very simple to assemble. This contrasts to the high-level programming languages people are used to today where the logic being written is far removed from the machine operations being performed and required large amounts of complex compiling to become readable by a computer.

The main advantage then that assembly has over machine code is a much greater ability to be written and read directly by people. The key though is that there is minimal downside. Assuming an assembler is available, you do not lose any of the control gained from programming directly in machine code which enables you to develop the incredibly tight and efficient programs associated with direct memory manipulation as discussed in my first post. This means that in any practical sense if that was desired, assembly would likely be as low-level as anyone would want to go.

History

Assembly of various forms was historically very quick to follow the development of computers. Even back when people  first began using computers machine code was considered finicky and highly impractical. The question that springs to my mind when considering this is how the first assemblers were created as surely they must have been written in machine code of some form. It turns out that the earliest assemblers were themselves written in assembly, they were just translated by hand into machine code. Due to the relative simplicity of translating assembly to machine code on a one to one basis, hand conversion was common when computers were such that machine code had to input directly, through punch cards or similar. This meant that programming time was split between writing the code in assembly and then translating it word for word into binary.

In the modern world of course, assemblers are well developed and commonly used to perform the final translations in a compiler to actually output the bit code to be read by the computer. In general these compilers are written in languages for different operating systems or processors than the code being assembled. This is known as cross-compiling and enables quick access from high-level languages to machine code without having to build up the assembler in machine code which often takes many iterations in which the next level of assembler has to be converted by the current assembler until an actually useful language is built up over time.

References
1. Landley R. Introduction to cross-compiling for Linux [Internet]. Landley.net. [cited 6 October 2016]. Available from: https://landley.net/writing/docs/cross-compiling.html

2. Fomin A. Introduction to Assembly Language [Internet]. Swansontec.com. 2001 [cited 6 October 2016]. Available from: http://www.swansontec.com/sprogram.html

No comments:

Post a Comment