Advertisement
tsnaik

MFP lab 11

Sep 29th, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. *************Addition
  2.  
  3. 1. f1.c
  4.  
  5. #include<stdio.h>
  6. #include<conio.h>
  7.  
  8. int a=60,b=70,c;
  9.  
  10. extern far int addition(int a,int b);
  11.  
  12. void main()
  13. {
  14.  
  15. clrscr();
  16. c=addition(a,b);
  17. printf("Addition=%d",c);
  18. getch();
  19. }
  20.  
  21.  
  22.  
  23. 2. f2.asm
  24.  
  25. ; _ prefix when in asm variables when external
  26.  
  27. extrn _a:word
  28. extrn _b:word
  29. public _addition
  30.  
  31. code segment
  32. assume cs:code
  33.  
  34. _addition proc far
  35.  
  36. mov ax,_a
  37. add ax,_b
  38. ret
  39. _addition endp
  40. code ends
  41. end
  42.  
  43.  
  44. ;turbo C only takes from AX
  45.  
  46.  
  47. **********Cel to fah
  48.  
  49. 1. f1.c
  50.  
  51. #include<stdio.h>
  52. #include<conio.h>
  53.  
  54. int c=60,f;
  55.  
  56. extern far int convert(int c);
  57.  
  58. void main()
  59. {
  60.  
  61. clrscr();
  62. f=convert(c);
  63. printf("f=%d",f);
  64. getch();
  65. }
  66.  
  67.  
  68.  
  69. 2. f2.asm
  70.  
  71. extrn _c:word
  72.  
  73. public _convert
  74.  
  75. code segment
  76. assume cs:code
  77.  
  78. _convert proc far
  79.  
  80. mov ax,_c
  81. mov bx,05
  82. div bx
  83. mov bx,09h
  84. mul bx
  85. mov bx,032
  86. add ax,bx
  87. ret
  88. _convert endp
  89. code ends
  90. end
  91.  
  92.  
  93. ***************LCM
  94.  
  95. 1. C
  96.  
  97. #include<stdio.h>
  98. #include<conio.h>
  99.  
  100. int a=5,b=10,c;
  101.  
  102. extern far int convert(int a,int b);
  103.  
  104. void main()
  105. {
  106. clrscr();
  107. c=convert(a,b);
  108. printf("lcm=%d", c);
  109. getch();
  110. }
  111.  
  112.  
  113.  
  114. 2.
  115.  
  116.  
  117. extrn _a:word
  118. extrn _b:word
  119.  
  120. public _convert
  121.  
  122. code segment
  123. assume cs:code
  124.  
  125. _convert proc far
  126.  
  127. mov ax,_a
  128. mov bx,_b
  129. one: cmp ax,bx
  130. jc loop1
  131.  
  132. loop1: xchg ax,bx
  133. jmp read
  134.  
  135. read: sub ax,bx
  136. jnz one
  137. mov ax,bx
  138. mov ax,_a
  139. mov cx,_b
  140. mul cx
  141. div bx
  142.  
  143.  
  144. ret
  145.  
  146. _convert endp
  147. code ends
  148. end
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. steps:
  161. 1. tasm f2.asm
  162. 2. open tc.exe
  163. 3. options ma case sensitive and output directory to \BIN
  164. 4. add obj and c to project
  165. 5. build all and run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement