Hey all, is there anyway I can pass bash variables to an assembly program, is the only way through C++
19 replies to this topic
#1
Posted 27 July 2011 - 06:23 AM
|
|
|
#2
Posted 27 July 2011 - 09:06 AM
Nah, impossible :-P ... Actually fairly easy... You would have to parse the command line of your app when it starts. Right, you are talking about something like: myapp.exe foo > bar or whatever you want to pass to your app?
#3
Posted 27 July 2011 - 12:13 PM
I dnt kno what that means...I'm working in Linux and what is being redirected and to where? but I figured I can get bash create a file then get my assembly program to read it and then return results in file, then bash script will read file and delete the file after....that's the best thing I can think off, unless there is a cooler way to do it
#4
Posted 27 July 2011 - 12:30 PM
this is a command line: nasm -f elf myfile.asm
similar to how you assemble in linux right? nasm would be your exe and the parameters are -f elf and myfile.asm... nasm gets the commandline and parses it for the different parts.. I don't use linux but found this (google is your best friend programming) :-P Writing A Useful Program With NASM
similar to how you assemble in linux right? nasm would be your exe and the parameters are -f elf and myfile.asm... nasm gets the commandline and parses it for the different parts.. I don't use linux but found this (google is your best friend programming) :-P Writing A Useful Program With NASM
#5
Posted 27 July 2011 - 12:58 PM
How do I access the values passed in command line ,inside my program....
#6
Posted 27 July 2011 - 06:34 PM
main:
push ebp
mov ebp, esp
sub esp, 12 ; save space for 3 local int variables
mov ecx, [ebp + 8] ; ECX = argc
mov edx, [ebp + 12] ; EDX = argv
mov eax, [edx] ; EAX = argv[0]
mov ebx, [edx + 4] ; EBX = argv[1]
; ...your code here...
add esp, 12 ; deallocate local variables
pop ebp
ret
This is just an example. The 12 bytes of local variables was arbitrary; you can have whatever you want there, or even nothing. Also note that this is 32-bit code.
Edited by dargueta, 27 July 2011 - 09:05 PM.
Fixed code
sudo rm -rf /
#7
Posted 27 July 2011 - 08:46 PM
Quote
mov ecx, [ebp + 4]
EBP+4? No return instruction pointer?
I mean, in Windows I use the RET instruction and it exits nicely.
And also, NASM accepts 0x* syntax, too, as well as *h.
#8
Posted 27 July 2011 - 09:05 PM
Windows and Linux do things differently. For some reason ret segfaults on me some times and not others; I still haven't really managed to figure it out.
And yes, I'm aware NASM accepts the 0x syntax. I learned assembly language on an older assembler that only understood the *H syntax.
And yes, I'm aware NASM accepts the 0x syntax. I learned assembly language on an older assembler that only understood the *H syntax.
sudo rm -rf /
#9
Posted 27 July 2011 - 09:14 PM
I just think 0x* looks better. Though I still have to use *h on MASM32.
How does Linux/Unix tell whether it's the next command line argument or not, when it makes that argv array?
How does Linux/Unix tell whether it's the next command line argument or not, when it makes that argv array?
#10
Posted 27 July 2011 - 09:27 PM
Typically it depends on what invoked the program. Different shells divide the arguments different ways. For example, with bash, a string in double quotes is considered a single argument. DOS, at least in the last version I used (XP I think) ignores the quotes, so something like this:
cd "C:\Documents and Settings"
Will get you an error along the lines of "directory not found." You have to do it the dinosaur way and type
cd C:\Docume~1
Basically what shells do is read in the command line, parse it their own way, turn it into a string array and pass it to execve(), execvp() or some similar function. I did something like this a while back for a CS class I was taking.
cd "C:\Documents and Settings"
Will get you an error along the lines of "directory not found." You have to do it the dinosaur way and type
cd C:\Docume~1
Basically what shells do is read in the command line, parse it their own way, turn it into a string array and pass it to execve(), execvp() or some similar function. I did something like this a while back for a CS class I was taking.
sudo rm -rf /
#11
Posted 01 August 2011 - 03:01 AM
I have two question:
1. so say i have a program called runner( this is the .exe ) i can then type
./runner 12 ( some random value 12 being passed to runner )
can i access the value 12 through the stack frame ?
2. is 12 passed as a chars, if thats the case i assume i have to create an integer variable
1. so say i have a program called runner( this is the .exe ) i can then type
./runner 12 ( some random value 12 being passed to runner )
can i access the value 12 through the stack frame ?
2. is 12 passed as a chars, if thats the case i assume i have to create an integer variable
#12
Posted 01 August 2011 - 07:52 AM
Like in C/C++, everything is passed in as character strings (pointers to strings, actually) and you're expected to convert everything you need to the appropriate format. So you're either going to have to link with the standard C library and use strtol() or atoi(), or write your own version. If you write your own, go with atoi(), as it's much simpler.
sudo rm -rf /
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









