Handmade Hero
A limbless child receives a magical gift that allows him to set off on the adventure he always dreamed of.
Intro to C
In this intro Casey explains what is C, how to compile and run C program, and how to use Visual Studio debugger.
Can you explain in simple words what is to declare memory?
Declare memory is sort of asking space for some data. Something like when you
initialize array with some size, it’s automatically allocating memory for that.
What is Assembly commands?
Assembly commands is sort of mnemonics of actual processor commands.
What fundamentally computer CPU is?
Fundamentally, a computer CPU is a group of electronic circuits that can perform
a certain set of mathematical functions. These circuits fetch an instruction
value from and (depending on the value), activate another set of circuits to
perform a specific function. Each instruction is a number that tells the CPU
which circuits to activate.
Mnemonics are words that represent machine code in a more human-readable way, so that programmers can more easily write and understand programs.
al
in mov
command means?
%al
refers to the low byte of the %ax
register.
Can you explain what this code do byte ptr[Test], 0FFh
Instruction byte ptr[Test], 0FFh
is telling the assembler to allocate one byte
of memory at the address represented by the label Test. And this is variable
declaration (TODO: test it).
What assembler mnemonic here will be used?
Move constant to some place of memory.
What 2 computer parts really matter in programming. One used to manipulate data,
second used to process data.
CPU and Memory.
What are we actually programming, when we write some code?
CPU itself is a
thing, which we’re actually programming.
What is deterministic algorithm, in simple words?
In computer science, a deterministic algorithm is an algorithm that, given a
particular input, will always produce the same output, with the underlying
machine always passing through the same sequence of states. Deterministic
algorithms are by far the most studied and familiar kind of algorithm, as well
as one of the most practical, since they can be run on real machines
efficiently. Formally, a deterministic algorithm computes a mathematical
function; a function has a unique value for any input in its domain, and the
algorithm is a process that produces this particular value as output.
In computing, an operand is?
It’s the part of a computer instruction which specifies what data is to be
manipulated or operated on, while at the same time representing the data itself.
A computer instruction describes an operation such as add or multiply X, while
the operand (or operands, as there can be more than one) specify on which X to
operate as well as the value of X. Additionally, in assembly language, an
operand is a value (an argument) on which the instruction, named by
mnemonic, operates. The operand may be a processor register, a memory address, a
literal constant, or a label. A simple example (in the x86 architecture) is MOV DS, AX
where the value in register operand AX
is to be moved (MOV
) into
register DS
. Depending on the instruction, there may be zero, one, two, or
more operands.
Difference between little endian and big endian.
Endianness is the order of sequence of bytes in computer memory.
little-endian
(LE) the least significant part of the number is stored first.big-endian
(BE) is more like natural order of bytes sequence, most significant part of the number is stored first. Now days LE order is dominating in various architectures.
Is compiler always tries to compact data structures?
No, it can be wider than needed, reason optimizations.
Compiler tries to reduce memory calls, etc.
But you can use #pragma
to customize packing optimizations.
What is Data structure alignment?
Data structure alignment is the way data is arranged and accessed in computer
memory. It consists of three separate but related issues: data alignment, data
structure padding, and packing. The CPU in modern computer hardware performs
reads and writes to memory most efficiently when the data is naturally
aligned, which generally means that the data’s memory address is a multiple of
the data size. For instance, in a 32-bit architecture, the data may be aligned
if the data is stored in four consecutive bytes and the first byte lies on a
4-byte boundary.
Data alignment is the aligning of elements according to their natural alignment.
To ensure natural alignment, it may be necessary to insert some padding between structure elements or after the last element of a structure.
Implicit Type Conversion example -
==printf("%c", x);==, use implicit conversion in printf function.
Explicit Type Conversion (casting) - ==(data_type)expression;==
What is Page (computer memory)?
A page, memory page, or virtual page is a fixed-length contiguous
block of virtual memory, described by a single entry in the page table. It is
the smallest unit of data for memory management in a virtual memory operating
system. Similarly, a page frame is the smallest fixed-length contiguous
block of physical memory into which memory pages are mapped by the operating
system. A transfer of pages between main memory and an auxiliary store, such as
a hard disk drive, is referred to as paging or swapping.
What is Page fault?
In computing, a page fault (sometimes called PF or hard fault) is an
exception that the memory management unit (MMU) raises when a process accesses a
memory page without proper preparations. Accessing the page requires a mapping
to be added to the process’s virtual address space.
A CPU cache is
Hardware cache used by the central processing unit (CPU) of a computer to reduce
the average cost (time or energy) to access data from the main memory.
Many modern desktops, server, and industrial CPUs have at least three
independent caches:
- Instruction cache, used to speed up executable instruction fetch
- Data cache, used to speed up data fetch and store; the data cache is usually organized as a hierarchy of more cache levels (L1, L2, etc.; see also multi-level caches below).
- Translation lookaside buffer (TLB), used to speed up virtual-to-physical address translation for both executable instructions and data. A single TLB can be provided for access to both instructions and data, or a separate Instruction TLB (ITLB) and data TLB (DTLB) can be provided. However, the TLB cache is part of the memory management unit (MMU) and not directly related to the CPU caches.
Main difference between while-loop and do-while-loop?
Do-while loop execute at least once, because condition is checked after we
execute loop body.
How write do-while-loop using only while loop?
What’s wrong with this code (specific case logic)?
Switch just jump to code, and continue execution blocks This logic usually is
not expected. And you need place break; statements in each case!
What are {}
blocks in C?
This blocks (block
or compound statement
) basically are base logical part of
program, which used to group code.
This block usually used in control statements and loops.
Variables declared in block are local and not available out of block.
In computer programming, a block
or code block
or block of code
is a
lexical structure of source code which is grouped together. Blocks consist of
one or more declarations and statements. A programming language that permits the
creation of blocks, including blocks nested within other blocks, is called a
block-structured programming language. Blocks are fundamental to structured
programming, where control structures are formed from blocks.
What dereference operator (indirection operator) *
do?
It’s used to get value of variable at the pointer address. It can be used to
output value of referencing or even set its value.
Additional Resources
Day 001: Setting Up the Windows Build
In my case it’s to setup the Linux build.
Compiler - partially compile source code into executable (exe
file usually)
Linker - gather all that executable code (from compiler) into executable
subst
- command to create virtual disk from some directory
Additional Resources
Day 001qa: Setting Up the Windows Build - Q&A
Day 002: Opening a Win32 Window
Usually items in struct is sequentially stored With alignment.
In C to use struct need define it first, but you can use typedef
to define it
and use it at the same time.
A lot of questions. There deep WINAPI integration, I propably need to rewatch this intro, too many unknown stuff. And I also check MSDN docs and of course QA session (first).
We use ansi winapi functions.
for(;;)
used instead of while(1)
to remove some warnings, looks like it’s
more conventional way to create infinity loop.
- sticky heading plugin → need move into win
- watch debugger video, maybe automatic debugger attach on compile?
- need to understand masking in C better (&/etc), here was good video in Russian