x86

help understanding differences between #define, const and enum in C and C++ on assembly level.

recently, i am looking into assembly codes for #define, const and enum: C codes(#define): 3 #define pi 3 4 int main(void) 5 { 6 int a,r=1; 7 a=2*pi*r; 8 return 0; 9 } assembly codes(for line 6 and 7 in c codes) generated by GCC: 6 mov $0x1, -0x4(%ebp) 7 mov -0x4(%ebp), %edx 7 mov %edx, %ea...

Combining prefixes in SSE

In SSE the prefixes 066h (operand size override) 0F2H (REPNE) and 0F3h (REPE) are part of the opcode. In non-SSE 066h switches between 32-bit (or 64-bit) and 16-bit operation. 0F2h and 0F3h are used for string operations. They can be combined so that 066h and 0F2h (or 0F3h) can be used in the same instruction, because this is meaning...

intel machine code to assembly code question.

hello,experts,i wonder the intel x86 machineCode/assemblyCode conversion is singleSide or bothSide? means: assemblyCode ---> machineCode and machineCode ---> assemblyCode are both available. since the x86 machineCode is vary in size (1-15 byte),and opcode vary in (1-3 byte),how to determine one opcode is 1byte or 2byte or 3byte ? and...

Using gdb to single-step assembly code outside specified executable causes error "cannot find bounds of current function"

I'm outside gdb's target executable and I don't even have a stack that corresponds to that target. I want to single-step anyway, so that I can verify what's going on in my assembly code, because I'm not an expert at x86 assembly. Unfortunately, gdb refuses to do this simple assembly-level debugging. It allows me to set and stop on app...

How write C# code being safe both under x86 and x64 when accessing COM? Typical traps?

We use an open source library written in C# wrapping Windows BITS COM component. However, the code is only safe to run it in x86 mode. I would like to contribute to the library by making it safe for both x86 and x64, however I have no deep knowledge in this field. Could you please list here good/bad practices, typical issues, maybe pri...

Using assembler x86 to write to .net

I'm a total beginner when it comes to computer languages, and was asked for a code to write .NET with assembler x86, and i'm stuck here at the moment. Any basic code lines would work, still couldn't find any on the web. ...

What about Programmer "Invisible" registers?

These are "Programmer Visible" x86-64 registers: What about the invisible registers? Just now I learned that MMU registers, Interrupt Descriptor Table (IDT) uses these invisible registers. I'm learning these things in the hard way. Is there any resource (book/documentation/etc) that gives me the complete picture at once? I am aware ...

P/Invoke on 32 bit and 64 bit systems

Let us pick the following Win API call as an example: BOOL MessageBeep(UINT uType); // from User32.dll The input parameter is UINT to specify the beep type, which is can be both 32bit and 64bit integer, depending on which Windows version we call it on (or am I wrong?). If I want to P/Invoke message beep from C#, so I apply the DllImp...

Windows development: x86 to x64 transition

Hi everybody. Are there any guidelines how to transit to x64 with as little pain as possible? Suppose, I have a windows native x86 executable written in C++. The EXE works fine by itself, but there is also DLL that is hosted by both, the former EXE and an outside x64 process. With setup like this, what parts would I need to rewrite? I...

P6 Architecture - Register renaming aside, does the limited user registers result in more ops spent spilling/loading?

I'm studying JIT design with regard to dynamic languages VM implementation. I haven't done much Assembly since the 8086/8088 days, just a little here or there, so be nice if I'm out of sorts. As I understand it, the x86 (IA-32) architecture still has the same basic limited register set today that it always did, but the internal register...

what does JMP do to stack and frame pointers?

When an assembly has an instruction like jmp f what happens to the stack and frame pointers? I mean - f is a label in memory right? How can we jump to different address in memory and not update our frame and stack pointers... EDIT: I am talking about Intel x86 assembly yes :) ...

Drawing a stack frame for x86 assembly

So, I am kind of confused about drawing a stack frame for my assembly code. I have a feeling I started out wrong. Here is what I got so far, but as you can see I am confused at step 5, because I think my initial layout is wrong. Can you tell me where I went wrong? ...

How to access C arrays from assembler for Windows x64?

I've written an assembler function to speed up a few things for image processing (images are created with CreateDIBSection). For Win32 the assembler code works without problems, but for Win64 I get a crash as soon as I try to access my array data. I put the relevant info in a struct and my assembler function gets a pointer to this stru...

Easiest/Best Way to Learn the x86 Instruction Set?

I would like to learn the x86 Instruction Set Architecture. I don't meaning learning an assembly for x86. I want to understand the machine code baby. The reason is that I would like to write an assembler for x86. Then I want to write a compiler that compiles to that assembly. I know that there are the Intel manuals and AMD manuals that...

How Do You Make An Assembler?

I'd like to make a simple x86 assembler. I'm wondering if there's any tutorials for making your own assembler. Or if there's a simple assembler that I could study. Also, I wonder what tools are used in looking at and handling the binary/hex of programs. ...

What is required to use LODSB in assembly?

What is the minimum set of steps required to use LODSB to load a relative address to a string in my code? I have the following test program that I'm using PXE to boot. I boot it two ways: via pxelinux.0 and directly. If I boot it directly, my program prints both strings. If I boot via pxelinux.0, it only prints the first string. Why? ...

Address of function is not actual code address

Debugging some code in Visual Studio 2008 (C++), I noticed that the address in my function pointer variable is not the actual address of the function itself. This is an extern "C" function. int main() { void (*printaddr)(const char *) = &print; // debug shows printaddr == 0x013C1429 } Address: 0x013C4F10 void print() { ... } Th...

x86 opcode alignment references and guidelines

I'm generating some opcodes dynamically in a JIT compiler and I'm looking for guidelines for opcode alignment. 1) I've read comments that briefly "recommend" alignment by adding nops after calls 2) I've also read about using nop for optimizing sequences for parallelism. 3) I've read that alignment of ops is good for "cache" performanc...

x86 and Memory Addressing

I've been reading up on memory models in an assembly book I picked up and I have a question or two. Let's say that the address bus has 32 lines, the data bus has 32 lines and the CPU is 32-bit (for simplicity). Now if the CPU makes a read request and sends the 32bit address, but only needs 8 bits, all 32 bits come back anyway? Also, t...

ASM x86 relative JMP

Hi, I'm doing some ASM code in a C code with the asm function. My environment is DVL with gcc version 3. Hi need to make a JMP to a relative address like %eip+0x1f. How can I do this ? Thanks ...