Assembly languages :: Assembly

Assembly languages

He noticed that most assembly

A thing I wanted to do for some time now was to learn assembly.Recently I have had the opportunity to do so by doing a lab part of the SPO600 curriculum.

Assembly is one of the hardest types of programming languages to learn. Assembly being a low-level language means the syntax is level above machine language. When a high level language such as C++ is compiled, it is interpreted by the compiler into assembly. There is no standard for assembly languages(kind of how Java resembles C++) as the language is build specifically for the architecture. Assembly is very memory oriented which requires the users to carefully use registers and addresses. The syntax, barely resembling natural language are short line blocks that generally call, add, push etc registers.

To better understand assembly languages, I shall analyse assembly implementations on Aarch64 and x86_64.

First I will run two C programs at virtually preform the same task. The first program will be a printf statement that prints out “Hello World!’. The second program will also have an printf “Hello World!” but will also have an additional argument of 13 in the statement. We will compile and run both these programs on a x86-64 platforming using Gcc as our compiler.

hello.c

#include int main{ printf("Hello World!\n"); }

Output

Hello World!

hello2.c

#include int main{ printf("Hello World!\n", 13); }

On x86_64 systems, the assembly equivalent of this code would be in the GNU x86 Assembly/Gas syntax.

hello-gas.s

.text .globl _start _start: movq $len, %rdx /* message length */ movq $msg, %rsi /* message location */ movq $1, %rdi /* file descriptor stdout */ movq $1, %rax /* syscall sys_write */ syscall movq $0, %rdi /* exit status */ movq $60, %rax /* syscall sys_exit */ syscall .section .rodata msg: .ascii "Hello, world!\n" len = . - msg

The Natwide Assembler (NASM) is also available for systems using x86 based architectures. Here are the NASM equivalent of the C programs.

Resources
  • superiorspapers.us

You might also like

Assembly Language Programming Tutorial - 37 - NOT Instruction
Assembly Language Programming Tutorial - 37 - NOT Instruction
Assembly Language Programming Tutorial - 20 - MOV Instruction
Assembly Language Programming Tutorial - 20 - MOV Instruction

Copyright © . All Rights Reserved