Skip to content

Instantly share code, notes, and snippets.

View ratasorin's full-sized avatar

Rata Sorin ratasorin

View GitHub Profile
class Mutex:
fun lock():
pass
fun unlock():
pass
class ConditionVariable:
fun wait(mutex):
# lock the variable
fun notify_all(mutex):
@ratasorin
ratasorin / 7seg.asm
Last active December 17, 2025 11:28
7 SEG SHOW
.DATA
ADDR_7SEG EQU 02H ; 2 Decimal
; 7-Segment Encoding Table (Common Cathode)
; Maps index 0-F to segment patterns (gfedcba)
HEX_TABLE
DB
3FH, ; 0
06H, ; 1
5BH, ; 2
@ratasorin
ratasorin / led.asm
Created December 17, 2025 11:20
LED ON/OFF
.DATA
ADDR_LEDS EQU 12H ; 18 Decimal (Address of the 74x373 Latch)
; Shadow variable to store current state of LEDs (initially all OFF)
LED_SHADOW DB 0FFH
; Bit Definitions for LEDs (0 to 7 - one hot encoded)
LED0_MASK EQU 01H ; 0000 0001B
LED1_MASK EQU 02H ; 0000 0010B
LED2_MASK EQU 04H ; 0000 0100B
@ratasorin
ratasorin / keyboard_scan.asm
Created December 17, 2025 11:11
Keyboard scan
.DATA
ADDR_KBD_IN EQU 16H ; 22 Decimal
ADDR_KBD_OUT EQU 18H ; 24 Decimal
; Column Selection Masks (Active Low)
COL_1_MASK EQU 11111110B ; Select Column 1
COL_2_MASK EQU 11111101B ; Select Column 2
COL_3_MASK EQU 11111011B ; Select Column 3
; Row Input Masks have a 1 hot encoding because TEST does bitwise AND comparing the result with "0"
@ratasorin
ratasorin / 8255_send_char.asm
Created December 17, 2025 11:07
8255 send char
.DATA
; Port Addresses
ADDR_8255_A EQU 0250H
ADDR_8255_C EQU 0254H
ADDR_8255_CTRL EQU 0256H
; Strobe: 1 (Idle) -> 0 (Trigger) -> 1 (Idle)
STROBE_IDLE EQU 01H ; Bit 0 is 1
STROBE_ACTIVE EQU 00H ; Bit 0 is 0
@ratasorin
ratasorin / 8251_txd_rxd.asm
Created December 17, 2025 09:34
Read and Transmit character with 8251
.DATA
ADDR_8251_CTRL EQU 04D0H
ADDR_8251_DATA EQU 04D2H
; Status Masks
MASK_TXRDY EQU 00000001B ; Bit 0 is TxRDY (Transmitter Ready)
MASK_RXRDY EQU 00000010B ; Bit 1 is RxRDY (Receiver Ready)
.CODE
@ratasorin
ratasorin / 8251_8255_config.asm
Created December 17, 2025 09:25
Configure operating modes for 8251 and 8255
.DATA
ADDR_8255_CTRL EQU 0256H ; Control Register Address
; Control Word for 8255:
; Bit 7=1 (Mode Set Flag)
; Bit 6-5=00 (Group A Mode 0 - Basic I/O)
; Bit 4=0 (Port A = Output)
; Bit 3=0 (Port C Upper = Output)
; Bit 2=0 (Group B Mode 0)
; Bit 1=1 (Port B = Input - Common default)
@ratasorin
ratasorin / remove-last-vowel.cpp
Last active December 14, 2022 07:55
Classroom assignment, remove last vowel from sentence
#include <iostream>
#include <cstring>
using namespace std;
char vowels[] = {'a', 'e', 'i', 'o', 'u'};
char *last_vowel(char* sentence) {
char* last_vowel_found;