NoamCohen123

assembly

Jul 17th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. // ASSEMBLY_FINAL.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9.  
  10. int function()
  11. {
  12.     // Print the return address of the function.
  13.     __asm
  14.     {
  15.         mov eax, [ebp + 4]
  16.     }
  17. }
  18.  
  19. int assmbly_power()
  20. {
  21.     __asm
  22.     {
  23.         mov cl, 10
  24.         mov eax, 1
  25.         L1:
  26.         mov ebx, 1
  27.             shl ebx, cl
  28.             add eax, ebx
  29.  
  30.             DEC cl
  31.             jnz L1
  32.  
  33.     }
  34. }
  35.  
  36. int get_val(int x, char *format)
  37. {
  38.     // pass a value to a function and print it with assembly.
  39.     __asm
  40.     {
  41.         mov eax, x
  42.         push eax
  43.         mov eax, format
  44.         push eax
  45.         call printf
  46.         pop ebx
  47.         pop ebx
  48.  
  49.     }
  50.  
  51.  
  52. }
  53. void main()
  54. {
  55.     char format[] = "%d is the number you entered";
  56.     int return_address = 0, i = 0, j = 0;
  57.     return_address = function();
  58.     i = assmbly_power();
  59.     printf("%d\n", i);
  60.     /*
  61.     __asm
  62.     {}
  63.     */
  64.     get_val(3, format);
  65.     printf("%d", j);
  66.     scanf("%d", &i);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment