learn,how to mix C and Assembly Language ?, Basic Computer Science

The technique to mix C and assembly language is to apply the "asm" directive. To access C-language variables from assembly language, you just use the C identifier that name is a memory operand. These variables cannot be local to a procedure, and also cannot be static within a procedure. They have to be global (but can be static global). The newline characters are essential.
unsigned long a1, r;
void junk( void )
{
asm(
"pushl %eax \n"
"pushl %ebx \n"
"movl $100,%eax \n"
"movl a1,%ebx \n"
"int $59 \n"
"movl %eax,r \n"
"popl %ebx \n"
"popl %eax \n"
);
}

This instance does the following:
1. Pushes the value stored in %eax and %ebx onto the stack.
2. Puts a value of 100 into %eax.
3. Copies the value in global variable a1 into %ebx.
4. Executes a software interrupt number 59.
5. Copies the value in %eax into the global variable r.
6. Restores (pops) the contents of the temporary registers %eax and %ebx.
Posted Date: 5/4/2012 8:26:11 AM | Location : United States







Related Discussions:- learn,how to mix C and Assembly Language ?, Assignment Help, Ask Question on learn,how to mix C and Assembly Language ?, Get Answer, Expert's Help, learn,how to mix C and Assembly Language ? Discussions

Write discussion on learn,how to mix C and Assembly Language ?
Your posts are moderated
Related Questions
Indexing and Abstracting Databases: A study of growth of indexing and abstracting services over the years would show that during the past two centuries, these services have be

Number data types store numeric values. They are an immutable data type, which means that changing the value of a number data type results in a newly allocated object. Number objec

Memory unit of computer: The Memory  unit is an important component of a computer where all the data and information are stored in the form  of binary digits (combination of 0

Printer output : Consider what is required here. Do you just require management information on the one hand or camera copy for reprographic purposes? Inkjet Very quiet. C


They are utilized to move the contents of the operators. Each instruction can be used with many different modes of addressing. MOV MOVS (MOVSB) (MOVSW) MOV INSTRUCTION Principle: D

Mike sells on the average 15 newspapers per week (Monday – Friday). Find the probability that 2.1 In a given week he will sell all the newspapers

Write a half-page summary explaining IP spoofing.

A rock weighs 33.6 N on Planet X and 49 N on Earth. What is g on Planet X

The skill of Assembly Language Programming (AoA), Randy Hyde''s acclaimed text on assembly language programming, is the most-frequently recommended book on 80x86 assembly language