x86

Calling assembly in GCC?

#include <stdlib.h> static inline uint xchg(volatile unsigned int *addr, unsigned int newval) { uint result; asm volatile("lock; xchgl %0, %1" : "+m" (*addr), "=a" (result) : "1" (newval) : "cc"); return result; } Can some one tell me what this code does exactly? I mean I have an idea or the parts of this command. "1" newva...

Running 32 bit assembly code on a 64 bit Linux & 64 bit Processor : Explain the anomaly.

Hello, I'm in an interesting problem.I forgot I'm using 64bit machine & OS and wrote a 32 bit assembly code. I don't know how to write 64 bit code. This is the x86 32-bit assembly code for Gnu Assembler (AT&T syntax) on Linux. //hello.S #include <asm/unistd.h> #include <syscall.h> #define STDOUT 1 .data hellostr: .ascii "hello w...

Outputting variable values in x86 asm ?

Hello All- I'm working on a homework assignment in x86 and it isn't working as I expect (surprise surprise!). I'd like to be able to output values of variables in x86 functions to ensure that the values are what I expect them to be. Is there a simple way to do this, or is it very complex? For what it's worth, the x86 functions are being...

push %ebp movl %esp, %ebp

Can anybody explain me what effect these two instructions cause in the assembly code generated by gcc for x86 machines: push %ebp movl %esp, %ebp ...

I've built a Windows service as "Any CPU". Why does it run in 32-bit mode on my 64 bit machine?

I've built a Windows service as "Any CPU". However, when I run it on my 64 bit machine it runs in 32 bit. How can I fix it? I'm using .NET and C#, and my operating system is Windows 2008 R2. If I build it in x64 it correctly loads in 64 bit mode. However, "Any Cpu" -- which is what I want -- loads in 32 bit, even though the machine it's...

No Program Entry Point TASM Error

I'm trying to develop a simple kernel using TASM, using this code: ; beroset.asm ; ; This is a primitive operating system. ; ;********************************************************************** code segment para public use16 '_CODE' .386 assume cs:code, ds:code, es:code, ss:code org 0 Start: mov ax...

c++ floating point precision loss: 3015/0.00025298219406977296

The problem. Microsoft Visual C++ 2005 compiler, 32bit windows xp sp3, amd 64 x2 cpu. Code: double a = 3015.0; double b = 0.00025298219406977296; //*((unsigned __int64*)(&a)) == 0x40a78e0000000000 //*((unsigned __int64*)(&b)) == 0x3f30945640000000 double f = a/b;//3015/0.00025298219406977296; the result of calculation (i.e. "f"...

shortest way to do a fetch in X86 assembler?

What is the shortest way to fetch a value from memory in X86 Assembler? ...

Undefined symbol sunOglCurPrimTablePtr in Solaris-x86

I was porting a C++ program from Solaris Sparc to Solaris x86. The program utilizes OpenGL library and the compilation is performed in a Sun Ultra27 workstation with the default GCC (3.4.3) and OpenGL library come with the machine. However, the following OpenGL call couldn't found while linking: Undefined symbol firs...

Floating point vs integer calculations on modern hardware

I am doing some performance critical work in C++, and we are currently using integer calculations for problems that are inherently floating point because "its faster". This causes a whole lot of annoying problems and adds a lot of annoying code. Now, I remember reading about how floating point calculations were so slow approximately cir...

What is register %eiz?

In the following assembly code that I dumped out using objdump: lea 0x0(%esi,%eiz,1),%esi What is register %eiz? What does the preceding code mean? ...

Why is a function executed from the same memory address each time?

I'm disassembling an executable: (gdb) disas main Dump of assembler code for function main: 0x004012d0 <main+0>: push %ebp 0x004012d1 <main+1>: mov %esp,%ebp ... Each time the memory address is the same:0x004012d0. Isn't the memory address to be dynamically assigned by the OS? UPDATE Now I see it's virtual space,and it c...

Visual Studio 2008 Build question x64 vs x86

Hi Everyone, I have written an application on my x64 machine in Visual Studio 2008. The application will be sent to someone, and I have two questions that I need answers to. What requirements will they need to have installed. I am assuming the .NET 3.5 redistributable. Are there anything else though? (The application does not call a...

Fastest way to calculate a 128-bit integer modulo a 64-bit integer

I have a 128-bit unsigned integer A and a 64-bit unsigned integer B. What's the fastest way to calculate A % B - that is the (64-bit) remainder from dividing A by B? I'm looking to do this in either C or assembly language, but I need to target the 32-bit x86 platform. This unfortunately means that I cannot take advantage of compiler sup...

Determine 32/64 bit architecture in assembly

I was reading over this question and wondered if the accepted answer might also be a way to determine the architecture. For instance, in asm could I push a WORD onto the stack and then check SP. Compare the new SP to the old SP: Diff of 4 means 32 bit Diff of 8 means 64 bit Am I correct in this thinking? ...

Setting processor to 32-bit mode

It seems that the following is a common method given in many tutorials on switching a processor from 16-bit to 32-bit: mov eax, cr0 ; set bit 0 in CR0-go to pmode or eax, 1 mov cr0, eax Why wouldn't I simply do the following: or cr0, 1 Is there something I'm missing? Possibly the only th...

Square a number in NASM assembly without multiplication

Is it possible to square a number stored in a register (say eax) without doing any multiplication (by using shifts, etc)? I will be squaring a 16-bit number in 32-bit assembly so overflow shouldn't be an issue. I am using NASM x86 assembly to create the program. Thanks in advance for your help. ...

Operand size conflict in x86 Assembly??

I'm a novice programmer who is attempting assembly for the first time. Sorry in advance if this is an incredibly lame question. I have a character stored in the EAX register, but I need to move it to my DL register. When I try: mov dl, eax I get an error C2443: operand size conflict. I know that the eax register is 32 bit while the ...

Using an array in embedded x86 assembly??

Hey all I have a method (C++) that returns a character and takes an array of characters as its parameters. I'm messing with assembly for the first time and just trying to return the first character of the array in the dl register. Here's what I have so far: char returnFirstChar(char arrayOfLetters[]) { char max; __asm { push eax...

Hello World bootloader not working!

Hello. I've been working through the tutorials on this webpage which progressively creates a bootloader that displays Hello World. The 2nd tutorial (where we attempt to get an "A" to be output) works perfectly, and yet the 1st tutorial doesn't work for me at all! (The BIOS completely ignores the floppy disk and boots straight into Win...