Skip to content

Instantly share code, notes, and snippets.

View ShinyaKato's full-sized avatar
🏠
Working from home

ShinyaKato ShinyaKato

🏠
Working from home
  • Medley inc.
  • Japan/Tokyo
  • X @0x19f
View GitHub Profile
@ShinyaKato
ShinyaKato / main.c
Created May 28, 2020 17:06
traverse binary tree without extra non-constant space such as dfs and stack.
#include <stdio.h>
typedef struct Node Node;
struct Node {
int value;
Node *left;
Node *right;
};
@ShinyaKato
ShinyaKato / main.rs
Created May 21, 2020 11:16
Rust template just taking input from stdin for competitive programming.
use std::io::{self, Read};
macro_rules! input {
($it: expr) => ($it.next().unwrap().parse().unwrap());
($it: expr, $T: ty) => ($it.next().unwrap().parse::<$T>().unwrap());
}
fn main() {
let mut buf = String::new();
io::stdin().read_to_string(&mut buf).unwrap();
@ShinyaKato
ShinyaKato / fizzbuzz.s
Last active May 6, 2020 00:10
x86-64 Assembly FizzBuzz on Linux
// build and execute
// $ gcc -o fizzbuzz fizzbuzz.s
// $ ./fizzbuzz
.section .rodata
.Sfizzbuzz:
.string "FizzBuzz\n"
.Sfizz:
.string "Fizz\n"
.Sbuzz:
@ShinyaKato
ShinyaKato / gen_hello.c
Created May 5, 2019 17:09
ELF (executable) generation example
// $ gcc gen_hello.c -o gen_hello
// $ ./gen_hello
// $ ./hello
#include <stdio.h>
#include <stdlib.h>
#include <elf.h>
#define SEGMENTS 1
#define SEG_EXEC 0
@ShinyaKato
ShinyaKato / gen_obj.c
Last active March 5, 2019 17:09
ELF (object file) generation
#include <stdio.h>
#include <stdlib.h>
#include <elf.h>
int main(int argc, char *argv[]) {
if (argc != 3) {
fprintf(stderr, "usage: ./gen_obj [integer] [output file]\n");
exit(1);
}
int n = atoi(argv[1]);
# generated by https://tool-taro.com/image_to_ascii/
AA = <<-EOS
@ShinyaKato
ShinyaKato / asm.md
Last active December 1, 2018 15:02
Assembler Note

instructions

  • [DONE] popq
  • [DONE] pushq
  • [DONE] movq
  • [DONE] movl
  • [DONE] movw
  • [DONE] movb
  • [DONE] movzbl
  • [DONE] movsbl