Skip to content

Instantly share code, notes, and snippets.

View VardanGrigoryan's full-sized avatar

Vardan VardanGrigoryan

View GitHub Profile
[BITS 16] ; We need 16-bit intructions for Real mode
[ORG 0x7C00] ; The BIOS loads the boot sector into memory location 0x7C00
;jmp word load
global _start
jmp _start
drive db 0
; jmp reset_drive
; jmp enter_pm
rm -rf *.o *.bin *.img
nasm -f bin bootsect.asm -o bootsect.bin
gcc -ffreestanding -c main.c -o main.o
gcc -c video.c -o video.o
gcc -c ports.c -o ports.o
ld -e main -Ttext 0x1000 -o kernel.o main.o video.o ports.o
ld -i -e main -Ttext 0x1000 -o kernel.o main.o video.o ports.o
objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin
./makeboot a.img bootsect.bin kernel.bin
#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
int main()
{
int size;
std::cin >> size;
/*
* A fast exponentiation.
* The algo has O(log(m)) time complexity, additionally it gets a boost because of compile time.
*/
template <int n, int mod, int debug_info, int m>
struct fast_exp {
static constexpr int value = (m % 2 == 0) ? fast_exp<(n * n) % mod, mod, debug_info, m / 2>::value : (n * fast_exp<(n * n) % mod, mod, debug_info, (m - 1) / 2>::value) % mod;
static constexpr void run_debug() {
static_assert(value == debug_info, "failed");