Tag Archives: C
Implementing Macro Processor in C
A macro processor is a fundamental system program designed to streamline the programming process by replacing macro instructions within a source code with their pre-defined sequences of statements. This implementation provides a basic macro processor written in C.
This C program functions by reading an assembly language program that may contain macro definitions and macro calls. The input assembly code is expected to be provided in a file named MACIN.TXT
. The core functionality of this processor involves:
- Macro Definition Detection: Identifying and parsing macro definitions within the input source code.
- Macro Definition Storage: Storing the identified macro definitions in a dedicated data structure known as the Macro Definition Table (MDT).
- Macro Expansion: When macro calls are encountered in the input, the processor retrieves the corresponding definition from the MDT and substitutes the macro call with the stored sequence of assembly language statements.
The final expanded assembly code, with all macro calls replaced by their respective bodies, is then written to an output file named MACOUT.TXT
. This process effectively automates the expansion of commonly used code blocks, reducing redundancy and improving code readability and maintainability.
Implementing Multi-pass Assembler in C
Here is implementation of multi-pass assembler in C. You have to provide Assembly Language Program, MOT table and POT table as input.
Mix (C++ and Assembly) Program to Find Largest Number from Given Numbers
This C++ program demonstrates how to find the largest element from a set of five integers using 8086 assembly instructions embedded directly into the code. The inline assembly helps perform comparisons and updates the result with the highest value found.
Continue reading Mix (C++ and Assembly) Program to Find Largest Number from Given NumbersMix (C++ and Assembly) Program to Sort Numbers in Ascending Order
This post demonstrates how to sort an array of integers using inline assembly in C++. Here, we perform sorting in ascending order by comparing and swapping adjacent elements using embedded assembly within a C++ program.
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5], x, y;
int i, j;
cout << "\n Enter 5 Numbers:";
for(i = 0; i < 5; i++)
{
cin >> a[i];
}
//Sorting
for(i = 0; i < 4; i++)
{
for(j = 0; j < 4; j++)
{
x = a[j];
y = a[j + 1];
_asm {
mov ax, x
mov bx, y
cmp ax, bx
jl nxt
mov cx, ax
mov ax, bx
mov bx, cx
mov x, ax
mov y, bx
}
nxt:
a[j] = x;
a[j + 1] = y;
}
}
cout << "\n Sorted Array:";
for(i = 0; i < 5; i++)
cout << a[i] << " ";
getch();
}
Mix (C++ and Assembly) Program to Find Smallest Number from Given Numbers
This C++ program demonstrates how to find the smallest number from an array using inline 8086 assembly language instructions. The logic involves comparing each array element and storing the smallest found so far using cmp
and conditional jump instructions.
#include<iostream.h>
#include<conio.h>
void main()
{
short a[5], x, y, res;
short i, j;
y = 999; // Initialize with a large number
cout << "\n Enter 5 Numbers:";
for (i = 0; i < 5; i++) {
cin >> a[i];
}
asm {
mov bx, y
}
// Finding smallest
for (i = 0; i < 5; i++) {
x = a[i];
asm {
mov ax, x
mov bx, y
cmp ax, bx
jnb nxt // Jump if not below (i.e., current is not smaller)
mov bx, ax
mov y, bx
}
nxt:
}
asm {
mov res, bx;
}
cout << "\n Smallest Element:" << res;
getch();
}
Mix (C++ and Assembly) Program to Count Number of 0’s and 1’s
This post demonstrates how to count the number of 0
s and 1
s in the binary representation of an integer using inline assembly in a C++ program. This is an excellent example of bit-level operations using low-level assembly instructions.