C Program to Write inline assembly language code in C Program
Add Two Numbers Using Inline Assembly Language ???
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #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); } |
- Assembly Language can be Written in C .
- C Supports Assembly as well as Higher Language Features so called “Middle Level Language”.
- As shown in above Program , “asm” Keyword is written to indicate that “next followed instruction is from Assembly Language”.
1 | asm mov ax,a |
- 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 ]
1 2 3 4 | asm mov ax,a asm mov bx,a asm add ax,bx asm mov c,ax |
What above Program Actually Does ?
- In 8086 Assembly Program for Storing Values AX,BX,CX,DX registers are used called General Purpose Registers .
1 | asm mov ax,a |
- Move Instruction 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”