Low-level learning — “Hello-World” x86 64 Assembly There are many, like several types of assembly languages. The most prominent are ARM, MIPS, and x86. Mips is on IBM CPUs and is found in Mac computers. Berkeley’s RISC style or reduced instruction set computer gave its name to the entire concept and was commercialized as the SPARC.

Why learn assembly you may ask…. “Because all code in the world becomes open source” Let’s learn a little about the underlining processes before we jump in: First, off intel or at&t syntax, jk….aka AT&T syntax needs to die in nuclear fire.

Briefly: Code exists somewhere in the hard drive in bytes you wrote the code and compiled it the bytes are allocated for your executable.

You load the executable in the ram: where it stores values: ram: random access memory where computer stores value its activity working on, the hard drive is static, ram is dealing with the active process.

Once the program is loaded in — CPUs registers are initialized — mini storages inside cpu person — x86 architecture has 16 of them — most are free to use — some registers have roles and specific functions. The metal or cpu can execute an instruction in code and also allocating space in ram and apace in the registers

Having an understanding of assembly language makes one aware of −

  • How programs interface with OS, processor, and BIOS;
  • How data is represented in memory and other external devices;
  • How the processor accesses and executes instruction;
  • How instructions to access and process data;
  • How a program accesses external devices.

Other advantages of using assembly language are −

  • It requires less memory and execution time;
  • It allows hardware-specific complex jobs in an easier way;
  • It is most suitable for writing interrupt service routines and other memory resident programs.

The first thing it does is put a register called ‘rip’ — register instruction pointer at the start of your code keeping track of your code

examples:

RBP — base pointer

RSP — stack pointer

Most registers are free to use

Learn by coding! Let’s look at some code — the language itself is pretty simple but the design patterns can be daunting. The syntax itself is simple t it’s understanding the connections and design patterns.

NASM Hello World for x86 and x86_64 Intel Mac OS X (get yourself an updated NASM with brew)

https://gist.github.com/FiloSottile/7125822

If you want to try this out yourself to actually compile this code create your object file with NASM, the net wide Assembler targeting the intel x86 series of processors, you will also want IBM’s ‘ld (Load Doubleword)’ instruction Load a doubleword of data into the specified general-purpose register.

Javascript and Assembly

“As a web developer specializing in JavaScript, I think necessarily in terms of JavaScript constructs, but I also often wonder how each relates to and will be ultimately represented in terms of computer instructions. For instance, here is an example of a simple if/else statement in JavaScript and its assembly language equivalent:

In the assembly example, the values op1 and op2 must be moved into the respective ax and bx registers before any calculation can be performed on them. They can then be compared and, if unequal, the program will jump (jne) to line one (L1). This is the equivalent of moving around the if statement and into the else statement in the JavaScript example, and setting x equal to 2. If the values are equal, the program keeps going and finally moves the value 1 into the main memory chunk represented by x. This is the equivalent of moving into the if statement and around the else statement in the JavaScript example and setting x equal to 1. Finally, once the comparison has been completed and x set to the appropriate value, the statement ends at the closing curly brace in JavaScript, with L2 being its assembly equivalent. This snippet is deliberately tiny and fragmented, and I ask the reader here to imagine that these comparison blocks exist within a larger, complete program.

I find this comparison interesting because I think it shows that having a surface-level understanding of assembly can be key to making each code block in a higher-level language like JavaScript seem much less abstract. While it can be daunting initially to look at two blocks of code written in two very different languages and fully understand how they each achieve the same (or a very similar) result, doing so can be immensely helpful to conceptualizing and breathing life into each program you write in whatever language you choose.” — Jessie White