Skip to content

Instantly share code, notes, and snippets.

@jstaursky
jstaursky / compiling_asm.md
Created December 14, 2020 17:08 — forked from yellowbyte/compiling_asm.md
how to assemble assembly with NASM assembler to 32-bit or 64-bit ELF binary with or without libc

32-bit ELF binary

how to assemble and link:

nasm -f elf32 -o <filename>.o <filename>.asm
ld -m elf_i386 -o <filename> <filename>.o

template code (hello world):

section .text
global _start
@jstaursky
jstaursky / GAS-asm-to-raw-binary.org
Last active December 14, 2020 18:18
GAS to hex, RAW binary instruction, instruction to binary, GASM

How to compile AT&T assembly syntax to binary (not as an ELF file) using GNU GAS assembler as

;; File example.s (MUST end in '.s' otherwise GAS assembler 'as' won't recognize)

.code32  ;; Not needed, still must compile asm w/ the 32 bit options regardless.
         ;; Only included as a reminder that this is 32 bit binary code.

.global _start
main ()
{
    /* Are we little or big endian? Originally from Harbison and Steele. */
    union {
        long l;
        char c[sizeof (long)];
    } u;
    u.l = 1;
    exit (u.c[sizeof (long) -1] == 1);

Emacs isn't just an editor, it’s an entire Emacs Lisp interpreter and environment. We can use Emacs Lisp not only to extend and customize our beloved editor, but also to write entire programs and applications. Nic Ferrier’s [elnode][] server is the most ambitious Emacs Lisp application of this sort, but we can start at a smaller scale and try to write our shell scripts and tools with Emacs Lisp.

However, it turns out that writing programs in Emacs Lisp is more intricate than it looks at a first glance. Emacs decades-long history as interactive application have left deep marks in Emacs and Emacs Lisp, which make independent

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "stdint.h"
void print_bits(uintmax_t number)
{
unsigned char* output = calloc (8*sizeof (uintmax_t), 1);
unsigned char* mov = output;
@jstaursky
jstaursky / minimal-emacs-conf.org
Last active November 13, 2020 03:11
minimal emacs, .emacs, init.el, beginner

Minimal .emacs/init.el

Sets up clean organization inside user-emacs-directory with a separate custom.el file, a backup directory and a settings.org file for a more literate emacs configuration that can be built upon.

Note that you may need to ”touch” some of the initial files so no error appears on startup.

;; do not use `init.el` for `custom-*` code - use `custom-file.el`.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))

(when (file-exists-p custom-file)
@jstaursky
jstaursky / slaspec.org
Last active August 13, 2020 15:29
learning to write slaspec
define endian=big;
define  space     ram       type=ram_space       size=4   default;
define  space     register  type=register_space  size=4;
define  register  offset=0  size=1 [ r0 r1 ];

define token instr(8)
op=(0,0) reg=(1,1) mode=(2,2) imm=(3,3)
;
attach variables [ reg ] [ r0 r1 ];
# This is David A. Wheeler's template for configure.ac, showing
# taken from https://dwheeler.com/autotools/
# some suggested options and setups.
# Process this file with autoconf to produce a configure script.
# Initialize autoconf.
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS],
[TAR-NAME], [URL])
# Force autoconf to be at least this version number:
(use-package rtags
  ;; Note that if you recompile and create new compile_commands.json
  ;; you will need to run "rc -J ." for rtags to reflect the changes.
  ;; REMEMBER RTAGS DOES NOT WORK FOR PROJECTS INSIDE /tmp
  :init
  (add-hook  'c++-mode-hook  #'rtags-start-process-unless-running)
  (add-hook  'c-mode-hook    #'rtags-start-process-unless-running)
  (add-hook 'rtags-jump-hook 'evil-set-jump)
@jstaursky
jstaursky / od-vs-hexdump.org
Last active July 23, 2020 19:11
hexdump vs od

Equivalent expressions in od and hexdump

interpret next 4 bytes as a signed decimal

od -t d4

format the next 4 bytes as a 4 byte decimal

hexdump  -e '/4 " %d"'