Skip to main content

C

Mix (C++ and Assembly) Program to Check if String is Palindrome or not

This C++ program checks whether a given array of five integers is a palindrome (i.e., reads the same forwards and backwards) using inline 8086 assembly instructions. It utilizes basic comparison instructions and control flow to determine equality between symmetric elements. #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 cmp ax, bx jnz no } } cout << "\n Array is Palindrome."; goto end; no: cout << "\n Array is not palindrome."; end: getch(); }

Mix (C++ and Assembly) Program to Search an Element in an Array

This C++ program demonstrates how to search for a specific element within an array of 10 integers using 8086 assembly instructions embedded inline. The program uses the cmp and jz instructions to perform the comparison and detect a match. #include<iostream.h> #include<conio.h> void main() { int nos[10], j, t; int i, p; cout << "\n Enter 10 numbers:"; for (i = 0; i < 10; i++) { cin >> nos[i]; } cout << "\n Enter number to be searched:"; cin >> j; for (i = 0; i < 10; i++) { p = i; t = nos[i]; _asm { mov ax, t // Load current array element mov bx, j // Load number to be searched cmp ax, bx // Compare current element with target jz out // If match found, jump to output } } cout << "\n No is not found."; goto end; out: cout << "\n Number is found at " << p + 1 << " th position"; end: getch(); }

Mix (C++ and Assembly) Program to Add Two 16 bit Numbers

While high-level languages like C++ are well known for abstracting away low-level operations, sometimes it’s beneficial to peek under the hood to see how things really work at the machine level. In this post, we’ll explore a simple C++ program that incorporates inline assembly to add two 16-bit numbers. #include<iostream.h> #include<conio.h> #include<stdio.h> void main() { clrscr(); int a,b,c; cout<<"Enter First Number:"; cin>>a; cout<<"Enter Second Number:"; cin>>b; asm mov ax, a // Move first number into AX asm mov bx, b // Move second number into BX asm add ax, bx // Add BX to AX (binary addition) asm mov c, ax // Move result into variable 'c' cout<<"Result:"; cout<<c; getch(); }

Mix (C++ and Assembly) Program to Add Two 16 bit Numbers (With DAA)

While high-level programming languages like C++ make arithmetic operations incredibly simple, delving into inline assembly offers valuable insights into how the CPU processes instructions under the hood. Hence in this post, we’ll walk through a simple program that uses both C++ and inline assembly to add two integer values. Additionally, we will carry out decimal adjust after addition.

Mix (C++ and Assembly) Program to Subtract Two 16-bit Numbers (With DAS)

While modern high-level languages like C++ abstract away many low-level operations, sometimes it's useful to dive into assembly-level instructions for greater control and understanding. This example demonstrates subtraction using inline assembly in C++, with the addition of the DAS instruction to adjust the result for Binary Coded Decimal (BCD) operations. #include<iostream.h> #include<conio.h> #include<stdio.h> void main() { clrscr(); int a, b, c; cout << "Enter First Number:"; cin >> a; cout << "Enter Second Number:"; cin >> b; asm mov ax, a // Move 'a' into AX asm mov bx, b // Move 'b' into BX asm sub ax, bx // Subtract BX from AX asm das // Adjust AX for BCD subtraction asm mov c, ax // Store result in 'c' cout << "Result:"; cout << c; getch(); }

Mix (C++ and Assembly) Program to Subtract Two 16 bit Numbers

While modern high-level languages like C++ abstract away many low-level operations, sometimes it's useful to get closer to the hardware to understand how things work under the hood. This example demonstrates how to subtract two 16-bit numbers using inline assembly in a simple C++ program. #include<iostream.h> #include<conio.h> #include<stdio.h> void main() { clrscr(); int a, b, c; cout << "Enter First Number:"; cin >> a; cout << "Enter Second Number:"; cin >> b; asm mov ax, a // Move 'a' into AX asm mov bx, b // Move 'b' into BX asm sub ax, bx // Subtract BX from AX asm mov c, ax // Store result in 'c' cout << "Result:"; cout << c; getch(); }

Mix (C++ and Assembly) Program to Add Two 8 bit Numbers

This blog post will guide you through a C++ program that performs the addition of two numbers using inline assembly. While modern compilers provide high-level arithmetic operations, understanding inline assembly can help in optimizing performance and understanding low-level interactions with the CPU. Let's explore this step-by-step! #include<iostream.h> #include<conio.h> #include<stdio.h> void main() { clrscr(); short int a, b, c; cout << "Enter First Number: "; cin >> a; cout << "Enter Second Number: "; cin >> b; asm mov ax, a asm mov ah, 00h asm mov bx, b asm mov bh, 00h asm add al, bl asm mov c, ax cout << "Result: "; cout << c; getch(); }

Mix (C++ and Assembly) Program to Find Whether Number is Odd or Even

This C++ program determines whether a given number is even or odd using 8086-style inline assembly. It utilizes the div instruction to divide the number by 2 and then checks the remainder stored in the dx register. #include<iostream.h> #include<conio.h> void main() { clrscr(); int a, res; cout << "\n Enter a number"; cin >> a; asm mov ax, a // Move input number into AX asm mov bx, 02h // Move divisor 2 into BX asm div bx // Divide AX by BX, quotient in AX, remainder in DX asm mov res, dx // Store remainder in res if(res == 0) { cout << "\n Even"; } else { cout << "\n Odd"; } getch(); }

Mix (C++ and Assembly) Program to Find Whether Number is Positive or Negative

This program demonstrates how to use inline 8086 assembly in C++ to determine whether a given number is positive or negative. It's a great way to understand how conditional branching works at the assembly level. #include<iostream.h> #include<conio.h> void main() { clrscr(); int a; cout << "\n Enter a number:"; cin >> a; asm mov ax, 0000h // Clear AX asm mov ax, a // Move user input into AX asm cmp ax, 0000h // Compare AX with 0 asm jl less // Jump to 'less' if AX < 0 asm jge greater // Jump to 'greater' if AX >= 0 less: cout << "\n Number is negative"; asm jmp end greater: cout << "\n Number is positive"; end: getch(); }