Mix (C++ and Assembly) Program to Find Reverse of an Array
This post explores how to reverse an array of integers using inline assembly within a C++ program. The program swaps elements from the start and end of the array using low-level assembly instructions. #include<iostream.h> #include<conio.h> void main() { int nos[5], x, y; cout << "\n Enter 5 numbers:"; int i, j; for(i = 0; i < 5; i++) { cin >> nos[i]; } for(i = 0, j = 4; i < 3; i++, j--) { x = nos[i]; y = nos[j]; _asm{ mov ax, x mov bx, y mov cx, ax mov ax, bx mov bx, cx mov x, ax mov y, bx } nos[i] = x; nos[j] = y; } cout << "\n Reverse:"; for(i = 0; i < 5; i++) { cout << nos[i] << " "; } getch(); }