Inside Assembly

Inside Assembly

The first time this programming language caught my attention dates back to my first years at university. Before that, I had heard of assembly language, but i had never had the opportunity to explore it. I remember a class discussion about assembly language, and how difficult it was, and how it could be used to interfere with systems if learned. It appeared to me as a language used by people who defined the concept of a real "hacker". (I didn't learn this language at university, we didn't have such a course when i was at school, we were learning more basic programming languages ​​and higher-level languages ​​in a basic sense.) Although it seemed cool at the time, the cool definitions didn't really attract me 😊 It was more the difficulty that led me to start a challenge within myself. From that point on, ambition took over, and i started learning the language obsessively. Many opportunities to improve myself came my way, and my command of the language increased over time, but i still don't think i have fully mastered it, even though it's been about 10 years... My story with the language is not the subject of this article, so i won't go into too much detail. I will try to tell you about assembly language as best i can.
I constantly see and talk to young people just starting out in the industry. These days, they don't even start with real programming languages. They're trying to build their careers by writing code with libraries and artificial intelligence, often using code blocks. This is, in my opinion, a huge mistake. I know learning real programming languages ​​is difficult, and people often want to focus on the easy options and advance quickly, but this isn't the right path. Young people need to harness their youthful ambitions and focus on more challenging tasks to improve themselves. There is so much to say, but i don't want to split this post too much.
highlevellanguage
Let's start by understanding what it is. Assembly is a low-level programming language closest to machine language, allowing us to communicate directly with hardware by giving direct instructions to the computer processor. It's a difficult language to learn and use. It's a language that makes you feel like you're doing god-like work in the computer world, but it also teaches you not to succumb to arrogance and ambition 😊
We can say that it's a form of machine code, consisting of 0s and 1s, translated into symbolic instructions that humans can understand. These codes are closely related to the processor. Each processor architecture uses its own unique assembly language, but ultimately, every assembly language code generally corresponds to a machine code.
veczeroone
We can find assembly code in the Linux kernel, Windows hardware drivers, and some real-time flight simulators. So, while it's a very old language, it's actually a preferred choice when close control to the hardware is required.
It all began years ago, when the first computers were programmed using only 0s and 1s—machine language. This was both incredibly difficult and error-prone. The first symbolic assembly language was developed between 1947 and 1950 by Kathleen Booth at Birkbeck University in England for the ARC and ARC2 computers. Her goal was to develop a simple, understandable language that could be easily read by humans and provided direct access to the processor, replacing incomprehensible machine code. The symbolic coding method she developed later became the basis for modern assembler programming.
ZF4p5
There are several features that make assembly language unique to us. First and foremost, in terms of hardware control, assembly provides direct access to processor registers, memory addresses, and I/O (input-output) ports. This allows developers to control every bit of hardware and utilize system resources with maximum efficiency. Regarding performance, because there's no abstraction layer, it delivers the highest possible performance for the hardware it runs on.
5ccba1aa19a67cab1a6ee617209f3c9a
Because each assembly instruction is directly translated into machine code, there is almost no overhead. Of course, such a performance-oriented, low-level language also presents challenges. Due to platform dependency, each processor architecture has its own assembly language, and the instruction set and addressing modes are architecture-specific. For example, Intel x86 assembly and ARM assembly are completely different. This limits code portability. Memory management is entirely the responsibility of the programmer. There is no automatic memory management like garbage collectors. This means that each byte must be manually controlled when to allocate and when to free it. Debugging and development are quite complex. Because abstractions like built-in functions and data structures found in high-level languages ​​are not available in assembly, everything must be done manually by the developer.
1666445800494
To understand assembly language, we first need to understand the basic operating logic of processors. Each processor retrieves, interprets, and executes instructions from memory sequentially. The life of a processor consists of a continuously repeating three-level cycle: fetch -> decode -> execute. This cycle is called the instruction cycle.
In the fetch phase, the processor retrieves the address of the next instruction and retrieves it from RAM. In the decode phase, the instruction's purpose is determined. The operation, registers, or memory locations to be used are determined. In the final phase, Execute, the arithmetic logic unit or other subunits execute the instruction. The result is written to the registers or memory, and this cycle repeats for each instruction.
Now that we understand processor logic, in the operating logic of assembly programs, each assembly instruction tells the CPU to perform a single task. This instruction generally consists of the following two components. The OPCode specifies the instruction's action; it tells the CPU what to do. Each processor has its own unique instruction set, but most processors use similar OPCodes. Operands are the data or addresses on which the instruction operates. Each instruction usually takes one or two operands, and an operand can hold a register memory address or a constant value.
3213451312s
Assembly instructions can be categorized into three main categories: Data Movement, Processing, and Flow Control. Data Movement instructions involve retrieving data from one location and placing it elsewhere. Instructions like "MOVE," "PUSH," and "POP" move data registers between memory and the stack. Processing instructions are used to process data. Instructions like "ADD," "SUB," and "AND" perform numerical and logical operations. Flow Control is the category where the program determines the order in which instructions will be executed. Instructions like "Jump," "Call," and "Loop" manage branching, looping, and function calls.
So, the basic logic in assembly language commands is to retrieve data from one location, process it, store the result elsewhere, and change the flow if necessary. In this article, I aim to foster a love of assembly language and introduce it to beginners, so i won't share code examples. I don't want to scare people away. 😊 I'll leave the research and learning to you. 🤝