A Beginners’ Guide to x86-64 Instruction Encoding

The encoding of x86 and x86-64 instructions is well documented in Intel or AMD’s manuals. However, they are not quite easy for beginners to start with to learn encoding of the x86-64 instructions. In this post, I will give a list of useful manuals for understanding and studying the x86-64 instruction encoding, a brief introduction and an example to help you get started with the formats and encodings of the x86-64 instructions. » Read more

How to Install Wine 32-bit on CentOS 7

Since version 7, RHEL has only x86-64 versions. The same thing happens to CentOS 7. In CentOS 7/EPEL, there is only package for Wine x86-64. However, many Windows .exe files are 32-bit. Even there are 64-bit versions for some software, their installation file is 32-bit. And for some certain software such as Office 2007, 32-bit wine is preferred. In this post, we will check how to install 32-bit Wine on CentOS 7. » Read more

How to Statically Link C and C++ Programs on Linux with gcc

Before statically linking you C and C++ programs, you should be aware of the drawbacks of the static linking especially with glibc. There are some good discussions already: with glibc you’re linking static programs which are not really static and some others here and here. That said, you can choose to statically link C and C++ programs on Linux, only when you know what you are doing and why. » Read more

Measuring Time Accurately in Programs

It is quite common to measure the time in programs using APIs like clock() and gettimeofday(). We may also want to measure the time “accurately” for certain purposes, such as measuring a small piece of code’s execution time for performance analysis, or measuring the time in time-sensitive game software. It is hard to measure the time very accurately. But we surely can measure the time to the granularity that we can accept for our purpose. » Read more

Inline Assembly with GCC on Linux

One cool feature of gcc is that it can inline assembly into C code. With inline assembly, the programmer can precisely control the execution of the processor, such as forcing variables to use registers, getting special processor state efficiently, and writing critical efficient code in assembly by hand. I compile a list of tutorials from the Internet about inline assembly with gcc on Linux. » Read more

Generating Mixed Source and Assembly List using GCC

When debugging and optimizing programs, developers sometimes need to generate and investigate into the assembly generated by the compiler. Generating a mixed source and assembly list will help a lot for debugging and optimization. gcc can achieve this by working with the assembler. Generate assembly list mixed with the source code Just add these gcc compile options: -Wa,-adhln -g The command: $ gcc -Wa,-adhln -g source_code.c > assembly_list.s The options: -g: Produce debugging information -Wa,option: Pass option as an option to the assembler -adhln: a: turn on listings d: omit debugging directives; n: omit forms processing h: include high-level source l: include assembly One example The source code: helloworld.c: #include <stdio.h> int main() { printf("Hello world!\n"); return 0; } The command: $ gcc -Wa,-adhln -g helloworld.c > helloworld.s helloworld.s: ... » Read more