NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: MrEfizz on July 25, 2015, 01:17:16 PM

Title: Getting input from Command line and adding in NASM
Post by: MrEfizz on July 25, 2015, 01:17:16 PM
ok good morning

i graduated from hello world to area of a triangle using nasm this morning, except that now i want to get input from the user prompts like "Enter First Number", "Enter Second number" then add or whatever

something like this
Code: [Select]
section .data

msg:
db 'Addition is = %d',10,0

section .text
extern _printf
global _main


_main:
push ebp
mov esp,epb

mov eax,5
add eax,2

push eax
push msg

call _printf

pop ebp
mov esp,ebp

ret
Title: Re: Getting input from Command line and adding in NASM
Post by: Bryant Keller on August 26, 2015, 08:43:28 PM
Since you're already using printf, why not use scanf for input. :P
Title: Re: Getting input from Command line and adding in NASM
Post by: Frank Kotler on August 26, 2015, 09:20:19 PM
Well we better get _printf working first. I don't know why I didn't notice it before now, but there's no way this is going to work!
Code: [Select]
section .data

msg:
db 'Addition is = %d',10,0

section .text
extern _printf
global _main


_main:
push ebp
mov esp,epb ; you want to move esp to ebp here!


mov eax,5
add eax,2

push eax
push msg

call _printf

pop ebp ; this is going to get the address of "msg" back off the stack

mov esp,ebp ; and put it in esp

ret ; go boom!
When you're using ebp as a frame pointer, you do NOT want to alter it within the function!

As I recall, we've got a working example of this in the "example code" section - a couple of pages in - called "integer in integer out" or some such...

Best,
Frank

Edit: Well my memory fails me. I can't find the example I had in mind. I could provide a Linux example. A 32-bit example "should" port to 'doze fairly easily. You probably want an example "known" to work in Windows...