Memory

Memory is the main device. It is used by the kernel to store program and data. You can imagine memory as the simple array of bytes.

Memory structure

This array can be accessed by an address (index, byte number). There are two regions in the memory that can be accessed: the main memory block and the register block. If you try to access memory using invalid address, kernel will crash.

Main memory

During boot, the program's code is loaded into memory starting from address 0. Main memory block addresses begin with 0 and spreads until address of memory_size-1. Size of this block, also simply called "memory size" can be configured in NoSense configuration file.

Memory is zeroed during machine initialization, but you shouldn't depend on this feature and you should always initialize your memory before using it, because your program could be ran from a loader, not directly by the kernel during machine boot.

Registers

Registers are the memory cells that have fixed addresses and special meaning. Their block begins with address 7FFFFC00h. Every cell in every data size have its own name. Universal registers are:

                AR                              BR                8B = 64b
          __,--'  '--,__                  __,--'  '--,__
        AX              AY              BX              BY        4B = 32b
      /    \          /    \          /    \          /    \
    AA      AB      AC      AD      BA      BB      BC      BD    2B = 16b
   /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \
  A1  A2  A3  A4  A5  A6  A7  A8  B1  B2  B3  B4  B5  B6  B7  B8  1B = 8b


                CR                              DR                8B = 64b
          __,--'  '--,__                  __,--'  '--,__
        CX              CY              DX              DY        4B = 32b
      /    \          /    \          /    \          /    \
    CA      CB      CC      CD      DA      DB      DC      DD    2B = 16b
   /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \
  C1  C2  C3  C4  C5  C6  C7  C8  D1  D2  D3  D4  D5  D6  D7  D8  1B = 8b

There are also three special 4-byte registers:

SR (Stack Register)
Contains address of the top of the stack, if it is used. You must initialize this register manually. It is used by stack instructions (see the page about the stack).
IR (Instruction Register)
Contains address of the currently executed command. It is managed by the kernel and used by execution instructions.
OR (Offset Register)
Contains number that is always added to addresses (see below).

Addressing

All addresses are incremented by the offset from OR. It allows to write operating system that can load into memory and execute many programs at the same time. Initially, program is loaded by the kernel at the beginning of the memory and OR is set to 0. But if you want to load a program into different part of the memory and set the offset register to the address of its begin, it will work too.

There are several things that are not shifted by the offset (there are always absolute):