Write a 32 bit (x86) Linux assembly language program that prints, one per line,
ID: 3868792 • Letter: W
Question
Write a 32 bit (x86) Linux assembly language program that prints, one per line, the command line arguments used to invoke your program along with all of the environment variables in your programs execution environment. You may not use ANY system calls. Your program must consist solely of a main function and may use only the printf and exit functions from the C standard library. Your program MUST NOToutput anything other than argv and envp values (ie, DO NOT prompt for user input or display any other helpful messages). Your main function must adhere to the following prototype (keep in mind that main uses the cdecl calling convention): int main(int argc, char *argv[], char *envp[]);
Example:
# ./assign3_part2 hello world
./assign3_part2
hello
world
TERM=xterm
SHELL=/bin/bash
PATH=/bin:/usr/bin:/usr/local/bin
PWD=/home/jones
HOME=/home/jones
Explanation / Answer
#include <stdio.h>
void main(int argc, char *argv[], char *envp[])
{
int m;
for (m = 0;m < argc;m++)
{
printf("%s ", argv[m]);
}
printf(" ");
for (m = 0;m < envp;m++)
{
printf("%s ", envp[m]);
}
printf(" ");
}
------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.