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(); }