assembly

Storing data in segments with assembly

Hello everyone! I am learning x86 assembly language, and I understand the purpose and usage of segments. Segments hold vital data, and can also be used to store extra data (ie. Memory Segmentation Model). Here is my question though. If segments can be used to store extra data, how can I make sure that my storing data in them won't overwr...

Alter Interrupt in 16 bit Real Mode

I'm trying to alter my interrupt table to take over the keyboard interrupt. My end goal is to write my new interrupt routine, copy myself into RAM and make the real-mode interrupt table point to me. I have found random sample code online but it is missing explanations on how to get the address of the original interrupt. They simply ha...

Inline Assembler: What scratch registers can be used?

When inserting inline assembler into a function in a C-like language, what is the convention about what registers you're allowed to use for scratch? Is it the compiler's responsibility to save the values of all the registers it needs to save before entering the asm block? Is it the responsibility of the programmer to store the values i...

Addl instruction, x86

You'll have to excuse me, I'm brand new to x86 assembly, and assembly in general. So my question is, I have something like: addl %edx,(%eax) %eax is a register which holds a pointer to some integer. Let's call it xp Does this mean that it's saying: *xp = *xp + %edx? (%edx is an integer) I'm just confused where addl will store the r...

What techniques to avoid conditional branching do you know?

Sometimes a loop where the CPU spends most of the time has some branch prediction miss (misprediction) very often (near .5 probability.) I've seen a few techniques on very isolated threads but never a list. The ones I know already fix situations where the condition can be turned to a bool and that 0/1 is used in some way to change. Are t...

Compiling assembly for windows on linux

This is a homework task, but it's very simple. The task comes with a working assembly file. I just need help to compile it on linux instead of windows. I'm using Ubuntu. I've installed mingw32. The task itself is to add some functionality, not compiling it. The file itself is here: here. To much code for including it, and besides the c...

Running code on different processor (x86 assembly)

In real mode on x86, what instructions would need to be used to run the code on a different processor, in a multiprocessor system? (I'm writing some pre-boot code in assembler that needs to set certain CPU registers, and do this on every CPU in the system, before the actual operating system boots.) ...

Inline io wait using MASM

How to convert this to use VC++ and MASM static __inline__ void io_wait(void) { asm volatile("jmp 1f;1:jmp 1f;1:"); } I know asm changes to __asm and we remove the volatile but whats next? I am trying to create the function to place in the code below #define PIC1 0x20 #define PIC2 0xA0 #define PIC1_COMMAND PIC1 #define PIC1_DATA...

How can I figure out which architecture I'm compiling for in GCC?

I want to write code that compiles easily for either 32 or 64 bit linux under gcc. I guess I'm looking for something like #ifdef IA32 subl $0x4, %esp #endif #ifdef X86_64 subl $0x4, %rsp #endif ...

Visual C++ Assembly link library troubles

Hi. I'm having a problem having my projects built in VC++ Express 2008... I'm using a library, irvine32.inc/lib. INCLUDE Irvine32.inc works for me at school (On already configured VS environments) by default, but at home (Windows 7 x64) I'm having a boatload of issues. My original post here was that a file that irvine32.inc referenced, ...

Micro-controller 8051: How to get addresses of inputs to JB & CJNE instructions?

I'm implementing whole set of 8051 instructions in VHDL from scratch. Most of things went well but stumbled on these 2 instructions: JB bit,rel 00100000 bit_address rel_address CJNE A,#data,rel 10110100 immediate_data rel_address Any help or hint is greatly appreciated. Thank you in advance! ...

IRQ Numbering Conflict

From: http://software.intel.com/en-us/articles/introduction-to-pc-architecture/ Exception number 10h corresponds to a "Floating Point Error" but software interrupt 10h also corresponds to "Video support" BIOS interrupts (both in real mode). What am I missing? ...

Assembly Programming and Interrupt Handling

I'm writing a program in assembly using MIPS architecture for a class, and I'm having trouble figuring out how to grab an input character by a user and store it in a register to process. The program would open a console, output a message, the user can then input a character and then this determines what is supposed to happen next in the...

DOS assembly Simple math

I have a number stored in dl, and I need this to work for numbers up to three digits? Here is the working code for digits 0-9. WriteNumber: ;; print out number in dl push ax push dx add dl,"0" mov ah,02h ; printing one char int 21h pop dx pop ax ret For example, for two digits. I could take dl/10. And then print out the result and th...

What's the low-level difference between a pointer an a reference?

If we have this code: int foo=100; int& reference = foo; int* pointer = &reference; There's no actual binary difference in the reference's data and the pointer's data. (they both contain the location in memory of foo) part 2 So where do all the other differences between pointers and references (discussed here) come in? Does the com...

DOS assembly read two succeeding characters, and convert to number

I'm writing a simple program that takes in two numbers between 1-99, adds them and prints out the result. I'm done with the printing part, I can print up too three digits, 99+99=198 so it's enough for this program. I have the program working for two one digit numbers. Example: 1 1 = 2 , 4 4 = 8 So the digits is separated by spaces. ...

Linux assembly woes

Is there really no way to print an ascii string in assembly to standard output without using up all four general purpose registers? ...

How are things stored in stack?

So I have been learning assembly and came to the topic of stack, storing local, static and global variable and stuff. But I'm having a hard time imagining it in my head. Bottom of memory but top of stack, :S whaa?? The thing that got me confused is, every time something gets push(ed) into stack, stack pointer gets subtracted. Shouldn'...

Need a debugger for Dos Assembly

Hi, I'm trying badly to track down a debugger for DOS assembly, it's really hard to debug this code and I need a debugger. Does anyone out there know where I can download any version of turbo debugger? ...

How do I write to a different thread's stack in C/C++?

I know this is a bad idea! Certainly for safe programming the stack for a given thread should be considered private to that thread. But POSIX at least guarantees that all of a thread's memory is shared and writeable by other threads, which means the stack of one thread can (in theory) be written to by another thread. So I'm curious how o...