How to include Assembly Code in C Program? - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

How to include Assembly Code in C Program?

Share This

Assembly Language can be Written in C. C Supports Assembly as well as Higher Language Features so-called "Middle-Level Language".

Assembly level code in C Program
#include <stdio.h> void main() { int a = 3, b = 3, c; asm { mov ax,a mov bx,a add ax,bx mov c,ax } printf("%d",c); }

As shown in above Program, "asm" Keyword is written to indicate that "next followed instruction is from Assembly Language"; such as asm mov ax,a indicates that the line of instruction is assembly level code (applicable for single line code). Opening Curly brace after "asm" keyword tells that it is the "Start of Multiple Line Assembly Statements" i.e "We want to Write Multiple Instructions".
Above Program Without "Opening and Closing Brace" can be written as - "asm" keyword before every Instruction. In 8086 Assembly Program for Storing Values AX, BX, CX, DX registers are used called General Purpose Registers.

Move Instruction (asm mov ax,a) Copies content of Variable "a" into Register "AX". Add Instruction adds Content of two specified Registers and Stores Result in "ax" in above example. Copy Result into Variable "c".



Happy Exploring!

No comments:

Post a Comment