Tag Archives: MP

Mix (C++ and Assembly) Program to Find Square/Cube/Factorial of a Number

This program demonstrates how to calculate the square, cube, or factorial of a number using 8086 inline assembly in C++. It presents a menu-based approach for the user to choose an operation and performs the calculation using the mul instruction in assembly.

Continue reading Mix (C++ and Assembly) Program to Find Square/Cube/Factorial of a Number

Mix (C++ and Assembly) Program to Perform Signed & Unsigned Multiplication and Division

This post walks through a C++ program that demonstrates how to perform basic arithmetic operations like multiplication and division using inline assembly. It allows the user to choose between signed/unsigned multiplication and division in a loop until they decide to exit.

Continue reading Mix (C++ and Assembly) Program to Perform Signed & Unsigned Multiplication and Division

Mix (C++ and Assembly) Program to Subtract Two 8 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 8-bit numbers using inline assembly in a simple C++ program.

#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      // Move 'a' into AX
    asm mov ah, 00h    // Ensure AH is cleared
    asm mov bx, b      // Move 'b' into BX
    asm mov bh, 00h    // Ensure BH is cleared
    asm sub al, bl     // Subtract BL from AL
    asm mov c, ax      // Store result in 'c'

    cout << "Result:";
    cout << c;

    getch();
}
Continue reading Mix (C++ and Assembly) Program to Subtract Two 8 bit Numbers

8086 Assembly Program to Search an Element in an Array

In this blog post, we’ll explore how to search for an element in an array using an 8086 assembly language program. The following code snippet demonstrates this process:

DATA SEGMENT
STRING1 DB 11H,22H,33H,44H,55H
MSG1 DB "FOUND$"
MSG2 DB "NOT FOUND$"
SE DB 33H
DATA ENDS

PRINT MACRO MSG
MOV AH, 09H
LEA DX, MSG
INT 21H
INT 3
ENDM

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AL, SE
LEA SI, STRING1
MOV CX, 04H

UP:
MOV BL,[SI]
CMP AL, BL
JZ FO
INC SI
DEC CX
JNZ UP
PRINT MSG2
JMP END1

FO:
PRINT MSG1

END1:
INT 3
CODE ENDS
END START
Continue reading 8086 Assembly Program to Search an Element in an Array

Mix (Assembly and C++) Program to Find Greatest of Two Numbers

This program demonstrates how to compare two integers using 8086 inline assembly in C++. By leveraging assembly instructions like sub and conditional jump js, the program determines which number is greater.

#include<iostream.h>
#include<conio.h>

void main() {
    clrscr();
    short a;
    short b;

    cout << "\n Enter First Number:";
    cin >> a;

    cout << "\n Enter Second Number:";
    cin >> b;

    asm mov ax, 0000h        // Clear AX
    asm mov bx, 0000h        // Clear BX
    asm mov ax, a            // Load first number into AX
    asm mov bx, b            // Load second number into BX
    asm sub ax, bx           // Subtract BX from AX
    asm js true              // Jump if result is negative (AX < BX)

    cout << "\n " << a << " is greater than " << b;
    asm jmp end              // Skip 'true' block

true:
    cout << "\n " << b << " is greater than " << a;

end:
    getch();
}
Continue reading Mix (Assembly and C++) Program to Find Greatest of Two Numbers

8086 Assembly Program to Print ‘hello’ using 09H

Displaying a string using DOS interrupt 21H function 09H is a straightforward way to print messages to the screen in 8086 assembly language. This blog post explores an 8086 assembly program that prints the string ‘hello’ to the console.

data segment
msg1 db 'hello$'
data ends

code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov sp,0d00h
mov ah,09h
int 21h
mov ax,4c00h
int 21h
int 3
code ends
end start
Continue reading 8086 Assembly Program to Print ‘hello’ using 09H

Interrupting BIOS with 8086 Assembly Program

Interacting with BIOS interrupts in 8086 assembly language is a crucial technique for handling low-level hardware operations. This blog post explores an 8086 assembly language program that invokes BIOS interrupts to manipulate the screen cursor position and handle user input.

code segment
assume cs:code
start:
mov sp, 7000h
mov ah, 01
mov ch, 00
mov cl, 14
int 10h
mov ah, 02
mov bh, 00
mov dh, 23
mov dl, 10
int 10h
mov ax, 4c00h
int 21h
int 3
code ends
end start
Continue reading Interrupting BIOS with 8086 Assembly Program