Convert inline assembly code to C++

The problem isn’t solvable in general; that’s because the comment, // call the function & handle the return value. use __stdcall calling convention indicates reliance on 32bit calling conventions. In 32bit x86, stdcall means that all arguments are passed on the stack, in reverse order (i.e. the last arg is pushed first. That is, if … Read more

How to access the control registers cr0,cr2,cr3 from a program? Getting segmentation fault

Quoting from IntelĀ® 64 and IA-32 Architectures Software Developer Manuals 3-650 Vol. 2A on moving to and from control registers: This instruction can be executed only when the current privilege level is 0. Which means the instruction can only be executed in kernel mode. A minimal kernel module, that logs the contents of cr0, cr2 … Read more

get string length in inline GNU Assembler

The problem with using GCC’s inline asm to learn assembly is that you spend half your time learning about how gcc’s inline assembly works instead of actually learning assembly. For example here’s how I might write this same code: #include <stdio.h> int getStringLength(const char *pStr){ int len; __asm__ ( “repne scasb\n\t” “not %%ecx\n\t” “dec %%ecx” … Read more