assembly

syscall wrapper asm C

人走茶凉 提交于 2021-02-04 16:31:37
问题 Can someone explain this code snippet to me? Also please give me some link/URL where i can know more about this? This code is used as a wrapper to override the "extern int errno" in our library. Can someone explain me this function, and tell why is wrapper needed in some syscalls? Which are also called WeakSYSCALLS? #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1) #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2) #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3) #define LOADREGS_5(a1, a2, a3, a4, a5) \ register int

Tools for learning Assembly in “The Art of Intel X86 Assembly”

我的梦境 提交于 2021-02-04 16:24:32
问题 Although I studied a Computer Organization course in my college, I want to study Assembly (and related concepts) rigorously using this old book: The Art of Intel X86 Assembly. Do you know how to get start on Linux? Is NASM a good choice for this? If I want to incorporate UCR Standard Library in my code, do I have to compile the library first? I want my code to run on a Linux VM (Virtual Box). Is this possible or it must be the native code of my machine? 回答1: Finally, I found a way to overcome

How do I interpret the columns of the CPU window's disassembly pane?

十年热恋 提交于 2021-02-04 16:19:41
问题 There is a tool called the CPU window, which I get pressing Ctrl + Alt + C , that shows the disassembly of my code. A green arrow to the left of the memory address indicates the location of the current execution point, then there is the memory addresses, but what does the second column mean, and why does the compiler sometimes jump more than one address after an instruction? For example: |first column|second column|assembly| 004520F4 55 push ebp //continuous 004520F5 8BEC mov ebp, esp //jumps

How do I interpret the columns of the CPU window's disassembly pane?

放肆的年华 提交于 2021-02-04 16:19:25
问题 There is a tool called the CPU window, which I get pressing Ctrl + Alt + C , that shows the disassembly of my code. A green arrow to the left of the memory address indicates the location of the current execution point, then there is the memory addresses, but what does the second column mean, and why does the compiler sometimes jump more than one address after an instruction? For example: |first column|second column|assembly| 004520F4 55 push ebp //continuous 004520F5 8BEC mov ebp, esp //jumps

Understanding stack alignment enforcement

北城余情 提交于 2021-02-04 13:57:34
问题 Consider the following C code: #include <stdint.h> void func(void) { uint32_t var = 0; return; } The unoptimized (i.e.: -O0 option) assembly code generated by GCC 4.7.2 for the code above is: func: pushl %ebp movl %esp, %ebp subl $16, %esp movl $0, -4(%ebp) nop leave ret According to the stack alignment requirements of the System V ABI , the stack must be aligned by 16 bytes before every call instruction (the stack boundary is 16 bytes by default when not changed with the option -mpreferred

x86 Assembly (AT&T): How do I dynamically allocate memory to a variable at runtime?

穿精又带淫゛_ 提交于 2021-02-04 08:36:07
问题 I am trying to allocate an amount of space to a variable at runtime. I know that I can allocate a constant amount of space to a variable at compile time, for instance: .data variable: # Allocate 100 bytes for data .space 100 However, how do I allocate a variable amount of space to a variable at runtime? For instance, allocating %eax bytes of space to the variable at runtime? 回答1: You can't dynamically allocate static storage. You need to use the stack, or malloc / mmap / whatever (sometimes

How to display floating-point rounded to .001 with Irvine32 WriteFloat, not printf

非 Y 不嫁゛ 提交于 2021-02-04 08:30:47
问题 I am very new to assembly language so bear with me... I have a floating-point that I have rounded to the nearest .001, but still displays as something like +1.6670000E+000. I would like it to display simply as 1.667. Here is my code for dividing and rounding the numbers: fild num_a fidiv num_b fimul thousand frndint fidiv thousand fst a_div_b And here is my code for displaying the float: mov eax, num_a call WriteDec mov edx, OFFSET divide call WriteString mov eax, num_b call WriteDec mov edx,

How to display floating-point rounded to .001 with Irvine32 WriteFloat, not printf

不打扰是莪最后的温柔 提交于 2021-02-04 08:30:06
问题 I am very new to assembly language so bear with me... I have a floating-point that I have rounded to the nearest .001, but still displays as something like +1.6670000E+000. I would like it to display simply as 1.667. Here is my code for dividing and rounding the numbers: fild num_a fidiv num_b fimul thousand frndint fidiv thousand fst a_div_b And here is my code for displaying the float: mov eax, num_a call WriteDec mov edx, OFFSET divide call WriteString mov eax, num_b call WriteDec mov edx,

Conditional move (cmov) in GCC compiler

こ雲淡風輕ζ 提交于 2021-02-04 08:08:25
问题 I saw somewhere that the GCC compiler might prefer sometimes not using conditional mov when converting my code into ASM. What are the cases where it might choose to do something other than conditional mov? 回答1: Compilers often favour if-conversion to cmov when both sides of the branch are short, especially with a ternary so you always assign a C variable. e.g. if(x) y=bar; sometimes doesn't optimize to CMOV but y = x ? bar : y; does use CMOV more often. Especially when y is an array entry

Conditional move (cmov) in GCC compiler

喜你入骨 提交于 2021-02-04 08:06:37
问题 I saw somewhere that the GCC compiler might prefer sometimes not using conditional mov when converting my code into ASM. What are the cases where it might choose to do something other than conditional mov? 回答1: Compilers often favour if-conversion to cmov when both sides of the branch are short, especially with a ternary so you always assign a C variable. e.g. if(x) y=bar; sometimes doesn't optimize to CMOV but y = x ? bar : y; does use CMOV more often. Especially when y is an array entry