For the second part of this lab we were to choose an open source project and inspect the assembler language inside the package, whether it be inline or in a file. I have chosen the package "Amule", let us begin taking a closer look
Q: How much assembley-language code is present
There are 2 functions of assembler present in a file
#if defined(__GNUC__) && defined(__i386__)
static inline uint32_t
rol(uint32_t x, int n)
{
__asm__("roll %%cl,%0"
:"=r" (x)
:"0" (x),"c" (n));
return x;
}
#define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )
#if defined(__GNUC__) && defined(__i386__)
static inline uint32_t
ror(uint32_t x, int n)
{
__asm__("rorl %%cl,%0"
:"=r" (x)
:"0" (x),"c" (n));
return x;
}
#define ror(x,n) ( ((x) >> (n)) | ((x) << (32-(n))) )
Q: Is the assembly code in its own file (.s or .S) or inline
The assembler is inline, located inside of a header file.
Q: Which platform(s) the assembler is used on
The code is looking for i386 which appears to be an AMD 32 bit processor type.
Q: What happens on other platforms
No real platform type specifications which I can see.
Q: Why it is there (what it does)
The commands rorl and roll look to be Rotate Left trough Carry and Rotate Right trough Carry. Each one of these commands shifts the bits one place to either the right or left.
I am not sure what this code is doing inside the program, I understand that sometimes on lower processors it will be more efficient to use bitwise operations like this opposed to a slower division or multiplication command, which can increase the speed of the program.
Q: Your opinion of the value of the assembler code, especially when contrasted with the loss of portability and increase in complexity of the code.
I believe assembler code is a very niche market for optimization, it has its place but due to the fact that it is not portable in addition to it being highly low level and with modern compilers doing a lot of behind the scenes optimization which was the primary focus of assembler in the past I would conclude that assembler is less useful today than it was in the past and therefore only those who have the technical skills and passion to work with assembler should venture out to attempt to use it. But having a basic understanding of assembler should still be part of every software programmers knowledge.
Comments