x86

Why is 'add' taking so long in my application?

南笙酒味 提交于 2021-01-28 11:13:20
问题 I'm profiling an application using Intel VTune, and there is one particular hotspot where I'm copying a __m128i member variable in the copy constructor of a C++ class. VTune gives this breakdown: Instruction CPU Time: Total CPU Time: Self Block 1: vmovdqa64x (%rax), %xmm0 4.1% 0.760s add $0x10, %rax 46.6% 8.594s Block 2: vmovapsx %xmm0, -10x(%rdx) 6.5% 1.204s (If it matters, compiler is gcc 7.4.0) I admit I'm an assembly noob, but it's very surprising that one particular add instruction is

Printing decimal number in assembly language?

本秂侑毒 提交于 2021-01-28 10:27:36
问题 I'm trying to get output in decimal form. Please tell me what I can do to get the same variable in decimal instead of ASCII. .model small .stack 100h .data msg_1 db 'Number Is = $' var_1 db 12 .code add_1 proc mov ax, @data mov ds, ax mov ah, 09 lea dx, msg_1 int 21h mov ah, 02 mov dl, var_1 int 21h mov ah, 4ch int 21h add_1 endp end add_1 回答1: These 3 lines that you wrote: mov ah, 02 mov dl, var_1 int 21h print the character represented by the ASCII code held in your var_1 variable. To print

Printing decimal number in assembly language?

房东的猫 提交于 2021-01-28 10:24:34
问题 I'm trying to get output in decimal form. Please tell me what I can do to get the same variable in decimal instead of ASCII. .model small .stack 100h .data msg_1 db 'Number Is = $' var_1 db 12 .code add_1 proc mov ax, @data mov ds, ax mov ah, 09 lea dx, msg_1 int 21h mov ah, 02 mov dl, var_1 int 21h mov ah, 4ch int 21h add_1 endp end add_1 回答1: These 3 lines that you wrote: mov ah, 02 mov dl, var_1 int 21h print the character represented by the ASCII code held in your var_1 variable. To print

What's 'new' in a 'new' processor when viewed from programmer's point

好久不见. 提交于 2021-01-28 09:30:52
问题 I have recently been interested in understanding low level computing. I understand that today's widely used computers follow x86/x86-64 architecture. To my understanding, architecture, more specifically Instruction Set Architecture (ISA) is the set of instructions that the programmer is able to issue to the CPU. The first question, Is the ISA keeps evolving or remains the same? I think that it keeps evolving (meaning new instructions keeps getting added/previous instructions modified?) but

What's 'new' in a 'new' processor when viewed from programmer's point

只愿长相守 提交于 2021-01-28 09:27:34
问题 I have recently been interested in understanding low level computing. I understand that today's widely used computers follow x86/x86-64 architecture. To my understanding, architecture, more specifically Instruction Set Architecture (ISA) is the set of instructions that the programmer is able to issue to the CPU. The first question, Is the ISA keeps evolving or remains the same? I think that it keeps evolving (meaning new instructions keeps getting added/previous instructions modified?) but

Shorter x86 call instruction

半腔热情 提交于 2021-01-28 09:26:52
问题 For context I am x86 golfing. 00000005 <start>: 5: e8 25 00 00 00 call 2f <cube> a: 50 push %eax Multiple calls later... 0000002f <cube>: 2f: 89 c8 mov %ecx,%eax 31: f7 e9 imul %ecx 33: f7 e9 imul %ecx 35: c3 ret call took 5 bytes even though the offset fit into a single byte! Is there any way to write call cube and assemble with GNU assembler and get a smaller offset? I understand 16 bit offsets could be used, but ideally I'd have a 2 byte instruction like call reg . 回答1: There is no call

Getting INT 16h key scancode instead of character

▼魔方 西西 提交于 2021-01-28 09:26:14
问题 I'm writing a simple bootloader, and I have a getch function. char getch() { uint16_t inchar; __asm__ __volatile__ ("int $0x16\n\t" : "=a"(inchar) : "0"(0x0)); return (char)inchar; } I tried the first obvious solution, which is remove the casting to char of the inchar variable, but when I print it still returning a char instead of code. My println implementation: void println(char *str) { while (*str) { // AH=0x0e, AL=char to print, BH=page, BL=fg color __asm__ __volatile__ ("int $0x10" : :

Getting INT 16h key scancode instead of character

冷暖自知 提交于 2021-01-28 09:26:00
问题 I'm writing a simple bootloader, and I have a getch function. char getch() { uint16_t inchar; __asm__ __volatile__ ("int $0x16\n\t" : "=a"(inchar) : "0"(0x0)); return (char)inchar; } I tried the first obvious solution, which is remove the casting to char of the inchar variable, but when I print it still returning a char instead of code. My println implementation: void println(char *str) { while (*str) { // AH=0x0e, AL=char to print, BH=page, BL=fg color __asm__ __volatile__ ("int $0x10" : :

x86 MASM Assembly - Input Buffer holds old input despite FlushConsoleInputBuffer

余生长醉 提交于 2021-01-28 09:18:04
问题 To practice assembly in MASM, I created a small program that is supposed to do the do the following: Print "Type a: " to the screen Read one character from the input buffer, which is then flushed If the character is "a", then break away from the loop and end the program, if otherwise, repeat from step one My code goes as follows: .386 .model flat,stdcall include \masm32\include\kernel32.inc ; Defines Symbols To Be Used for the kernel32 library includelib \masm32\lib\kernel32.lib STD_OUTPUT

Why Segment fault when writing to writeable .data section? Using Ubuntu, x86, nasm, gdb, readelf

给你一囗甜甜゛ 提交于 2021-01-28 09:01:13
问题 I'm learning to write a simple shell code using assembly. I get a Segment fault when the mov opcode executes to write over the db data. Why? Any guidance appreciated! Debugging with gdb confirms the data is contiguous with the code at run time and readelf analysis of the program confirms the data segment is writeable. section .text global _start _start: ; The following code calls execve("/bin/sh", argv, envp=0) jmp short two one: pop ebx xor eax, eax mov [ebx+12], eax mov [ebx+7], al mov [ebx