x86

When do we create base pointer in a function - before or after local variables?

给你一囗甜甜゛ 提交于 2021-02-18 19:03:16
问题 I am reading the Programming From Ground Up book. I see two different examples of how the base pointer %ebp is created from the current stack position %esp . In one case, it is done before the local variables. _start: # INITIALIZE PROGRAM subl $ST_SIZE_RESERVE, %esp # Allocate space for pointers on the # stack (file descriptors in this # case) movl %esp, %ebp The _start however is not like other functions, it is the entry point of the program. In another case it is done after. power: pushl

When do we create base pointer in a function - before or after local variables?

扶醉桌前 提交于 2021-02-18 19:00:53
问题 I am reading the Programming From Ground Up book. I see two different examples of how the base pointer %ebp is created from the current stack position %esp . In one case, it is done before the local variables. _start: # INITIALIZE PROGRAM subl $ST_SIZE_RESERVE, %esp # Allocate space for pointers on the # stack (file descriptors in this # case) movl %esp, %ebp The _start however is not like other functions, it is the entry point of the program. In another case it is done after. power: pushl

When do we create base pointer in a function - before or after local variables?

守給你的承諾、 提交于 2021-02-18 19:00:17
问题 I am reading the Programming From Ground Up book. I see two different examples of how the base pointer %ebp is created from the current stack position %esp . In one case, it is done before the local variables. _start: # INITIALIZE PROGRAM subl $ST_SIZE_RESERVE, %esp # Allocate space for pointers on the # stack (file descriptors in this # case) movl %esp, %ebp The _start however is not like other functions, it is the entry point of the program. In another case it is done after. power: pushl

Linux memory segmentation

ⅰ亾dé卋堺 提交于 2021-02-18 10:48:06
问题 Looking into the internals of Linux and memory management, I just stumbled upon the segmented paging model that Linux uses. Correct me if I am wrong, but Linux (protected mode) does use paging for mapping a linear virtual address space to the physical address space. This linear address space constituted of pages, is split into four segments for the process flat memory model, namely: The kernel code segment ( __KERNEL_CS ); The kernel data segment ( __KERNEL_DS ); The user code segment ( _

Inline assembly multiplication “undefined reference” on inputs

风流意气都作罢 提交于 2021-02-17 07:15:08
问题 Trying to multiply 400 by 2 with inline assembly, using the fact imul implicity multiplies by eax . However, i'm getting "undefined reference" compile errors to $1 and $2 int c; int a = 400; int b = 2; __asm__( ".intel_syntax;" "mov eax, $1;" "mov ebx, $2;" "imul %0, ebx;" ".att_syntax;" : "=r"(c) : "r" (a), "r" (b) : "eax"); std::cout << c << std::endl; 回答1: Do not use fixed registers in inline asm, especially if you have not listed them as clobbers and have not made sure inputs or outputs

Moving a character back and forth across the monitor

末鹿安然 提交于 2021-02-17 06:04:42
问题 Write a program that will move a character from left to right and then back again across the monitor of the PC a number of times as specified by the user's input. The user is to be prompted for the character to display and how many times to move it back and forth. An input of '?' and 1 would cause the '?' to move back and forth across the monitor 1 trip. Your program must only allow entry of numbers from 1 to 4 inclusive. Use a loop that allows an exit only if the value is greater than zero

Implementing a flow “(1) if {…} else if {…} … (2)” in Assembly

五迷三道 提交于 2021-02-17 05:57:57
问题 I have the following flow in C: // some stuff1 //................ if (something1) { func1(); func2(); } else if (something2) { func3(); func4(); } // some stuff2 I wonder, how can I encode that in Assembly? I mean, not exact intructions, but the flow. Should I use labels for jumping to what's inside if (something1) { ...} and "else if (something2)"? How would I return then to "// some stuff2"? ; some stuff1 ; and then cmp [some_struc], SOME_CONST je .... ???? cmp [some_struc], SOME_CONST2 je

Check if a number is even

我只是一个虾纸丫 提交于 2021-02-17 05:56:19
问题 I'm working my way through low level bit hacks, and would like to write an assembly program for each. Here is what I have for checking if a number is even or not: is_even: # check if an integer is even. # This is the same as seeing if its a multiple of two, i.e., & 1<<n - 1 # rdi stores the number xor %eax, %eax test $0b1, %rdi setz %al ret _start: mov $5, %rdi call is_even Are there any ways to improve the above or make it more readable? Is it possible to do the is_even check with 2

Newton - Raphson inversion algorithm in assembly

纵饮孤独 提交于 2021-02-17 05:44:29
问题 I am trying to implement Newton - Raphson inversion algotihm in assembly according to this equation: Xn+1 = Xn(2-b*Xn) My function is: .data const: .int 2 .text .global inversion inversion: pushl %ebp movl %esp, %ebp fldl 8(%ebp) # load b fldl 12(%ebp) # load X0 inv: fst %st(2) # save Xn fmul %st(1), %st(0) # b*Xn fsubr const # 2-b*Xn fmul %st(2), %st(0) # Xn(2-b*Xn) fcomi %st(2), %st(0) # check if it the same result as before jne inv # jump # it should return the st(0) leave ret And my C

x86 MESI invalidate cache line latency issue

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-17 02:00:32
问题 I have the following processes , I try to make ProcessB very low latency so I use tight loop all the time and isolate cpu core 2 . global var in shared memory : int bDOIT ; typedef struct XYZ_ { int field1 ; int field2 ; ..... int field20; } XYZ; XYZ glbXYZ ; static void escape(void* p) { asm volatile("" : : "g"(p) : "memory"); } ProcessA (in core 1 ) while(1){ nonblocking_recv(fd,&iret); if( errno == EAGAIN) continue ; if( iret == 1 ) bDOIT = 1 ; else bDOIT = 0 ; } // while ProcessB ( in