101

A mask (of the facial variety) is something that covers up some parts of your face and lets other parts show through. The terminology is used by analogy in computing: a bitmask covers up (filters out) some bits in a bitset and allows others to pass. Are there any other type of "masks" besides bit masks in the IT domain? Just off the top of my head, ...


67

There are several practical reasons why functions like fopen return pointers to instead of instances of struct types: You want to hide the representation of the struct type from the user; You're allocating an object dynamically; You're referring to a single instance of an object via multiple references; In the case of types like FILE *, it's because you ...


56

A bit mask is used to mask some bits of a bit field while exposing others: initial value: 011011001 bit mask.....: 111110000 result value.: 011010000 This has been used before computing in electronics with logical gates (AND, OR...) or transistors or in electromechanics with relays.


44

Executables do depend on both the OS and the CPU: Instruction Set: The binary instructions in the executable are decoded by the CPU according to some instruction set. Most consumer CPUs support the x86 (“32bit”) and/or AMD64 (“64bit”) instruction sets. A program can be compiled for either of these instruction sets, but not both. There are extensions to ...


40

It turns out you only need one instruction to build a machine capable of Turing-computation. This class of machines that have only one instruction and are Turing-complete is called One Instruction Set Computers or also somewhat jokingly Ultimate RISC.


40

Bitmasks are terribly old. I haven't been able to find a reference to the first one, but they were certainly popular by the advent of 8-bit processors, and likely were also used in 4-bit processors. The idea behind bitmasks is to take advantage of bitwise parallelism. A 8 bit computer can do the same bitwise operation to 8 bits at once if they're packed ...


40

There are two ways of "returning a structure." You can return a copy of the data, or you can return a reference (pointer) to it. It's generally preferred to return (and pass around in general) a pointer, for a couple of reasons. First, copying a structure takes a lot more CPU time than copying a pointer. If this is something your code does frequently, it ...


33

In its most general usage in English, a mask is a device that hides something. Screen printing is mentioned in another answer. Painting tape 'masks off' something to avoid getting paint on it, etc. The Solder Mask on a PC board 'masks off' the area to be soldered from the area not to be soldered. In the case of "bit masking", some bits are 'hidden' or ...


33

Programming concretely is the impulse to pull details towards you so you can nail them all down in one place. We all start this way and it's hard to let go. Programming abstractly is most definitely "forgetting about the lower-level details". Sometimes even high level details. You push details away and let something else deal with them. The sneaky ...


32

If I understand correctly, the development process was peer review and experimentation. The team consisted of people like "Math Doctors" - extremely dedicated, intelligent, passionate, detail-oriented folks whose lives were dedicated to their work. So when I say peer review, I mean many peer reviews over the course of many months (more than a year). These ...


27

"Besides the fact that a higher level language is easier to code in and therefore less error prone" I really think this is a good enough reason all by itself. If you have no compelling reason to work in a low level of abstraction (such as performance, knowledge in the team, etc), then there is no reason to do it. If all you want is a coffee, then you want ...


18

what makes it difficult for say the visual C++ compiler on windows to generate a linux binary executable file? Other than an unwillingness to do that on Microsoft's part, absolutely nothing. The obstacles aren't technical. Development toolchains are just programs that take input and produce output. Visual C++ produces x86 assembly and then uses an ...


16

The AGC is controlled with verbs and nouns The Apollo command software is not written in any syntax users would recognize today. Astronauts input commands numerically, with each two-digit number representing a verb or a noun. The verb described the action to be performed, and the noun specified the data to be affected by the verb’s action. Astronauts hated ...


14

It's completely context dependent. Compared to PHP, C is low level; Compared to x86 assembly, C is high level; Compared to the instructions I used to construct this universe in which you reside, C is so high level you can barely see it. It depends who you're talking to, and about what, as to what the answer is. C is a bit of a unique beast, though, because ...


14

There was a lovely documentary I'm trying to chase down about John 'Jack' Garman had to "invent" a "a priority-scheduled multiprogramming operating system". This may have been related to the lander module though. The story was that when you were landing the lander, you better give priority to guidance because other things, like the temperature in the cabin ...


13

I know C is a good language to learn the principles behind programming. I disagree. C is absent too many features to learn principles behind programming. C's features for creating abstractions are terrible, and abstraction is one of the key principles behind programming. If you want to learn how hardware works, and hence some mechanical sympathy for the ...


13

In addition to other answers, sometimes returning a small struct by value is worthwhile. For example, one could return a pair of one data, and some error (or success) code related to it. To take an example, fopen returns just one data (the opened FILE*) and in case of error, gives the error code thru the errno pseudo-global variable. But it would be perhaps ...


13

This kind of microoptimization is usually avoided because it hurts code readability – and microoptimizations is the job of the compiler. But sometimes these techniques can be legitimately useful. Often, instead of branching we can make use of how bit patterns interact. E.g. instead of testing if a boolean is set with a conditional, we could perhaps multiply ...


13

At the bottom, there are some updates to how this fared for me every quarter of the year or so, I think they're valuable. Good naming. Or, if it's someone else's code, trying to attribute good names / responsibilities based on even bad names on that system's classes / functions so it makes sense in my head. Once it does, the low-level implementations become ...


11

The only danger you will run into is little vs. big endianess (whether the most or least significant byte is written first). However if you remain in the same environment there will be no issue. besides the general ensuring of writing/parsing roundtrip. The file system is designed to handle any sequence of bytes.


11

Register machine bytecode often comes in three-address form, that is, it talks about data flow relationships between registers, and operations take explicit destination registers. So a basic instruction set may look like this: set register, constant mul out, in1, in2 add out, in1, in2 You could assume you have an infinite number of registers r0, r1, etc. ...


11

volatile means some other processor or I/O device or something can change the variable out from under you. With an ordinary variable, your program's steps are the only thing that will change it. So for instance if you read 5 from a variable and you don't change it, it'll still contain 5. Since you can rely on that, your program doesn't have to take the time ...


11

volatile means two things: The value of the variable may change without any code of yours changing it. Therefore whenever the compiler reads the value of the variable, it may not assume that it is the same as the last time it was read, or that it is the same as the last value stored, but it must be read again. The act of storing a value to a volatile ...


10

On your motherboard, you have a CPU and a bunch of wires (called a bus) that go to your RAM, which comes separately on sticks that are relatively easy to replace. You can think of the memory address as controlling 32 of those wires. 0x52A132F3 translates to 01010010101000010011001011110011 in binary. Each 1 means the CPU puts a voltage (1.5 volts for DDR3)...


10

A bit mask is similar to screen printing. You select some certain bit position to be taken over into the result: source value = 42 -> 00101010b mask = 51 -> 00110011b result 42&51 = 00100010b -> 34 Another meaning of mask is a page in a graphical user interface where the user can input data.


9

In addition to all of the gotchas already mentioned, if you are making up a new binary file format rather than reading and writing data in an existing format, it is absolutely vital that you include a file header: a block of data at the very beginning of the file that unambiguously identifies the file format and records any metadata that may be required. ...


9

Fortunately, there are a variety of well-known real register machines that you can look at. For example, x86 code for the above might be: mov eax, 2 mul eax, 5 add eax, 1 (In x86 Intel notation, the destination is the left operand.)


Only top voted, non community-wiki answers of a minimum length are eligible