Author Topic: Getting input from Command line and adding in NASM  (Read 4514 times)

Offline MrEfizz

  • New Member
  • Posts: 1
Getting input from Command line and adding in NASM
« 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

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: Getting input from Command line and adding in NASM
« Reply #1 on: August 26, 2015, 08:43:28 PM »
Since you're already using printf, why not use scanf for input. :P

About Bryant Keller
bkeller@about.me

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2505
  • Country: us
Re: Getting input from Command line and adding in NASM
« Reply #2 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...
« Last Edit: August 26, 2015, 10:02:24 PM by Frank Kotler »