ASSEMBLY LANGUAGE PROGRAMMING BY C

Assembly language programming by c programming language using asm keyword questions, answers and explanation

(1) What will be output of following c program?

#include<stdio.h>
int main(){

asm{
      mov ax,61;
      mov bx,10;
      add bx,ax;
    }
printf("\n%d",_BX);

return 0;
}

Output: 71
Explanation:

ax and bx is general purpose register. Statement mov ax, 61 means value 61 is storing at register ax. Statement add bx, ax mean addition of content of register bx i.e 10 and content of register ax i.e. 61 and result of addition is storing at register bx.

(2) What will be output of following c program?

#include<stdio.h>
int main(){

asm{
          mov ax,10;
          mov bx,20;
         mov cx,30;
         add ax,bx;
          sub ax,cx;
   }
printf("%d",_AX);
return 0;
}

Output: 0

Explanation:
Same concept as in question 1

Mnemonic sub means subtraction.

(3) What will be output of following c program?

#include<stdio.h>
int main(){

asm{
      mov ax,10;
      mov bx,20;
      mov cx,30;
      add ax,bx;
      add bx,cx
   }
printf("%d  %d   %d",_AX,_BX,_CX);
return 0;
}

Output: 30 50 30

Explanation: same concept as in question 1.

(4) What will be output of following c program?

#include<stdio.h>
int main(){

asm{
      mov ax,10;
      mov cx,20;
      inc cx;
      div 2;
   }
   printf("%d ",_AX);
   return 0;
}

Output: Compile time error
Explanation:

Mnemonic in c means increment content of register by one. Mnemonic div means division with ax. Operand of div must be a register not a value.

Note. Register ax is known as accumulator.

(5) What will be output of following c program?

#include<stdio.h>
int main(){
asm{
      mov ax,15;
      mov cx,12;
      mov bx,3;
      div bx;
   }
   printf("%d ",_AX);
   return 0;
}

Output: 5
Explanation:

Mnemonic div means division of its operand with content of accumulator i.e. ax. Meaning of div bx means 15/3.

(6) What will be output of following c program?

#include<stdio.h>
int main(){
asm{
      mov ax,15;
      mov bx,3;
      inc bx;
      mul bx;
   }
   printf("%d ",_AX);
   return 0;
}

Output: 60
Explanation:

Mnemonic mul means multiplication of its operand with content of accumulator i.e. ax. Meaning of mul bx means 15*4.

Note: inc bx means increase the content of register bx by one.

(7) What will be output of following c program?

#include<stdio.h>=
int main(){
int i=0;

asm mov dx,25;
for(i=0;i<5;i++)
asm dec dx;
printf("%d ",_DX);
return 0;
}

Output: 20
Explanation:

dec dx means decrease the content of register dx by one.

(8) What will be output of following c program?

#include<stdio.h>
int main(){
int j=5;
asm mov cx,10;

asm OR cx,j;
printf("%d ",_CX);
return 0;
}

Output: 5
Explanation:

Mnemonic or means bitwise OR operations between its operands.

(9) What will be output of following c program?

#include<stdio.h>
int main(){
asm {
      mov ax,15;
      mov dx,2;
      and dx,ax;
      not ax;
     }
printf("%d %d ",_AX,_DX);
return 0;
}

Output: -16 2
Explanation:

Mnemonic and means bitwise AND operations between its operands.

(10) What will be output of following c program?

#include<stdio.h>
int main(){
      asm mov ax,15;
      asm mov bx,5;
      india:
      asm inc ax;
      asm dec bx;
      asm jnz india;
printf("%d ",_AX);
return 0;
}

Output: 20
Explanation:

Statement jnz India means jump to label india till content of last register i.e. bx is not zero. When content of register bx became zero then stop the jumping.

(11) What will be output of following c program?

#include<stdio.h>
int main(){
      asm mov ax,15;
      asm mov bx,1;
      india:
      asm xor ax,5;
      asm dec bx;
      asm jz india;
printf("%d ",_AX);
return 0;
}

Output: 15
Explanation:

Statement jz India means jump to label india till content of last register i.e. bx is zero. When content of register bx became not zero then stop the jumping.

(12) Write an assembly language program in c program to find out factorial of given number?

No comments: