NASM Forum > Example Code

Command Line Arguments using NASM and GCC

(1/2) > >>

stressful:
A simple, lightweight code to take command line input to calculate series of SIN values. Should be easy to convert to any trigonometric functions.

--- Code: ---D:\NASM>sine

 Usage: sine v1 v2 vn

D:\NASM>sine 3.4
sin(3.4000) rad = -0.255541

D:\NASM>sine 3.4 0.0 -9.2 7.6 1.5
sin(3.4000) rad = -0.255541
sin(0.0000) rad = 0.000000
sin(-9.2000) rad = -0.222890
sin(7.6000) rad = 0.967920
sin(1.5000) rad = 0.997495
--- End code ---

EDIT: Added 64-bit version (Win64)

stressful:
Just added the 64-bit version for Win64

stressful:
Added Linux versions (32-bit and 64-bit).

I don't know if I have / haven't reached my upload limit on this board (which is 5MB I think). If I have, then the attachments below could be my last token.

Edit: Added "cosr.asm" as an example for using "ld" instead of GCC for command-line arguments.

rajex:
Can you help me understand how the OS calls the binary with the command-line arguments on the stack to the _start subroutine, I can't quite figure out my around esp and ebp.

Frank Kotler:
Hi rajex,
Welcome to the Forum.

In 32-bit code (at least) the "_start:" label is not "call"ed, so is not really a "subroutine". There is no return address on the stack, the first thing is "argc". (unless you've pushed ebp) Usually gcc is not involved in this case, so the "subject" may not be accurate.

My computer recently crashed and I didn't have my code backed up so I don't have an example at the moment. Can rewrite one, but not really in the mood, so see what you can do...

Best,
Frank

Navigation

[0] Message Index

[#] Next page

Go to full version