Can Endianess of system be changed using c code [closed] - c

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 6 years ago.
Improve this question
I know that endianess little or big is inherent to the system. Then, how is it possible to change using c code, as I have seen a code, which says it can change the endianess.

Endianess depends on the CPU hardware. So normally you can't do anything about it.
The code you have seen was most likely just tossing bytes around from one endianess to the other. Though some CPUs (for example some PowerPC) do have the possibility to configure endianess by writes to a hardware register.

You can't change the endianness of the system in general (there are bi-endian architectures), this would require you to change the instruction set. You can change the endianness of the data you use though. Take a look at this question to see how.

Related

Undefined operations on integers in c [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 5 years ago.
Improve this question
I am trying to learn about integer representations in c and I am having a lot of difficulty understand the fact that some operations are undefined meaning they are inconsistent among systems. I find a lot of sources claiming to teach about how these things work sometimes slip in things that are specific to the architecture they are coding for.
When I am coding I intend never to rely on undefined behaviors that happen to work a certain way on most processors.
What is the definitive truth of what happens in c (across all systems) when things like truncation, extension, comparison are done and when unsigned and signed types are included in casting and arithmetic. Which of these operations have a defined behavior across all systems?
The definitive truth is the C standard. Links to versions of it are in this answer.

different execution time or the same with different options? [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 6 years ago.
Improve this question
If i compile a C program with different options like '-o, -o2, -o3' Will there be any difference in the execution time or memory utilization?.
Maybe.
Depends. You're telling the compiler to spend a bit of additional time into looking for places where it could probably optimize the code from the standard approach. It might find such places, but it also might not. On all but the most trivial programs, there is, however, quite a high probability the compiler will be able to optimize ("Hello World" doesn't optimize very well, though...).

How is encoding faster than not encoding? [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 making a virtual machine in C and I was told that by converting the "assembly" code into hexadecimal or binary, I could speed up the execution. My question is, if I have a string and I encode it to numbers, how can it be faster than not encoding it when it adds and extra step to the execution in the VM?
--EDIT--
An example of the VM assembly is:
push 10 # Push the value 10 to the top of the stack
print # Print the value at the top of the stack
The encoded instructions look like this:
010a 0c
But the part I don't get is how encoding the assembly into instructions can be faster than not doing it because you have to decode them again. Please let me know if I'm wrong though.
Yes, encoding is better in the case on the re-use of the code.
Keep in mind that a function or piece of code is called many times, and so you loose little times for the first conversion and after you gain a lot of time when you start interpret the same code.

Fastest C conditions execution [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 9 years ago.
Improve this question
Today I stumbled upon one simple part of code and I would like to know more people opinion.
What would be the fastest code to evaluate this graph
There is no such thing as the fastest code to evaluate this graph. It depends on the processor architecture. What can be faster on one architecture, will be slower on another, or not even possible.
Nowadays, the compilers excel at block optimizations, and you should write the code as natural as you can and let the compiler decide what "the fastest" means. If the compiler doesn't have an optimization option, the best way to handle this type of conditions is to use 'conditional move' instructions, because they do not stall the pipeline, but this is very much specific to certain architectures.

A byte has 8-bits. Can it be larger in another system? give an example [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 8 years ago.
Improve this question
A byte has 8-bits. Can it be larger in another system? Give an example.
Also, how many different types of calls such as writeint,writedec,writestring,writechar are there in assembly language.
Thanks.
Not any more. There was a time, yes, when there were systems without a fundamental 8-bit byte.
System where 1 byte != 8 bit?
how many different types of call such as writeint,writedec,writestring,writechar are there in assembly language
This question makes no sense. Assembly language is just a means of writing code that translates directly to machine instructions. call is just one of these instructions - it jumps to some other section of code, with the intent of returning to the place where the call was made.
The things you're referring to sound more like library routines - in which case there are any number of them, depending on the programming environment.

Resources