Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global main ;Main function - replace with WinMain under Windows
- extern printf ;replace with _printf under Windows
- extern scanf ;replace with _scanf under Windows
- section .data ;PRE-DEFINED DATA
- intro1 db "Hey! This program is written in NASM - Netwide Assembler.",10,0 ;Intro 1 message
- 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
- msg db "And here is the prompt: ",0 ;Prompt message
- fmt db "%s",0 ;Format - string
- limes db " ",10,0 ;To add padding to the end, off course.
- section .bss ;UNINITIALIZED DATA (variables)
- inpt resb 255 ;Reserved for input
- section .text ;THE PROGRAM CODE ITSELF
- main:
- ;Set up our stackframe.
- push ebp ;save the base pointer
- mov ebp, esp ;Moves stack pointer into the base pointer
- ;Printing a message
- push intro1 ;Pushed intro1 to the stack
- call printf ;Call printf
- add esp, 4 ;Clear peremiter
- ;Printing a message again
- push intro2 ;pushed intro2 into the stack
- call printf ;Call printf
- add esp, 4 ;Clear peremiter
- ;Printf again
- push msg ;push msg into the stack
- call printf ;Call printf
- add esp, 4 ;Clear peremiter
- push inpt ;Push pointer to INPUT into the stack
- push fmt ;Push the format into the stack
- call scanf ;Call scanf
- add esp, 8 ;Clear the peremiter - 8, because two arguments
- push inpt ;Push pointer to the INPUT to the stack
- call printf ;Call printf to output what we got
- add esp, 4 ;Clear peremiter
- push limes ;Push limes to the stack
- call printf ;Call printf
- add esp, 4 ;Clear peremiter
- ;Destroy our stack frame
- mov esp, ebp ;Restore our stack pointer
- pop ebp ;Get rid of the base pointer
- ret ;THE END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement