Skip to content

Instantly share code, notes, and snippets.

View TJesionowski's full-sized avatar

Timothy Jesionowski TJesionowski

View GitHub Profile
; Solution to exercise at end of https://youtu.be/APiHPkPmwwU
; to execute $ nasm boot.asm -f bin -o boot.bin && qemu-system-x86_64 -drive file=boot.bin,format=raw
mov ah, 0x0e
mov al, 97
mov dl, 97
int 0x10
loop:
inc dl
mov al, dl
; cleaner, more efficient implementation of final program shown in https://youtu.be/APiHPkPmwwU
; to execute $ nasm boot.asm -f bin -o boot.bin && qemu-system-x86_64 -drive file=boot.bin,format=raw
mov ah, 0x0e
mov al, 65
int 0x10
loop:
inc al
cmp al, 'Z'
int 0x10
@TJesionowski
TJesionowski / no-if.c
Created February 16, 2019 17:26
An example of parametric gotos, an incredibly weird feature of gcc that lets you do things like intra-function jump tables.
#include <stdio.h>
int main() {
printf("Enter 0 to print hello and 1 to print goodbye: ");
unsigned long mask = 0;
scanf("%ld", &mask);
// ensure mask is 0 or 1
mask = !(!(mask));
@TJesionowski
TJesionowski / called_hello.asm
Last active February 16, 2019 17:11
A simple example of linking assembly programs to C programs.
section .data
msg db "Hello, World.asm","\0x0a" ;
section .text
global hello
hello:
mov rax, 1
mov rdi, 1
mov rsi, msg
@TJesionowski
TJesionowski / inline_asm.c
Created December 14, 2018 00:06
a quick demonstration of C inline assembly
// re-writing strlen, while certainly doable, isn't the point
#include <string.h>
void print(char* message);
void readLine(int maxBytes, char *dest);
int main(void) {
char message[] = "Hello world!\n";
print(message);
@TJesionowski
TJesionowski / pthread_rng.c
Created December 13, 2018 23:56
A quick and dirty rng with pthreads
// implements a race-based rng using posix threads
#include <pthread.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
// https://randu.org/tutorials/threads/