x86

How is a GDT invoked?

血红的双手。 提交于 2021-02-16 21:50:36
问题 I know how a GDT (Global Descriptor Table) is implemented and the use of segment registers and segment descriptors. However how/when is a GDT entry accessed? Is it accessed in basic mov instructions like mov [eax],ebx Does this implicitly invoke ds segment register and then access the GDT segment descriptor or there is some other way via which access to the GDT entry happens? 回答1: TL;DR : The Global Descriptor Table (GDT) or Local Descriptor Table (LDT) is only accessed when a segment

How is a GDT invoked?

北城余情 提交于 2021-02-16 21:49:25
问题 I know how a GDT (Global Descriptor Table) is implemented and the use of segment registers and segment descriptors. However how/when is a GDT entry accessed? Is it accessed in basic mov instructions like mov [eax],ebx Does this implicitly invoke ds segment register and then access the GDT segment descriptor or there is some other way via which access to the GDT entry happens? 回答1: TL;DR : The Global Descriptor Table (GDT) or Local Descriptor Table (LDT) is only accessed when a segment

Using scanf into global or local variables (on the stack), 32-bit calling convention

好久不见. 提交于 2021-02-16 20:11:49
问题 Given the following code : .section .rodata str: .string "Hello World!\n" input: .long 2 ######## .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp pushl $str call printf #return from printf: movl $0, %eax movl %ebp,%esp popl %ebp ret The output would be "Hello World!". Now I try to get a number from the user , and then print it out on the screen , but it doesn't work (code compile,but I did something wrong) . Where is my mistake ? .section .rodata input: .long 2 ######

Using scanf into global or local variables (on the stack), 32-bit calling convention

邮差的信 提交于 2021-02-16 20:11:12
问题 Given the following code : .section .rodata str: .string "Hello World!\n" input: .long 2 ######## .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp pushl $str call printf #return from printf: movl $0, %eax movl %ebp,%esp popl %ebp ret The output would be "Hello World!". Now I try to get a number from the user , and then print it out on the screen , but it doesn't work (code compile,but I did something wrong) . Where is my mistake ? .section .rodata input: .long 2 ######

Subtracting two characters

我的未来我决定 提交于 2021-02-16 18:13:12
问题 I just started programming in assembly so I am a beginner. To practice, I am trying to rewrite a basic libc in assembly (NASM Intel syntax). But I'm stuck on the strcmp function: ;; Compare two C-style NUL-terminated strings ;; Inputs : ESI = address of s1, EDI = address of s2 ;; Outputs : EAX = return an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2 strcmp: call strlen mov ecx, eax ; ecx = length of the string

What is the function of a “data label” in an x86 assembler?

帅比萌擦擦* 提交于 2021-02-16 16:41:21
问题 I'm currently learning assembly programming by following Kip Irvine's "assembly language x86 programming" book. In the book, the authors tries to explain the concept of data label A data label identifies the location of a variable, providing a convenient way to reference the variable in code. The following, for example, defines a variable named count: count DWORD 100 The assembler assigns a numeric address to each label. So my understanding of what data label does is: data label count is a

How to implement sign function with SSE3?

一世执手 提交于 2021-02-16 13:08:38
问题 1) Is there a way to efficiently implement sign function using SSE3 (no SSE4) with the following characteristics? the input is a float vector __m128 . the output should be also __m128 with [-1.0f, 0.0f, 1.0f] as its values I tried this, but it didn't work (though I think it should): inputVal = _mm_set_ps(-0.5, 0.5, 0.0, 3.0); comp1 = _mm_cmpgt_ps(_mm_setzero_ps(), inputVal); comp2 = _mm_cmpgt_ps(inputVal, _mm_setzero_ps()); comp1 = _mm_castsi128_ps(_mm_castps_si128(comp1)); comp2 = _mm

how are barriers/fences and acquire, release semantics implemented microarchitecturally?

半腔热情 提交于 2021-02-16 12:57:07
问题 A lot of questions SO and articles/books such as https://mirrors.edge.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.2018.12.08a.pdf, Preshing's articles such as https://preshing.com/20120710/memory-barriers-are-like-source-control-operations/ and his entire series of articles, talk about memory ordering abstractly, in terms of the ordering and visibility guarantees provided by different barriers types. My question is how are these barriers and memory ordering semantics

What is the explanation of this x86 Hello World using 32-bit int 0x80 Linux system calls from _start?

我的梦境 提交于 2021-02-15 07:50:37
问题 section .text global _start ;must be declared for using gcc _start: ;tell linker entry point mov edx, len ;message length mov ecx, msg ;message to write mov ebx, 1 ;file descriptor (stdout) mov eax, 4 ;system call number (sys_write) int 0x80 ;call kernel mov eax, 1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'Hello, world!',0xa ;our dear string len equ $ - msg ;length of our dear string This is a basic 32-bit x86 Linux assembly code to print "Hello, World!" on

What is the explanation of this x86 Hello World using 32-bit int 0x80 Linux system calls from _start?

谁说我不能喝 提交于 2021-02-15 07:50:13
问题 section .text global _start ;must be declared for using gcc _start: ;tell linker entry point mov edx, len ;message length mov ecx, msg ;message to write mov ebx, 1 ;file descriptor (stdout) mov eax, 4 ;system call number (sys_write) int 0x80 ;call kernel mov eax, 1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'Hello, world!',0xa ;our dear string len equ $ - msg ;length of our dear string This is a basic 32-bit x86 Linux assembly code to print "Hello, World!" on