
What is Assembly Language ?
Some Facts
The assembly programming language is a low level language, situated between a high level programming language, like Python for example, and the code machine. So, the high level programming code, is converted first to an assembly code then converted to code machine by an assembler.
The language uses mnemonics to represent the low level machine instructions, and it is usually used as the programming language for applications where speed is critical in general. Or for real time embedded systems in particular.
The assembly language is related to the architecture of the machine. So it is machine dependent, and it differs from an architecture to an other.
For example, there is the RISC, and the CISC architectures. For each of one of these, correspond an assembly language family:- CISC: Complex Instruction Set Computer Architecture. In this computer architecture (Instructions Set Architecure), the size of the assembly code will be small. This is possible because the processor is build in a way that enables the execution of complex instructions that are composed of multiple operations. But, the number of cycles per instructions will be high. One of the CISC families is the x86 architecture. And NASM (Netwide Assembler ), MASM (Microsoft Macro Assembler), and GAS (GNU Assembler) are assembly languages adapted for this class of architecture.
- RISC: Reduced Instruction Set Computer Architecture. In this architecture, the size of the assembly code will be large. This is caused by the fact that the processor is build in a way that let him execute only simple instructions that can be run on one clock cycle . As a good consequence, the number of cycles per instructions will be low. One of the RISC families is the MIPS architecture (Microprocessor without Interlocked Pipelined Stages ), to which correspond the MIPS assembly language.
How to install it
The assembly language I selected is the MIPS language. To later run our code, we are going to use MARS (MIPS Assembler and Runtime Simulator) IDE environment. Which is; as you may already gest it, an assembler and at the same time a runtime simulator. We are not going to install MARS, we will just run it. But, to be able to do so, you have to install Java first. You can go to our Java page to see how.
- on Windows:
To download MARS, just go to this MissouriState University page, and click on the Download Mars button. You will download a jar archive. Now, to run MARS, just double click on the file (assuming that Java is already installed on your machine)
- on ubuntu :
-
Same thing for Ubuntu, just go the same download page we saw in the installation for Windows, and click on the download button. But, after saving the downloaded jar file, do the following:
- Right click on it, and click on properties.
- Click on the permissions tab, then check the "Allow executing file as program" box.
- Now, click on the Open with tab, and select the Java runtime installed on your computer. In my case, it was the "OpenJDK Java 11 Runtime". After that, click on the Set as default button, and close the properties window.
- All you have to do now, is to double click on the download jar file to run it.
The Hello World Code
To write and run your MIPS code using MARS, do the following:
- After opening MARS by double clicking on it, click on New from the File menu.
-
Write the following code:
.data
out_string: .asciiz "\nHello World!\n"
.text
main:
li $v0, 4 #the operation code
la $a0, out_string #the operand
syscall #perform the operation
li $v0, 10
syscall
- Just to clarify something about the code. The prefixed lines with the hashtag(#) symbol are simply comments and not actual code.
- To save the code, click simply on Save, from the File menu, and write hello.asm in the File Name area. After that click on the Save button.
- To assemble the code, click on Assemble from the Run menu.
- To run the code, click on Go from the same Run menu. You will see the "Hello World!" message printed in the Run I/O bottom window.
Additional Information
For more information about the Erlang language and the corresponding code, you can check the following pages:
- RISC vs. CISC
- Computer Architecture and Assembly Language - Course Overview
- MIPS Assembly Overview
- Hello, World! in MIPS Assembly - Discover Coding
- Building Your First Simple Program With The MIPS Assembly Language – Sweetcode.io
- MIPS architecture - Wikipedia
- x86 Assembly Language Programming
- RISC vs. CISC Architectures: Which one is better?
Something to say ?
If you want to add something about the Assembly language or about this post, please feel free to do it by commenting below 🙂 .