FAQ Database Discussion Community


Switch to user space

assembly,x86,operating-system,kernel
this is part of code which demonstrates basic functions of os kernel. After flushing GTD and setting up IDT I want to switch to ring 3 run some int and context switch. However I cannot jump to user mode. I want to use trick with iret instruction. As far I...

Storing variables in specific addresses in assembly language

assembly,x86,nasm,memory-address
I have an assignment that asks me to make a Fibonacci loop and store the first 10 numbers in the memory from address 200 hexadecimal and so forth. I am using DOSBox 0.74 for this. I know how to do the Fibonacci loop I just don't get how I can...

How many 32-bit integer ops can a Haswell core perform at once?

x86,cpu,simd,avx,cpu-speed
In the context of preparing some presentation, it occurred to me that I don't know what the theoretical limit is for the number of integer operations a Haswell core can perform at once. I used to naively assume "Intel cores have HT, but that's probably parallelizing different kinds of work,...

Bitstuffing in assembly not working as intended

c++,assembly,x86,simulation,bitstuffing
I am currently trying to learn assembly (Intel x86) and I've made a program that simulates bit stuffing on 32bit words -> every 5 consecutive identical bits (5 0's or 5 1's), an opposite bit is inserted. In order to keep the word to its original 32bit size, the less...

Factorial code concept in assembly x86

assembly,x86,factorial
So guys this is a basic factorial program in assembly x86. 3 things really confuses me in this code, so maybe you can guys can fill in. what does [ebp+8] means? is it just an array that is based on eax? what is ja L1 means? cmp eax, 0. Someone...

SIMD minmag and maxmag

assembly,floating-point,x86,sse,avx
I want to implement SIMD minmag and maxmag functions. As far as I understand these functions are minmag(a,b) = |a|<|b| ? a : b maxmag(a,b) = |a|>|b| ? a : b I want these for float and double and my target hardware is Haswell. What I really need is code...

Calling conventions with composite date types

c++,c,gcc,x86,calling-convention
I understand the calling conventions for passing 32-bit and 64-bit integers (and pointers), floats, and doubles for 64-bit code for Micrsoft and the System V AMD64 ABI. But it's not clear to me what the calling conventions there are for composite data types. To be more clear what are the...

assembly function with C segfault

c,assembly,x86,sse,fpu
I am trying to make assembly function that uses SSE and FPU for parallel calculations. Unfortunately I am receiving segmentation fault(core dumped) error(while debugging it doesn't show in assembly function). I also cannot step out from assembly function. Gdb shows: Warning: Cannot insert breakpoint 0. Cannot access memory at address...

SSE intrinsics: Convert 32-bit floats to UNSIGNED 8-bit integers

x86,sse,mmx
Using SSE intrinsics, I've gotten a vector of four 32-bit floats clamped to the range 0-255 and rounded to nearest integer. I'd now like to write those four out as bytes. There is an intrinsic _mm_cvtps_pi8 that will convert 32-bit to 8-bit signed int, but the problem there is that...

TAS vs TTAS locking

performance,x86,locking,atomic,spinlock
I'm comparing TAS vs TTAS locking. Here are the code: TAS: .globl _tas_lock_acquire _tas_lock_acquire: repeat: lock btsw $0, (%rdi) jc repeat ret .globl _tas_lock_release _tas_lock_release: lock btrw $0, (%rdi) ret TTAS: .globl _ttas_lock_acquire _ttas_lock_acquire: try_lock: lock btsw $0, (%rdi) jc spinwait ret spinwait: btsw $0, (%rdi) jc spinwait jmp try_lock...

x86/C++ - Pointer To Pointer: Const being violated by compiler?

c++,visual-studio-2013,x86,shared-ptr
I was working on a shared pointer (called Handle) implementation for my student project's game engine, and we ran into a bug that we couldn't explain. For some reason, at a certain point in our factory, there was an invalid internal pointer being passed to a factory through a handle,...

Packed masking in SSE

c,assembly,x86,nasm,sse
I need to build some kind of masking system for a packed single because I need to use packed operations on vectors that contain less than 4 elements. So, for example, I need to do something like this: section .data align 16 a: dd 1.5, 2.3, 5.0 align 16 x:...

Difference between Constants and Direct addressing in x86 addressing modes

assembly,x86
I would like to know the difference between the assembly code when using operands for addressing modes. Example mov ax, 25 // where 25 is considered as a constant mov ax, [1000] // [1000] is considered as a memory location My question is, are the difference between constants and memory...

Prefetching double class member requires casting to char*?

c++,performance,optimization,x86,prefetch
I have a class which I am using _mm_prefetch() to pre-request the cacheline containing a class member, of type double: class MyClass{ double getDouble(){ return dbl; } //other members double dbl; //other members }; _mm_prefetch() signature is: void _mm_prefetch (char const* p, int i) But when I do: _mm_prefetch((char*)(myOb.getDouble()), _MM_HINT_T0);...

converting a vector of chars to int in assembly

assembly,x86,8086
I'm trying to do the following, but I'm having some trouble, and the only code I find on the web is for transforming strings into a number (basicly atoi), but I need something slightly different, e.g: num1 Db '60','30' num2 Db '2', '3' num3 Db '*', '*' Basicly I only...

Unknown variable being moved into EAX register

assembly,x86,x86-64
For the following function: void say_hello (void) { char name[5]; gets(name); //this is a unsafe function to use. Results in stack overflow printf("Hello %s\n", name); } I know that rbp+var_5 is the argument for the gets() function and rbp+var_10 is the argument for the printf function. But what is rbp+var_14?...

invalid instruction suffix when assembling x86 assembly with as

assembly,x86,x86-64
I wrote an assembly program that assemble successfully with as --32 when I use pushl and popl in the following code snippet: PrintHelloWorld: movl $10, %ecx PrintTenTimes: pushl %ecx movl $4, %eax movl $1, %ebx leal HelloWorld, %ecx movl $14, %edx int $0x80 popl %ecx loop PrintTenTimes jmp ExitCall But...

Effective Address calculation time on 8086/8088

assembly,x86,8086,cpu-architecture
I've started to implement a 8086/8088 with the goal of being cycle-exact. I can understand the reasoning behind the number of clock cycles for most instructions, however I must say I'm quite puzzled by the Effective Address (EA) calculation time. More specifically, why does computing BP + DI or BX...

Accessing a corrupted shared library

assembly,x86,32bit-64bit
Here is the code of cpuid2.s: #cpuid2.s view the cpuid vendor id string using c library calls .section .data output: .asciz "The processor Vendor ID is '%s'\n" .section .bss .lcomm buffer, 12 .section .text .global _start _start: movl $0, %eax cpuid movl $buffer, %edi movl %ebx, (%edi) movl %edx, 4(%edi)...

x86 jmp asterisk %eax

assembly,x86,jmp
In the paper for Google Native Client, the authors define a nacljmp as these two instructions: and %eax, 0xffffffe0 // Clears the 5 least significant bits in %eax. jmp *%eax First, I can see they clear the 5 least signficiant bits to make the instruction 32 bit aligned before it...

How does this instruction look in memory?

assembly,x86
I am having trouble figuring out how this instruction looks in memory for a x86 processor. mov $0x3c,%eax Can someone help me figure it out? For example an easy one is: xor %edi,%edi ---> 0x31 0xFF...

subroutine not reading from stdin

linux,assembly,x86,stdin
code is as follows getstr: ; get a LF terminated string from stdin ; in: EAX = dest buffer ; out: ax = bytes read ; EAX NOT preserved, all other registers preserved ;op mod opr1 opr2 comment ;-------------------------------------------------------- push ebx push ecx push edx sub esp, 2 ; allocate...

NASM output prompt for user input

assembly,x86,nasm,dosbox
Related, but not helpful to my current situation: nasm dos interrupt (output string) (I just wanted to clarify this is not a duplicate) What I am trying to do is create a prompt that will say "Enter a Base 10 number: " to the user. After that, I will convert...

Wrong answer from DIV assembly

assembly,x86
I have a part of my code mov di,3 mov cx,16 looop: xor dx,dx shl bx,1 adc dx,dx cmp cx,16 je cx16 (it's will dec cx and jump loop) push dx dec cx cmp cx,0 je cx0 mov ax,cx div di cmp dx,0 jne looop when cx = 3 i...

Meaning of “EC” in x86 disassembly [duplicate]

x86,intel-syntax
This question already has an answer here: Hex values of registers? x86 3 answers I am trying to disassemble Hex "8B EC". The disassembler gives me mov ebp, esp "8B" - MOV Instruction; "EC" - ???; How disassembler know that "EC" is ebp, esp?...

Meaning of “ds:” in assembly language

assembly,x86
I'm just a beginner in assembly language and have probably silly question. What is difference between those two lines? 3e 8b 06 mov eax,DWORD PTR ds:[esi] 8b 06 mov eax,DWORD PTR [esi] In my opinion it does the same, I also tried this program: int main() { __asm { mov...

GCC incorrectly inlining function with asm block

gcc,assembly,x86,inline-assembly
In the process of porting code from Watcom to GCC I noticed incorrectly generated function, and couldn't figure out why it happens. Here is minimal example: #include <stdio.h> bool InstallExceptionHandler(int exceptionNo, void (*handler)()) { bool result; asm volatile ( "mov ax, 0x203 \n" "mov cx, cs \n" "int 0x31 \n"...

Why call instruction opcode is represented as FF15?

assembly,x86,opcode
I am still learning assembly and trying to connect an instruction with it's opcode. Reading pdf at https://code.google.com/p/corkami/wiki/PE101?show=content It just dissect a PE file of a simple program that show message box in windows, the code is "removing all unrelated entries" push 0 push Title + DATADELTA push Caption +...

Memory alignment today and 20 years ago

c,gcc,assembly,x86
In the famous paper "Smashing the Stack for Fun and Profit", its author takes a C function void function(int a, int b, int c) { char buffer1[5]; char buffer2[10]; } and generates the corresponding assembly code output pushl %ebp movl %esp,%ebp subl $20,%esp The author explains that since computers address...

MASM: integer to string using std and stosb

string,assembly,x86,int,masm
I have the following procedure for converting a user supplied integer to a string. I'm pretty sure my algorithm is working fine for converting each digit of the integer to it's correct decimal ASCII value. However, I'm having difficulty then storing that digit into its correct place in the outString....

Assembly Language:Can physical address be 16 bits in segmented memory model?

assembly,x86
I am working on a University assignment of Assembly language related to memory addressing.Can physical address be 16 bits? Following are the values provided by instructor. BX=0x0000 SI=0x01A2 DS=0x0A2E Effective Address: EA = Base + Index + Offset = 0x0000+0x01A2+0xFF00 =0x100A2 = 0x00A2 Physical: =Segment * 10 + EA =0x0A2E...

BIOS rewrite on x86

x86,bios
My question is rather simple, yet I couldn't find out the answer. How to write on the BIOS memory chip ? Allright, to write data to IO devices on x86 (or actually whatever), the process always seems to be accessing the IO device through port-mapped or memory mapped IO. To...

Read a non-atomic variable, atomically?

c++,multithreading,performance,x86,atomic
I have a non-atomic 62-bit double which is incremented in one thread regularly. This access does not need to be atomic. However, this variable is occasionally read (not written) by another thread. If I align the variable on a 64-bit boundary the read is atomic. However, is there any way...

Spin Lock using xchg

c,x86,locking
I'm trying to implement the simplest spinlock (using TAS) in C using inline assembly with the command xchg. Since my compiler error messages are getting more and more exotic and I'm starting to grow grey hairs I've decided to ask here. Also I'm sorry if this question was already answered...

Counting character frequencies in an array of characters - x86 Assembly

assembly,x86
I'm trying to count the occurrences of characters in a string. My code is below: data segment 'DSEG' text db "This is a sentence.",0 ; string textSize dw $ - text - 1 ; size of string, - 1 to account for null-termination character freqTable dd 256 DUP(0) ends 'DSEG'...

What is the decoded form of an instruction?

assembly,x86,x86-64,intel
I am reading through "What every computer scientist should know about memory" by Ulrich Drepper. In section 6.2.2, it reads: [...] instructions have to be decoded before they can be executed and, to speed this up (important on x86 and x86-64), instructions are actually cached in the decoded form, not...

Memory transfer intel assembly AT&T

memory,assembly,x86,intel
I have a problem moving a string bytewise from one memory adress to another. Been at this for hours and tried some different strategies. Im new to Intel assemby so I need some tips and insight to help me solve the problem. The getText routine is supposed to transfer n...

x86 calling convention: should arguments passed by stack be read-only?

c,x86,stack,argument-passing,calling-convention
It seems state-of-art compilers treat arguments passed by stack as read-only. Note that in the x86 calling convention, the caller pushes arguments onto the stack and the callee uses the arguments in the stack. For example, the following C code: extern int goo(int *x); int foo(int x, int y) {...

Interrupt Descriptor Table Gate

assembly,x86,operating-system,interrupt-handling,protected-mode
I've written this code to create a sample IDT and load it in to the proper register. I've checked Intel System programming guides for proper structures, and yet I can't get interrupts working. While running kernel code in Bochs, and triggering interrupt (using __asm__ ("int $32"); I get a log...

VC++ SSE code generation - is this a compiler bug?

visual-c++,assembly,x86,sse,visual-studio-debugging
A very particular code sequence in VC++ generated the following instruction (for Win32): unpcklpd xmm0,xmmword ptr [ebp-40h] 2 questions arise: (1) As far as I understand the intel manual, unpcklpd accepts as 2nd argument a 128-aligned memory address. If the address is relative to a stack frame alignment cannot be...

How to use uint64_t and -m32?

gcc,x86,32-bit
The following code is printing for example 1030432081 (which is wrong) when compiled with gcc -m32 time.c whereas it works fine when compiled without the -m32 flag. Is there any way I can get this to work? #include <sys/time.h> #include <stdio.h> #include <stdint.h> #include <inttypes.h> void test() { struct timeval...

What is the EBP register pointing to when the main function executes? (Intel x82 architecture)

c,assembly,x86,calling-convention
I know that during a function call, the EBP register is pointing to the first value that the called function pushes onto the stack. But when the main function is called for the first time, what is the EBP register pointing to? Is it the first local variable that is...

Assembly x86 sign flag

assembly,x86
Why would the below instructions set the sign flag? mov al,0FEh sub al,2 As I understand it the AL register can hold 2^8 - 1 or 255. 0FEh = 254 in decimal. Subtracting 2 leaves 252. This seems to be positive. (For those new to assembly/binary arithmetic, below may clarify...

What is the compatible subset of Intel's and AMD's x86-64 implementations?

assembly,x86,x86-64
While learning x86-64 assembly, I came across my first incompatibility between Intel 64 and AMD64 implementations of "x86-64": Why does syscall compile in NASM 32 bit output while popa does not compile in 64 bit? syscall is valid in the compatibility mode of one but not the other. Is there...

Why do these two instructions have the same opcode?

assembly,x86
I was doing some assembly programming (Actually writing an assembler) and I noticed that MOV EBX, <something> and MOV BX, <something> have the same opcode 0xBB! Why is that and how does the processor differentiate between the two? Does it differentiate based on the size of the second operand? And...

Why is this line of assembly an 'invalid use of register'?

assembly,x86,memory-mapping
I am going through some OS development tutorials and I constantly see the following section of code: .intel_syntax noprefix do_e820: xor ebx, ebx # ebx must be 0 to start xor bp, bp # keep an entry count in bp mov edx, 0x0534D4150 # Place "SMAP" into edx mov eax,...

Android live build jars: arm64, armabi, mips, mips64, x86

android,jar,x86,mips
I am using an external library that uses a native lib. In my APK (and inside this external library) separate jars are packaged for: arm64-v8a armeabi armeabi-v7a mips mips64 x86 x86_64 There jars are quite large. I want to remove some of them. Are there any LIVE devices using x86?...

Confused about assembly FLD instruction m64fp

assembly,floating-point,x86,fpu
I'm so confused. I have some question about the FLD m64fp instruction, but I have no idea where to start. Because this is a homework, I'm not specifically asking for answers, but the method to solve the problem. Any suggestion or idea would be appreciated. Eight consecutive bytes in memory...

selection sort issues in masm

sorting,assembly,x86,masm
I have a program that I'm working on. Trying to do selection sort in assembly using MASM in Visual Studio 2010 and I have a problem. Whenever I change the condition to sort from descending to ascending order the program gives an incorrect answer. I'm trying to correct this I...

How to do a jump based on cmpss output (floating-point compare)?

assembly,x86
According to this reference, I can compare if xmm1 and xmm2 are equal by doing the following: cmpss xmm2, xmm1, 0 However, it seems that the zero flag is not set. Instead, the result is stored in xmm2. How do I do a jump based on whether or not they're...

Subtraction order in assembly

assembly,x86,calling-convention,att
So I have. pushl %ebp movl %esp, %ebp movswl 12(%ebp), %edx movl 8(%ebp), %eax subl %edx, %eax popl %ebp ret If say my function calls 2 variables: function(int a, short b). When I call the subtraction, would it be (b - a) or (a - b). eax is where the...

Reliability of having arithmetic shift in c++ when targeting x86

c++,x86
So according to the c++ spec The value of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a non-negative value, the value of the result is the integral part of the quotient of E1/2^E2. If...

Huge performance difference in byte-array access between x64 and x86

c#,performance,x86,64bit,clr
I'm currenty doing micro-benchmarks for a better understanding of clr performance and version issues. The micro-benchmark in question is xoring two byte arrays of each 64 bytes together. I'm always making a reference implementation with safe .net before I try to beat the .net framework implementation with unsafe and so...

What is the meaning of the data32 data32 nopw %cs:0x0(%rax,%rax,1) instruction in gcc inline asm?

c,gcc,assembly,optimization,x86
While running some tests for the -O2 optimization of the gcc compilers, I observed the following instruction in the disassembled code for a function: data32 data32 data32 data32 nopw %cs:0x0(%rax,%rax,1) What does this instruction do? To be more detailed I was trying to understand how does the compiler optimize useless...

Startup of Winforms program 10x slower under x64 relative to x86

c#,winforms,performance,x86,64bit
I've created a popular Winforms program in C# which has a lot of GUI widgets, and found that when the platform target is x64, startup is around 5-10x slower than x86. Under an x64 target, it takes around 5 seconds to start up, and this negatively impacts the user experience....

`mov` a literal to the ES register

assembly,x86,nasm
I have this portion of code : mov ax, 0x100 mov es, ax but when I try to replace the code above by this : mov es, 0x100 nasm tells me that I made an invalid combination of opcode and operands. Why ?...

Assembly code that prints all elements of an array

assembly,x86
I've been trying print elements of an array. I've got this code that sums all elements of an array and prints the result and I tried to edit in a lot of ways with no luck. Here is the code I found on internet: section .text global _start ;must be...

C float in NASM x86 assembly

c,assembly,x86,nasm
In my university project i have to use binary representation of float number in x86 assembly for arithmetic operations. Using FPU is forbidden so i try to read float number and return it as DWORD but whatever i try to do i get "-nan". Any advices? Edit: I use gcc...

Does RIP-relative addressing require 16-byte aligned?

assembly,x86,x86-64
The test is on 64-bit/x86 Ubuntu 12.04. With GCC 4.6.3. So basically I am manipulating some x64 assembly code. And I observed that RIP-relative addressing require the absolute address to be 16-byte aligned. Here is an example when debugging using gdb: 0x40f38d <S_0x40F614+61> xorpd 0x84d3(%rip),%xmm0 # 0x417868 <S_0x417DE0> This memory...

x64 LAR instruction (Load Access Rights Byte)

assembly,x86,64bit,x86-64,machine-code
This instruction has some confusing modes, here's the table for the 64-bit version on page 862 of the intel x64 manual: Opcode Instruction Description 0F 02 /r LAR r16, r16/m16 r16 ← access rights referenced by r16/m16 0F 02 /r LAR reg, r32/m16 reg ← access rights referenced by r32/m16...

Reversing a string and printing it in IA32 assembly

string,assembly,x86,att,reversing
So basically I'm trying to read a string, increase a counter (in this case, %edx) until I read a \n, and then, going backwards to print it reversed. This is my code: .section .data cadsal: .asciz "Por favor ingrese su cadena:\n" leer: .asciz "%s" salidafinal: .asciz "La cadena introducida, invertida...

Linux 64 bit context switch

linux,assembly,linux-kernel,x86,x86-64
in the switch_to macro in 32 bit mode, there the following code is executed before the __switch_to function is called: asm volatile("pushfl\n\t" /* save flags */ \ "pushl %%ebp\n\t" /* save EBP */ \ "movl %%esp,%[prev_sp]\n\t" /* save ESP */ \ "movl %[next_sp],%%esp\n\t" /* restore ESP */ \ "movl $1f,%[prev_ip]\n\t"...

Is it possible to mix x64/x86 in a C# Project?

c#,wcf,x86,64bit
We have a WebService that's been running for a while, there's about 6~ projects on it. Recently, we had to support a C++ 32 bit library, I tested and I had to set the project's target platform to x86 or I'd get the BadImageFormatException. So this new project is set...

Do non-maskable interrupts have priority over the current instruction?

assembly,x86,interrupt
I'm working on an Assembly course and the following question has puzzled me. I've tried to replicate it in code, but it's hard to reproduce the situation in a simulator. A value of 5 is stored at 0x0000100. At the exact same moment when the processor is evaluating a INCB...

ASM : Trouble using int21h on real machine

assembly,x86,bootloader
I want to input a char in ASM compare it to a defined char and print a message if they are the same or retry if they aren't Problem is that my code works on emu8086 but not on a VM: mdp DB 'c$' equal : mov ah, 1h int...

Assembly call subprograms based on user input

linux,assembly,input,x86,att
I have a program that is supposed to either add or subtract two hardcoded numbers based on user input 0 or not 0. I get memory access violation error inside input. when i try to call sum or call diff instead input in line 9 it works fine and gives...

What is this concept of Pending Interrupts

x86,interrupt,interrupt-handling,microprocessors,isr
I am unable to fathom the term Pending Interrupts. I mean, the way I see asynchronous events is like "Time, tide and Interrupts" wait for none. Then what is this pending interrupts. How can I service a request that has come in the past, which has gone. Can someone please...

lodsd / stosd assembly instructions : possible errata in reversing book

assembly,x86,x86-64
In page 25 of "Practical Reverse Engineering x86 - x64 ARM, Kernel & Obfuscation" I found an assembly code example retranslated to rough C in which lodsd and stosd instructions "translations" seems inverted. Since I'm fairy new to assembly language I'd like to know if it's really an errata or...

x86 Procedure Call Memory Allocation

c,assembly,struct,x86,att
So I have a problem from my textbook (Computer Systems: A Programmer's Perspective Problem 3.64): It gives code like this: typedef struct { int a; int *p; } str1; typedef struct { int sum; int diff; } str2; str2 word_sum(str1 s1) { str2 result; result.sum = s1.a + *s1.p; result.diff...

ASCIIZ string ending with a zero byte

string,assembly,x86,dos
I was writing an Assembly level program to create a file. .model small .data Fn db "test" .code mov ax,@data mov ds,ax mov CX,00 lea DX,Fn mov ah,3ch int 21h Mov ah,4ch Into 21h End Although program had no errors, but file was not created, so I searched the internet...

Assembly - extract specific bit

assembly,x86,gas,att
I want to extract 17th bit from my 32bit (int) value. Am I doing this right? I'm using AT&T syntax. movl $0x11112222,%eax movb $0b01000000,%bl andb %ah,%bl I put 32bit number into 32 bit register. Now 17th bit is in ah register (as well as other 16-23 bits). Now as it...

x86 asm - 12 bytes subtracted from esp. Only 8 needed

gcc,assembly,x86
I've compiled this code with gcc (gcc -ggdb -mpreferred-stack-boundary=2 -o demo demo.c) and decompiled it to look at the assembly (I know it's using unsafe functions, this was for an exercise into buffer overflows): #include<stdio.h> CanNeverExecute() { printf("I can never execute\n"); exit(0); } GetInput() { char buffer[8]; gets(buffer); puts(buffer); }...

JMP not working

c,assembly,x86,8086,real-mode
Okay, so I've been trying to make a two-step bootloader in assembly/C but I haven't been able to get the JMP working. At first I thought the read was failing, but, after the following test I ruled that out: __asm__ __volatile__( "xorw %ax, %ax;" "movw %ax, %ds;" "movw %ax, %es;"...

Debian Jessie 32-bit libraries

x86,debian,32bit-64bit,32-bit
For those looking for the answer, there it's, as it's not clear on other websites. This is required at least by the Intel compiler. Maybe it helps also for other software....

Print string using INT 0x10 in bootsector

assembly,x86,fasm
I want to create printl function that allow me to print string in the ax register. I am in 16-bit real mode and I can not find any way to print a message. I using int 0x10 to print a single letter. I try pass argument (string to print) in...

“CMPL” -> Based mode into indirect addressing mode

assembly,x86,cmp,addressing
So I'm working on this file. I have to transform complex addressing mode into simple addressing mode. I've managed to do movl $0, 0(%esp) into addl $0, %esp movl $0, (%esp) addl $-0, %esp works just fine, for all cases. However I can't do the same thing with cmpl $4,...

Most efficient way to test a 256-bit YMM AVX register element for equal or less than zero

c++,x86,simd,avx
I'm implementing a particle system using Intel AVX intrinsics. When the Y-position of a particle is less than or equal to zero I want to reset the particle. The particle system is ordered in a SOA-pattern like this: class ParticleSystem { private: float* mXPosition; float* mYPosition; float* mZPosition; .... Rest...

call function with float in assembly x86 x87

c,assembly,x86,stack,x87
I'm new to assembly programming and, as a part of a bigger program I have need to pass floating point values to another C-function. I have a call from my test program to my assembly function, that only pushes the parameters on the right stack, and calls a second C...

How to write a procedure to print a string and a newline character in x86 assembly?

assembly,x86
I'm trying to write a some reusable procedures to print strings in x86 assembly: print_str: prints a 0-terminated string print_nl: prints a newline character print_strnl: prints a 0-terminated string, then a newline character print_str works fine, but for some reason, print_nl and print_strnl both go into an infinite loop. Here's...

Assembler get value of pointer

assembly,x86,att
At the moment I play a bit with assembler but I have one question to pointers. In my assembler program I have a String which I put in the registers EAX and I want to get the third character from the string. This works great with this code: movl $3,...

Does QEMU emulate TLB?

x86,qemu,emulation,tlb,device-emulation
I have a very simple question, does QEMU emulate TLB? What happens when a guest linux system executes an "invlpg" instruction as it is for the invalidation of a TLB entry. I am aware that QEMU has softmmu link which is used for translating the guest virtual address to host...

Could this shift/jump be faster than switch…case statement?

assembly,x86,switch-statement,emulation,opcodes
I'm trying to optimize a branch (a switch...case like) at its max to emulate an X CPU on an x86 CPU. I thought of this: In memory I'll load blocks of x86 opCodes with a fixed length of 0x100 bytes, like this: first block 0 ...[my code, jump at 0x10000,...

x86 64 AT&T , moving part of register into another register

indexing,x86,cpu-registers,mov
I'd like to move one byte from register rdx to register rbx, like this: mov %rdx , (%rbx,%r15,1) where rdx contains 0x33 ,r15 is index and rbx contains 0 at start. I have tried using this method in many ways , always ending with SIGSEGV error. In the end I...

Linux x86 syscall 355 is run repeatedly on bootup and causes crash unless returns -ENOSYS

linux,linux-kernel,x86,system-calls,syscall
kernel version: 3.14.33 Before I added any system calls, the highest-numbered one for x86 (32 bit) was 352. I then added 353-357 by simply adding a row each to arch/x86/syscall/syscall_32.tbl and then using SYSCALL_DEFINEx as appropriate in kernel/*. The problem is with the syscall numbered 355. It is run repeatedly...

Extended Inline Assembly GCC- bad register name and junk 'done' after expression error when compiling

c,gcc,assembly,x86
I'm writing a program using assembly code to write a program that calculate one of the quadratic equation roots. I've written all of my code, but I have the following error: main.c:37: Error: bad register name `%qword' main.c:39: Error: junk `done' after expression How do I correct those error, please?...

Asm x86 segmentation fault in reading from file

assembly,x86,segmentation-fault,mmap
I'm receiving segmentation fault in 5th line of loop2. This is the part of my code which is reading values from mmapped file byte by byte. Could you please tell me what I'm doing wrong? .global _start _start: mov $2,%rax mov 16(%rsp),%rdi mov $02,%rsi syscall cmp $0,%rax jl exit 1:...

Assembly x86 “PSHUFB 128bit” implementation in another language

python,algorithm,assembly,x86,hex
I was reversing some application and i faced this opcode: PSHUFB XMM2, XMMWORD_ADDRESS and i tried implementing the algorithm of this function in python with no success! The reference of how this opcode should work is here: http://www.felixcloutier.com/x86/PSHUFB.html Here is a code snippet: PSHUFB (with 128 bit operands) for i...

MOVUPD vs. MOVDQU (x86/x64 assembly)

assembly,x86,64bit
What's the difference between these instructions? MOVDQU is an unaligned double quadword move and MOVUPD is an unaligned two 64-bit float move. I mean they're both just moving unaligned 128-bit data. MOVDQU is on page 948, MOVUPD is on page 995 of the intel x64 manual....

Read a pair of input co-ordinates in BCD and move the cursor tothe specified location on the screen using assembly level language

assembly,x86
This is the program I have display macro msg lea dx,msg mov ah,09h int 21h endm .model small .data msg1 db 10h,13h,"Enter row$" msg2 db 10h,13h,"Enter Column$" row db ? col db ? .code mov ax,@data mov ds,ax display msg1 call read mov row,al display msg2 call read mov col,al...

doubly linked list in nasm assembly

assembly,x86,nasm
I wanted to do a double linked list in Nasm . I have this structure for Node struc node left: resd 0 right: resd 0 data: resd 0 endstruc I do this when i want to use malloc push dword [node_sz] call [malloc] add esp, 4 * 1 Where: node_sz...

Play a sound file in masm32 and to stop the other sound file at the same time [closed]

winapi,assembly,x86,masm32,playsound
So I am doing a game in assembly language and I am using the PlaySound() function to play a background song. I want to do that after I "die" in the game, another sound file will start playing a sound file, and at the same time will stop the other...

How can you tell the size of a register in x86?

assembly,x86
How would you know how to fill in the underscore in the following assembly code: mov_ %eax, (%rsp) It's either "b" for byte, "w" for word, "l" for double word, or "q" for quad. The syntax of the registers is supposed to (I think) indicate how much data is getting...

Spawning a shell using ASM

linux,assembly,x86
I have the following code in asm to spawn a shell - but it crashes giving Segmentation Fault. Can you please suggest what could be the issue. jmp short mycall ; Immediately jump to the call instruction shellcode: pop esi ; Store the address of "/bin/sh" in ESI xor eax,...

Transformation of based indexed mode into indirect addressing mode (x86 assembly)

assembly,x86,addressing
I'm corrently working on changing examples from complex indirect addresssing mode into simple indirect addressing mode pieces. However, I've come across an example from the Based Mode, I'm unable to "transform". Code: move %eax, 28(%esp) I've tried addl $28, %esp movl (%eax), %esp This creates a segmentation fault; and I've...

subl causing Floating point exception

assembly,x86
I am creating a compiler which should compile a fictional language into asm x86 code. When compiling this piece of code (fictional code): int x; int f(int n) { write n; } int main() { x = 1; f(x); } write is equal to just print in console. The desired...

Imprecision of ASM jump instructions observed in debugger

assembly,x86,reverse-engineering,machine-code,ollydbg
I am making some inline modifications to an application in OllyDbg and am noticing some strange behavior. These are the instructions I wrote, copied directly from the debugger: 2005FE35 4C DEC ESP 2005FE36 77 21 JA SHORT 2005FE59 ; 23 byte difference To be clear, I only modified the opcodes...

Assembly (x86):

assembly,x86,bootloader,16-bit
I've been banging my head against the wall in an attempt to understand why the following assembly is not correctly dumping the contents of 'HELLO_WORLD'. ; Explicitly set 16-bit [ BITS 16 ] [ ORG 0x7C00 ] ; Create label for hello world string terminated by null. HELLO_WORLD db 'hello...

Using SSE to mimic the standard Math.pow function

c,assembly,x86,sse,simd
I'm trying to learn how to work with SSE and I decided to realize a simple code that computes n^d, using a function that gets called by a C program. Here's my NASM code: section .data resmsg: db '%d^%d = %d', 0 section .bss section .text extern printf ; ------------------------------------------------------------...

What's the purpose of _dl_sysinfo_int80?

c,gcc,assembly,x86
I mean, why not to issue the int instruction directly? Dump of assembler code for function execve: [omitted] 0x0806c282 <+18>: call *0x80e99f0 [omitted] End of assembler dump. (gdb) disas *0x80e99f0 Dump of assembler code for function _dl_sysinfo_int80: 0x0806ed70 <+0>: int $0x80 0x0806ed72 <+2>: ret End of assembler dump. From my...

NASM add byte to register ebx

assembly,x86,nasm
Is there a simple way to make this NASM snippet to work? add ebx, byte [ebp-10+ecx] I get the following error: error: mismatch in operand sizes. I want to add the byte in the memory address [ebp-10+ecx] to the least significant byte of ebx. Of course ebx is a 4...