x86

Choosing the right and learning assembler for compiler-writing

I'm writing a compiler and I have gone through all the steps (tokenizing, parsing, syntax tree structures, etc.) that they show you in all the compiler books. (Please don't comment with the link to the "Resources for writing a compiler" question!). I have chosen to use NASM together with alink as my backend. Now my problem is: I just c...

How to deal with alias registers in data-flow analysis using SSA form? (e.g. EAX/AX/AH/AL in x86)

For exmaple: How to represent the following x86 in SSA form: xor eax, eax inc ax By introducing some pseudo functions, I come up with: eax@1 = eax@0 ^ eax@0 ax@1 = LOWORD(eax@1) al@1 = LOBYTE(ax@1) ah@1 = HIBYTE(ax@1) hax@1 = HIWORD(eax@1) ax@2 = ax@1 + 1 eax@2 = MAKEDWORD(ax@2, HIWORD(eax@1)) al@2 = LOBYTE(ax@2) ah@2 = HIBYTE(a...

Can an x64 application use x86 assemblies - and vice versa?

My application is built as a x64 application. After moving to VS2010 I got some problems which seems to be related to some x64/x86 mismatch in referenced dlls. Now I'm moving to target .NET4, and I get even more similar problems. My question is: What precautions do I need to take regarding mixing x64 and x86. Can it be done at all? I t...

What's the point of LEA EAX, [EAX]?

LEA EAX, [EAX] I encountered this instruction in a binary compiled with the Microsoft C compiler. It clearly can't change the value of EAX. Then why is it there at all? ...

x86 Assembly: Before Making a System Call on Linux Should You Save All Registers?

I have the below code that opens up a file, reads it into a buffer and then closes the file. The close file system call requires that the file descriptor number be in the ebx register. The ebx register gets the file descriptor number before the read system call is made. My question is should I save the ebx register on the stack or somew...

Simple way to print value of a register in x86 assembly.

I need to write a program in 8086 Assembly that receives data from the user, does some mathematical calculations and prints the answer on the screen, I have written all parts of the program and all work fine but I don't know how to print the number to the screen. At the end of all my calculation the answer is AX and it is treated as an ...

Easy way to convert c code to assembly?

Is there an easy way (like a free program) that can covert c/c++ code to x86 assembly? I know that any c compiler does something very similar and that I can just compile the c code and then disassemble the complied executable, but that's kind of an overkill, all I want is to convert a few lines of code. Does anyone know of some program...

Why doesn't Linux use the hardware context switch via the TSS?

Hi guys! I read the following statement: The x86 architecture includes a specific segment type called the Task State Segment (TSS), to store hardware contexts. Although Linux doesn't use hardware context switches, it is nonetheless forced to set up a TSS for each distinct CPU in the system. I am wondering: Why doesn't...

Write a maximum of two instructions to clear, set and complement some bits in the AL register

You are required to write a maximum of two instructions in assembly to do the following: Clear bits 0 and 7 of register AL, i.e. make them 0 Set bits 3 and 4 of register AL, i.e. make them 1. Complement bits 1 and 5 of register AL. Keep all other bits in the register AL as is without changing their values. ...

80x86 16-bit asm: lea cx, [cx*8+cx] causes error on NASM (compiling .com file)

Title says it all. The error NASM gives (dispite my working OS) is "invalid effective address". Now i've seen many examples of how to use LEA and i think i gots it right but yet my NASM dislikes it. I tried "lea cx, [cx+9]" and it worked; "lea cx, [bx+cx]" didn't. Now if i extended my registers to 32-bits (i.e. "lea ecx, [ecx*8+ecx]") ...

Printf in assembler doesn't print

Hi there, I have got a homework to hack program using buffer overflow ( with disassambling, program was written in C++, I haven't got the source code ). I have already managed it but I have a problem. I have to print some message on the screen, so I found out address of printf function, pushed address of "HACKED" and address of "%s" on t...

Why is my boot loader's stack segment at 0x3FF (end of Real Mode IVT)?

Title says it all. "address 0x500 is the last one used by the BIOS" is what Wikipedia - "00000000-000003FF Real Mode IVT (Interrupt Vector Table)" is what osdev.org's article over the BIOS memory map says. So can you tell me why NASM places my .com file's stack pointer to 0x3FF while my instruction pointer starts at 0x7C00? To me...

Why don't stacks grow upwards (for security)?

This is related to the question 'Why do stacks typically grow downwards?', but more from a security point of view. I'm generally referring to x86. It strikes me as odd that the stack would grow downwards, when buffers are usually written to upwards in memory. For example a typical C++ string has its end at a higher memory address than...

I'm about to learn x86 assembly on os x 10.6 let me know how compile..plz

hello~ I'm about to learn x86 assembly language on mac os x... I'm using as instruction to compile assembly file in commend window. but I have several errors.. and I don't know how I can get through.. here is the errors and my assembly code.. which is quite simple. **ung-mi-lims-macbook-pro:pa2 ungmi$ as swap.s swap.s:16:Unknown pse...

x86 assembly question

This is my assembly program which is just a function to swap *x *y. So first argument from main is address of x which is in 8(%ebp) and second one is address of y is in 12(%ebp). The program does swap x and y. I need 7 lines for doing this. can you make it 6 lines and there is a condition you can use only %eax, %ecx, and %edx 3 register...

How Do Assemblers Map x86 Instruction Mnemonics to Binary Machine Instructions?

I'm interested in writing an x86 assembler. I'm wondering what is a good way to map x86 assembly mnemonic instructions (using an Intel-like syntax) into the corresponding binary machine code instructions. ...

x86 CMP Instruction Difference

Question What is the (non-trivial) difference between the following two x86 instructions? 39 /r CMP r/m32,r32 Compare r32 with r/m32 3B /r CMP r32,r/m32 Compare r/m32 with r32 Background I'm building a Java assembler, which will be used by my compiler's intermediate language to produce Windows-32 executables. Currently ...

MOV BX,[SI] - ASM question

Hello,I'm studying ASM 8086 theoretically on highschool. And when I do this: MOV BX,[SI] is SI+1 going to BH or BL? Thank you :-) ...

Building Android NDK Toolchain for x86 Android on Windows via Cygwin

The Android SDK includes the Android NDK, which in turn contains a customised GCC based tool chain for Android on ARM processors; The question is how to build the NDK tool chain to run on Windows to target x86 Android? The tool chain is already setup to build on Windows (cygwin) targeting ARM; There are also existing pre-built (unoffici...

Question about ADD on ASM 8086

Hello, I'm studying ASM 8086 theoretically on highschool. (that means that I study ASM 8086 on a notebook, and never got to run it over a computer). And I don't understand - what will happen if I do this: MOV AL, F2h ADD AL, 20h What will the computer do? (what will be the value of AL,AX, CF,ZF?) and what will happen if I do this: ...