Blog is moved

This blog is now movet to Github Pages

Say hello to x86_64 Assembly [part 8]

Floating point numbers

It is eight and final part of Say hello to x86_64 Assembly and here we will take a look on how to work with non-integer numbers in assembler. There are a couple of ways how to work with floating point data: First of all let's look how floating point number stored in memory. There are three floating point data types:
  • single-precision
  • double-precision
  • double-extended precision
As Intel's 64-ia-32-architecture-software-developer-vol-1-manual described:
The data formats for these data types correspond directly to formats specified in the IEEE Standard 754 for Binary Floating-Point Arithmetic.
Single-precision floating-point float point data presented in memory:
  • sign - 1 bit
  • exponent - 8 bits
  • mantissa - 23 bits
So for example if we have following number:

Exponent is either an 8 bit signed integer from −128 to 127 or an 8 bit unsigned integer from 0 to 255. Sign bit is zero, so we have positive number. Exponent is 00001111b or 15 in decimal. For single-precision displacement is 127, it means that we need to calculate exponent - 127 or 15 - 127 = -112. Since the normalized binary integer part of the mantissa is always equal to one, then in the mantissa is recorded only its fractional part, so mantissa or our number is 1,110000000000000000000000. Result value will be:
value = mantissa * 2^-112
Double precision number is 64 bit of memory where:
  • sign - 1 bit
  • exponent - 11 bit
  • mantissa - 52 bit
Result number we can get by:
value = (-1)^sign * (1 + mantissa / 2 ^ 52) * 2 ^ exponent - 1023)
Extended precision is 80 bit numbers where:
  • sign - 1 bit
  • exponent - 15 bit
  • mantissa - 112 bit
Read more about it - here. Let's look at simple example.

Say hello to x86_64 Assembly [part 7]

Interaction C with Assembly

It is seventh part of Say hello to x86_64 Assembly and here we will look on how we can use C together with assembler.

Actually we have 3 ways to use it together:
  • Call assembly routines from C code
  • Call c routines from assembly code
  • Use inline assembly in C code
Let's write 3 simple Hello world programs which shows us how to use assembly and C together.

Some tricks which i got from linux makefile

I'm not superuser of make, but sometime i use it. My knowledge about the files usually end in the next things: I know that if I'll create Makefile file, write some simple rules which are in general form:

And than execute make target, it executes command. Last time ago i started to learn some low-level stuffs as assembly programming, operating system theory and practice (as you can read and understand from previous blog posts about assembly programming). Some days ago i started to read Linux kernel Makefile and here i want to share some make syntax features which i learned from there. So this post is not for people who used make much time and knows much about it.

Say hello to x86_64 Assembly [part 6]

It is sixth part of Say hello to x86_64 Assembly and here we will look on AT&T assembler syntax. Previously we used nasm assembler in all parts, but there are some another assemblers with different syntax, fasm, yasm and others. As i wrote above we will look on gas (GNU assembler) and difference between it's syntax and nasm. GCC uses GNU assembler, so if you see at assembler output for simple hello world:

You will see following output:

Looks different then nasm Hello world, let's look on some differences.