low-level

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 accurate from my limited testing, however it is running incredibly fast, and I want to throttle it down to the actual clock speed of the machin...

Optimize y = x*x in Galois field arithmetic

I have this C-code to do multiplications over GF(8): int32_t GaloisMultiply (int32_t a, int32_t b) { int32_t i; int32_t mask = 0x100; int32_t y = 0; for(i=0;i<8;i++) { if(b & mask) { y ^= a; } mask >>= 1; y <<= 1; } if(b & 0x1) { y ^= a; } return(y); } That's more or less the text-boo...

GCC Fixed Size Integers

On the MSVC++ compiler, one can use the __int8, __int16, __int32 and similar types for integers with specific sizes. This is extremely useful for applications which need to work with low-level data structures like custom file formats, hardware control data structures and the like. Is there a similar equivalent I can use on the GCC compi...

How do you set strings to uppercase / lowercase in Unicode?

This is mostly a theoretical question I'm just very curious about. (I'm not trying to do this by coding it myself or anything, I'm not reinventing wheels.) My question is how the uppercase/lowercase table of equivalence works for Unicode. For example, if I had to do this in ASCII, I'd take a character, and if it falls withing the [a-z]...

Low level keyboard input on 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? ...

How to find out if a pointer is on the stack on PC/Visual C++

[This is for PC/Visual C++ specifically (although any other answers would be quite illuminating :))] How can you tell if a pointer comes from an object in the stack? For example: int g_n = 0; void F() { int *pA = &s_n; ASSERT_IS_POINTER_ON_STACK(pA); int i = 0; int *pB = &i; ASSERT_IS_POINTER_ON_STACK(pB); } so o...

What is the best way to add two numbers without using the + operator?

A friend and I are going back and forth with brain-teasers and I have no idea how to solve this one. My assumption is that it's possible with some bitwise operators, but not sure. ...

Bitwise subtraction in Python

This is a follow-up to my question yesterday: CMS kindly provided this example of using bitwise operators to add two numbers in C: #include<stdio.h> int add(int x, int y) { int a, b; do { a = x & y; b = x ^ y; x = a << 1; y = b; } while (a); return b; } int main( void ){ printf( "6 ...

How are Operating Systems "Made"?

Creating an OS seems like a massive project. How would anyone even get started? For example, when I pop Ubuntu into my drive, how can my computer just run it? (This, I guess, is what I'd really like to know.) Or, looking at it from another angle, what is the least amount of bytes that could be on a disk and still be "run" as an OS? ...

Is knowing some basic low-level stuff essential to all programmers?

Should all decent programmers be expected to know at least something about low-level stuff such as the following: The gist of how garbage collection is implemented, how memory management works without GC, and exactly what the difference is between the heap, the stack and the static data segment? At least be able to read assembly langua...

Safer Alternatives to the C Standard Library

The C standard library is notoriously poor when it comes to I/O safety. Many functions have buffer overflows (gets, scanf), or can clobber memory if not given proper arguments (scanf), and so on. Every once and awhile, I come across an enterprising hacker who has written his own library that lacks these flaws. What are the best of the...

How long does a context switch take in Linux?

I'm curious how many cycles it takes to change contexts in Linux. I'm specifically using an E5405 Xeon (x64), but I'd love to see how it compares to other platforms as well. ...

How are variables on the stack accessed?

Suppose we have these local variables: int a = 0; int b = 1; int c = 2; int d = 3; As far as I know, these will be allocated on the system stack, like this: | | | 3 | d | 2 | c | 1 | b |_0_| a Does this mean that in order to get the value of a, the values of d, c and b must first be popped out of the stack? If so, where do these ...

Problems with running an application under controlled environment (Win32).

I'm not exactly sure how to tag this question or how to write the title... so if anyone has a better idea, please edit it! Here's the deal: Some time ago I had written a little but cruicial part of a computing olympiad management system. The system's job is to get submissions from participants (code files), compile them, run them again...

Readings, tools and libraries for low-level, network related, softwares in C

I'm going to graduate soon in electronics and tlc engineering and I have some decent OO programming experience with PHP and Java. Now I would like to try starting a career as a C programmer. I'm interested in C since this is, I think, the most suited language, without considering Assembly, to develop device drivers, firmwares and other l...

Compiler-Programming: What are the most fundamental ingredients?

I am interested in writing a very minimalistic compiler. I want to write a small piece of software (in C/C++) that fulfills the following criteria: output in ELF format (*nix) input is a single textfile C-like grammar and syntax no linker no preprocessor very small (max. 1-2 KLOC) Language features: native data types: char, int an...

How do the visually impared handle boot failures and other low-level environments

I know that screen readers and similar software exists to help the blind and visually impaired to use computers when in Windows or other operating systems. I am curious as to what support is available in lower level environments such as OS installers and BIOS setup etc. ...

What is the purpose of the frame pointer?

I'm a beginner in assembly language and have noticed that the x86 code emitted by compilers usually keeps the frame pointer around even in release/optimized mode, when it could use the EBP register for something else. I undertand why the frame pointer might make code easier to debug, and might be necessary if alloca() is called within a...

Can increment of a register be used to determine the clock rate?

Can increment of a register (in a loop) be used to determine the (effective) clock rate? I've naturally assumed it can, but I was commented that Cpu's may implant Super-scalar techniques that make this kind of computation useless. Also I was told that incrementing of registers on CPU can be done in less than one clock cycle. is it true...

What fast low-level languages can you recommend?

I have became interested in C-like languages for performance computing. Can you recommend some alternative programming languages which have the following attributes: must be close to the hardware (bit fiddling, pointers or some alternative safe method like references) no managed code (no jvm/.net languages) has to be really fast (like ...