Skip to content

Instantly share code, notes, and snippets.

from enum import Enum
from nmigen import *
from nmigen.asserts import *
from nmigen.sim import pysim
class Opcodes(Enum):
NOPO = 0x0
LD = 0x1
LDC = 0x2
AND = 0x3
@the6p4c
the6p4c / cursed.c
Created August 27, 2020 02:23
hey! don't do this!
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/io.h>
#include <sys/mman.h>
#include "elf.h"
import sys
def main():
input_file = sys.argv[1]
output_file = sys.argv[2]
with open(input_file, 'rb') as f_in, open(output_file, 'wb') as f_out:
decompressed_length = int.from_bytes(f_in.read(4), 'little')
bytes_written = 0
@the6p4c
the6p4c / top.v
Created October 1, 2019 13:08
a dodgy uart, without the r
`default_nettype none
module top(input CLK, output PIN_24);
wire tx_buf_empty;
reg tx_data_ready;
reg [7:0] tx_data;
uart_tx #(
.BAUD_DIVISOR(16000000 / 115200)
) uart_tx_inst (
@the6p4c
the6p4c / bug.c
Created September 27, 2019 11:28
// Build with gcc -o bug bug.c
//
// Prints non-NULL address of y when executed outside of valgrind, and a NULL
// (rendered as "(nil)" by printf) when executed inside valgrind.
#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/types.h>
/* !heavily! work in progress */
MEMORY {
ram (rwx) : org = 0x00000000, l = 64K
user (rx) : org = 0xFFF80000, l = 512K
}
SECTIONS {
.text : {
*(.text)
*(.text*)
from nmigen import *
from nmigen.cli import main
class Test:
def __init__(self):
self.out = Signal(8)
def get_fragment(self, platform):
data = list(range(10))
arr = Array(data)
LAI x (01XX)
load accumulator immediate
acc = x
LAM x (02XX)
load accumulator memory
acc = mem[x]
LAI x (0300)
load accumulator memory indirect
acc = mem[mem[0]]
SAM x (04XX)
def generate_stacks(n):
if n == 1:
yield (True,)
yield (False,)
else:
for stack in generate_stacks(n - 1):
yield stack + (True,)
yield stack + (False,)
def stack_flip(stack, n):
class Sandpile:
def __init__(self, size, data=None):
self.size = size
if data:
assert(isinstance(data, list))
assert(len(data) == size)
for row in data:
assert(isinstance(row, list))