Advertisement
Metalhead33

Assembly Code 2

May 28th, 2015
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global main ;Main function - replace with WinMain under Windows
  2. extern printf ;replace with _printf under Windows
  3. extern scanf ;replace with _scanf under Windows
  4.  
  5. section .data ;PRE-DEFINED DATA
  6. intro1 db "Hey! This program is written in NASM - Netwide Assembler.",10,0 ;Intro 1 message
  7. intro2 db "This is my first attempt at using SCANF within ASM. Let's see how it'll turn out.",10,0 ;Intro 2 message
  8. msg db "And here is the prompt: ",0 ;Prompt message
  9. fmt db "%s",0 ;Format - string
  10. limes db " ",10,0 ;To add padding to the end, off course.
  11.  
  12. section .bss ;UNINITIALIZED DATA (variables)
  13. inpt resb 255 ;Reserved for input
  14.  
  15. section .text ;THE PROGRAM CODE ITSELF
  16. main:
  17.     ;Set up our stackframe.
  18.     push ebp ;save the base pointer
  19.     mov ebp, esp ;Moves stack pointer into the base pointer
  20.    
  21.     ;Printing a message
  22.     push intro1 ;Pushed intro1 to the stack
  23.     call printf ;Call printf
  24.     add esp, 4 ;Clear peremiter
  25.  
  26.     ;Printing a message again
  27.     push intro2 ;pushed intro2 into the stack
  28.     call printf ;Call printf
  29.     add esp, 4 ;Clear peremiter
  30.  
  31.     ;Printf again
  32.     push msg ;push msg into the stack
  33.     call printf ;Call printf
  34.     add esp, 4 ;Clear peremiter
  35.  
  36.     push inpt ;Push pointer to INPUT into the stack
  37.     push fmt ;Push the format into the stack
  38.     call scanf ;Call scanf
  39.     add esp, 8 ;Clear the peremiter - 8, because two arguments
  40.  
  41.     push inpt ;Push pointer to the INPUT to the stack
  42.     call printf ;Call printf to output what we got
  43.     add esp, 4 ;Clear peremiter
  44.  
  45.     push limes ;Push limes to the stack
  46.     call printf ;Call printf
  47.     add esp, 4 ;Clear peremiter
  48.  
  49.     ;Destroy our stack frame
  50.     mov esp, ebp ;Restore our stack pointer
  51.     pop ebp ;Get rid of the base pointer
  52. ret ;THE END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement