112 questions
82
votes
8
answers
55k
views
Why bit endianness is an issue in bitfields?
Any portable code that uses bitfields seems to distinguish between little- and big-endian platforms. See the declaration of struct iphdr in linux kernel for an example of such code. I fail to ...
128
votes
7
answers
48k
views
How exactly does the callstack work?
I'm trying to get a deeper understanding of how the low level operations of programming languages work and especially how they interact with the OS/CPU. I've probably read every answer in every stack/...
24
votes
4
answers
3k
views
What is an "internal address" in Java?
In the Javadoc for Object.hashCode() it states
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically ...
42
votes
8
answers
82k
views
How are 3D arrays stored in C?
I understand that arrays in C are allocated in row-major order. Therefore, for a 2 x 3 array:
0 1
2 3
4 5
Is stored in memory as
0 1 2 3 4 5
However, what if I have a 2 x 3 x 2 array:
0 1
2 3
...
10
votes
2
answers
2k
views
Why memory reordering is not a problem on single core/processor machines?
Consider the following example taken from Wikipedia, slightly adapted, where the steps of the program correspond to individual processor instructions:
x = 0;
f = 0;
Thread #1:
while (f == 0);
...
27
votes
7
answers
16k
views
CPU Emulation and locking to a specific clock speed
If you had read my other question, you'll know I've spent this weekend putting together a 6502 CPU emulator as a programming exercise.
The CPU emulator is mostly complete, and seems to be fairly ...
3
votes
1
answer
425
views
int_fast8_t size vs int_fast16_t size on x86-64 platform
I already learned that on the x86-64 platform using any 64-bit register would need a REX prefix, and any address less than 64 bits would require an address-size prefix.
On x86-64 bit:
E3 rel8 is jrcxz
...
45
votes
3
answers
13k
views
Why doesn't Linux use the hardware context switch via the TSS?
I read the following statement:
The x86 architecture includes a
specific segment type called the Task
State Segment (TSS), to store hardware
contexts. Although Linux doesn't use
hardware ...
6
votes
1
answer
2k
views
Each program allocates a fixed stack size? Who defines the amount of stack memory for each application running?
When we run a code, the compiler after compile "detects" the necessary amount of Stack memory? And with this, each program has its own "block" of stack memory.
Or the stack memory ...
71
votes
5
answers
42k
views
To learn assembly - should I start with 32 bit or 64 bit?
I'm really wanting to learn assembly. I'm pretty good at c/c++, but want a better understanding of what's going on at a lower level.
I realize that assembly related questions have been asked before, ...
10
votes
6
answers
6k
views
x86 equivalent for LWARX and STWCX
I'm looking for an equivalent of LWARX and STWCX (as found on the PowerPC processors) or a way to implement similar functionality on the x86 platform. Also, where would be the best place to find out ...
5
votes
9
answers
30k
views
What is INT 21h?
Inspired by this question
How can I force GDB to disassemble?
I wondered about the INT 21h as a concept. Now, I have some very rusty knowledge of the internals, but not so many details. I remember ...
-1
votes
1
answer
1k
views
Custom heap/memory allocation ranges
I am writing a 64-bit application in C (with GCC) and NASM under Linux.
Is there a way to specify, where I want my heap and stack to be located. Specifically, I want all my malloc'ed data to be ...
40
votes
4
answers
31k
views
How does the computer calculate Square roots? [closed]
How does the computer calculate Square roots ?
I mean what is going on there! How does it process it!!
Does it use some mathematical ways like Newton's method?
What about Trigonometric Functions? And ...
22
votes
12
answers
21k
views
Would you use num%2 or num&1 to check if a number is even? [closed]
Well, there are at least two low-level ways of determining whether a given number is even or not:
1. if (num%2 == 0) { /* even */ }
2. if ((num&1) == 0) { /* even */ }
I consider the second ...
13
votes
4
answers
14k
views
How does a compiler compile a compiler?
Coming from a high-level programming background, I am interested in learning about low-level programming. I want to know how a compiler is compiled?
After looking at some articles in wiki, Numerical ...
10
votes
5
answers
12k
views
What has a better performance: multiplication or division?
Which version is faster:
x * 0.5
or
x / 2 ?
I've had a course at the university called computer systems some time ago. From back then I remember that multiplying two values can be achieved with ...
5
votes
2
answers
8k
views
How are GUI's really made?
My question is
Gui libraries like Qt and lets say for Windows operating systems
how do they create all those graphical user interfaces(windows etc).
Does each operating system gives API's or ...
0
votes
1
answer
1k
views
8086 assembly register indirect MOV instruction
I just wanted to ask: why is it that when I write :
MOV DL, [BX]
it works, but when I write:
MOV DL, [AX]
it doesn't?
8
votes
2
answers
9k
views
Can I change a user's keyboard input?
I found this keyboard hook code, which I'm trying to slightly modify for my purposes: http://blogs.msdn.com/toub/archive/2006/05/03/589423.aspx
As an overview, I want to have the user press a key, ...
6
votes
5
answers
9k
views
Low level keyboard input from Windows
What win32 calls can be used to detect key press events globally (not just for 1 window, I'd like to get a message EVERY time a key is pressed), from a windows service?
5
votes
8
answers
888
views
Why do Java and C# have bitshifts operators?
Is the difference between integer multiply(temporarily forgetting about division) still in favor of shifting and if so how big is the difference?
It simply seems such a low level optimization, even ...
3
votes
1
answer
5k
views
Using a low-level keyboard hook to change keyboard characters
I'm creating a custom keyboard layout. As the beginning step, I want to have the user press a key, have my keyboard hook intercept it, and output a different key of my choosing.
I found this ...
2
votes
6
answers
1k
views
How do computers differentiate 2 pieces of data? [closed]
I was wondering that computers store all the info in the form of 1s and 0s/low and high voltage, yada yada...but then when we compile the program, it - or just any data stored on the comp - is in ...
2
votes
1
answer
7k
views
STM32 FDCAN Communication: How do you set up FDCAN using low level programming on STM32U5?
I'm curently trying to initialise and configure FDCAN on the STM32U575 microcontroller to communicate with a microchip CAN Bus Analyzer. All coding is done with Keil uVision studio in low level ...