Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MINGW_ASM
- // compile with:
- // gcc -masm=intel -m32 file.c
- int main() {
- unsigned char feld[5]; // Initialize the array with 0
- unsigned char* p_feld = feld; // Set the pointer to the first element of the array
- unsigned short int i;
- #ifdef MINGW_ASM
- printf("Executing assembler code.\n"); // Corrected quotation marks
- asm (
- "mov eax, 4;" // Set the starting index for the loop
- "mov cl, 5;" // Initialize with the value 5
- "loop: mov [eax + %[p_feld]], cl;" // Store 'cl' in the corresponding array element
- "add cl, -1;" // Decrement 'cl'
- "add eax, -1;" // Move to the previous element
- "jge loop;" // Jump back as long as 'cl' >= 0
- :
- : [p_feld] "r" (p_feld) // Update 'p_feld' as an output operand
- : "eax", "cl", "memory" // Registers altered by the assembler
- // memory clobber tells compiler that memory it
- // isn't aware of is being accessed in the assembly
- );
- #else
- printf("Assembler code will not be executed.\n");
- #endif
- // Output the array to see if it contains the expected values
- for (i = 0; i < 5; i++) {
- printf("feld[%d] = %d\n", i, feld[i]);
- }
- return 0; // Successful program termination
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement