Converting assembly code to machine code in C manually [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I've been given a practise homework to do from college which requires me to manually convert assembly code to machine code. I will display the images of what the before and after looks like. It basically requires my to remove the comments (after semi colon) and white spaces after the instruction. I found this to be puzzling since im a C noob and ive been thrown into assembly code. I am planning to do this in notepad++. The assembly language im using is meant to be very simplified since x86 would be ridiculous to start off on. Any help would be appreciated!

As stated in the comment, this has nothing to do with machine code, it's just trivial string manipulation (essentially, it's sed 's/[[:space:]]*\(;.*\)\?$//'):
Read a line
Walk the string one character at time; each time you find a non-whitespace character, write down its position in a variable.
When you find either the end of the string (character 0) or a semicolon (character ';'), truncate the string to the character following the last non-whitespace one you found (effectively, set it to zero).
Write down the updated string to the other file.
Repeat until the input file is finished.

Related

Count amount of words, characters, newlines in C [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I know it is not recommended to post code as an image, since I am getting a formatting error when trying to post code on here. Anyway, I am trying to write a simple C program to count number of words, characters, newlines using do while loop. However, the output is not as expected. Please help!
Instead of a do-while, you should try using while. Since your code starts off by checking whether a is any of your if cases, it goes to the else case, and increments the New line variable. If possible, could you share the output screen.

C programming language,how to convert input string in code and run it [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Is there a way to transform what the user inputs in code?
like
if
char k[50];
printf("insert the code to insert");
scanf("%s", &k);
function =>
converts string and execute the string if the code is correct
for example
if the user insert "int a = 0;"
as input , the program run the input string?
What you're looking for is essentially something like the eval function that some languages has.
Nope, there is not a way to do that. At least not in a practical way. The reason is quite simple. In C, you need to compile the complete program before you run it. If there is even a single syntax error in you 10k+ lines of code, you will not get an executable binary from the compiler.
Python on the other hand can execute line by line. That's why you can execute Python code that has syntax errors. The program will not crash until you encounter the error.
Besides, you should always think twice before using something like this irregardless of the language. The risks for vulnerabilities are extremely high.
Contrary to some other languages, the C language doesn't have an eval function to do what you want. The only option is to write the source file into a file and then execute the compiler available on the host machine.

Find the number of characters from the first character of nth occurrence of a character in a text file without using an array and strchr function? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Fore example lets assume the following is a text in a file:
"I want to find number of characters from the first character is the nth occurrence of a character in a text file, but, I want to do this without declaring an array, storing the text file in it and applying the strchr function."
Lets say I want to find the position of the second new line character in the text? How many number of characters is the new line from the first character in the text? For e.g. The first occurrence character 't' is the 6th character of the text file.
If it is possible can someone please explain how? If no, can someone please explain why?
That can be done in an operating system that supports memory mapped files. This includes Windows and POSIX operating systems such as Linux.
In POSIX it is done using mmap(); there is example code in the documentation.
For Windows there is an API for for memory mapped files. Again, sample code is included in the documentation.

why are only underscores used in c to name variables? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
why not other special symbols? Is this problem solved in advanced languages? I searched for this topic but didn't got satisfactory answer. Is the value of underscore is special(ASCII)? Hope I will find a good answer. Thanks..
Because that's the way the language is specified: see K&R appendix A section 2.2 (original ed) or 2.3 (2nd ed). The _ isn't special other than it is allowed to be used by the C specification.
If you look a bit further, you will see that most of the other punctuation characters are used as operators of one kind or another so you don't have much else to use for variable names anyway.
Some of us are old enough to remember the days when (on some compilers) the $ character was also allowed.
Generally White spaces are not allowed in C
In order to seperate word and word in names programmers use '_' there is no certain specific reason but it is better for readability rather than other special symbols
Try this
aditya*kiran
aditya_kiran
the second one is more readable

What does "end-of-file" mean in C [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to learn C, and am having difficulty understanding what end-of-file means, in terms of a statement like "if fgets() attempts to read past the end of file".
I understand that one can mark an EOF by pressing certain key combos, and that char '\0' represents an EOF, but there must be something basic that I'm not understanding regarding my question, and I hope someone can help explain it to me>
A file is a finite sequence of bytes, just like a book is a finite sequence of words. Eventually you reach the end and there's nothing more to read.
A null character does not represent the end of a file, by the way — you're probably confusing that with the null character used to mark the end of a string in memory in C/C++. That's unrelated to files.

Resources