• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    C
  • License
    Other
  • Created over 7 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

minimal instruction set and assembler/compiler for "Hello World" execution

full-stack-hello

full-stack-hello is a minimal virtual machine kit capable of performing tasks at any level of the technical stack on which a typical 'Hello World' program execution depends. It means:

  • Instruction Set Architecture (ISA);
  • Virtual machine implementing the ISA;
  • Assembly and/or Compiler following the ISA;
  • Runtime support such as standard libraries and ELF;

Instruction set

Opcode Description
OP_ADD sum two operands
OP_SUB subtract two operands
OP_MUL multiply two operands
OP_DIV divide two two operands
OP_MOD Modulo, remainder of operand 1 divided by operand 2
OP_PRINT print integer or string
OP_JLT jump to specified address (in operand 2) if operand 1 is less than 0
OP_JLE jump to specified address (in operand 2) if operand 1 is less than or equal to 0
OP_JZ jump to specified address (in operand 2) if operand 1 is equal to 0
OP_JGE jump to specified address (in operand 2) if operand 1 is greater than or equal to 0
OP_JGT jump to specified address (in operand 2) if operand 1 is greater than 0
OP_JNZ jump to specified address (in operand 2) if operand 1 is not equal to 0
OP_JMP jump to specified address
OP_CALL call to specified address
OP_RET return to where called from
OP_HALT terminate VM

Assembly Notation

  • Registers are specified by # as temporary storage.
    • print #1 dumps the content of register #1.
  • An immediate value (or simply an immediate or imm) is a piece of data that is stored as part of the instruction itself instead of being in a memory location or a register.
    • mul $-2 $2 #4 stores the result of (-2) * (2) into register #4.
  • A valid Label name ends with : and is referred as :X in any JMP/CALL instructions to jump to label X.
    A:
    print $1
    jmp :A
    
    • Infinite loop that dumps constant 1.

Build and Verify

$ make
cc -Wall -std=gnu99 -g -c -o vm.o -MMD -MF .vm.o.d vm.c
cc -Wall -std=gnu99 -g -c -o as.o -MMD -MF .as.o.d as.c
cc -Wall -std=gnu99 -g -c -o driver.o -MMD -MF .driver.o.d driver.c
cc -Wall -std=gnu99 -g -o as_exec vm.o as.o driver.o
$ make check
42
tests/halt.s pass

Hello World
tests/hello.s pass

42
50
150
tests/test.s pass

$ make test
python tests/run_tests.py
..
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK

Assembler Usage

Specify -h to obtain the description of the assembler.

$ ./as_exec -h
Usage: as_exec [-w] [-x] [-o <out_file>] <in_file>
       -w Assemble <in_file> and write to an ELF file, see -o below
       -o if -w is specifed, <out_file> is used to store the object code
       -x Load <in_file> and execute it

       <in_file> the file name to be used by commands above

For example, if the assembly file in concern is tests/coverage.s

  1. Assemble an assembly source file and evaluate (execute) it.
    ./as_exec tests/hello.s
    
  2. Assemble an assembly source file and write to default ELF file tests/hello.o.
    ./as_exec -w tests/hello.s
    
  3. Assemble an assembly source file and write to default ELF file tests/temp.o.
    ./as_exec -o tests/temp.o -w tests/hello.s
    
  4. Laod an assembled ELF file tests/hello.o and evaluate (rexcute) it.
    ./as_exec -x tests/hello.o
    

The common ELF tools, such as objdump, can be applied to the output ELF file.

objdump -x tests/hello.o

Currently, the ELF support is very limited and could be improved.

Licensing

full-stack-hello is freely redistributable under the two-clause BSD License. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

More Repositories

1

amacc

Small C Compiler generating ELF executable Arm architecture, supporting JIT execution
C
997
star
2

mini-arm-os

Build a minimal multi-tasking OS kernel for ARM from scratch
C
929
star
3

facebooc

Yet another Facebook clone written in C
C
553
star
4

MazuCC

A minimalist C compiler with x86_64 code generation
C
502
star
5

talks

schedule and materials about my presentations
338
star
6

nstack

Userspace TCP/IP stack for Linux
C
314
star
7

unix-v1

Restoration of 1st Edition UNIX kernel sources from Bell Laboratories
C
193
star
8

kernel-in-kernel

Develop your own OS kernel by reusing Linux infrastructure
C
171
star
9

min-dl

minimal dynamic linker implementation for ELF, supporting x86_64 and Arm/Aarch64
C
162
star
10

tetris

A text-mode tetris game
C
144
star
11

xv6-x86_64

re-implementation of UNIX v6 in ANSI C for x86_64 SMP
C
143
star
12

stm32f429-linux-builder

create a uClinux distribution for STM32f429 Discovery board
Makefile
133
star
13

mazu-editor

a minimalist text editor with syntax highlight, copy/paste, and search
C
108
star
14

codezero

Codezero Microkernel
C
102
star
15

cregex

A small implementation of regular expression matching engine in C
C
80
star
16

tlsf-bsd

Two Level Segregated Fit (TLSF) memory allocator implementation, BSD License
C
74
star
17

simple-dvm

A simplified educational Dalvik virtual machine implementation
C
58
star
18

armv8-hello

Hello World for bare metal ARMv8 using QEMU
Makefile
51
star
19

lsd_slam

LSD-SLAM
C++
48
star
20

tinygl

TinyGL: a Small, Free and Fast Subset of OpenGL
C
44
star
21

ogc

A minimal mark-and-sweep garbage collector
C
43
star
22

x-compressor

A minimalist lossless data compressor
C
42
star
23

jit-construct

JIT compiler from scratch, derived from Nick Desaulniers' great work
Lua
37
star
24

svgirl

SVG Instant Rendering Library with focus on embedded systems
C
36
star
25

ttt

An implementation of tic-tac-toe in C, featuring an AI powered by the negamax algorithm
C
30
star
26

rv32jit

JIT-accelerated RISC-V instruction set simulator
C++
30
star
27

stm32f429-r3d

small software 3D rendering program on STM32F429-Discovery
C
26
star
28

kvm-user-x86

A simple userspace program to interact with Linux KVM
C
23
star
29

uThreads

A concurrent library based on cooperative scheduling of user-level threads(fibers) implemented in C++
C++
22
star
30

tvision

GCC/Linux port of Turbo Vision
C++
21
star
31

hungry-birds

classical example of concurrent producer/consumer problem
C
20
star
32

nalloc

structure aware memory allocator
C
19
star
33

stm32f429-lcd-demo

Simple STM32F429 Discovery LCD demo program using emWin library
C
18
star
34

jamvm

JamVM 2 + OpenJDK
C
18
star
35

littlefs-fuse

A FUSE wrapper that puts the littlefs in user-space
C
17
star
36

linsched

Restoration of The Linux Scheduler Simulator (LinSched)
C
16
star
37

stm32f429-demos

Collection of demo program for STM32F429 Discovery
Makefile
15
star
38

auto-tetris

Play Tetris game automatically!
C
15
star
39

skin-deep

Generate faces with smoother skin
C
14
star
40

matrix_oo

Object-oriented matrix implementation in C99
C
14
star
41

tic-tac-toe

An implementation of classical tic-tac-toe game for terminal I/O
C
12
star
42

dummy-driver

dummy Linux kernel module for education purpose
C
11
star
43

Taunix

Realtime operating system kernel for TI TMS320F24x DSP
C
11
star
44

MathEX

An embedded mathematical expression evaluator in C99
C
10
star
45

fizzbuzz

Implement Fizzbuzz without loop-internal conditionals, or arithmetic operators.
C
10
star
46

cjit

A tiny JIT compiler based on MIR
C++
9
star
47

anrmalloc

A new embedded-friendly memory allocator
C
9
star
48

arith_register

Use ELF linker set to construct lists of arithmetic implementations automatically
C
8
star
49

membroker

Memory Broker is a library that helps balance memory load between processes in user space using IPC
C
6
star
50

scalable-font-editor

A scalable font editor, which produces the fonts for embedded environments
C
5
star
51

bubble-sort-arm

Bubble sort in ARM assembly (incomplete)
Assembly
4
star
52

doxygen-oop-in-c

C
4
star
53

iota-whitepaper

IOTA whitepaper
TeX
4
star
54

micronaut-from-scratch

Ahead-of-Time compilation with Micronaut and GraalVM
Java
1
star
55

git-hook-tests

Tests for Git Hooks
Shell
1
star
56

ci-test-public

(TMP) A repository for testing CI pipeline
1
star
57

muxleq

16-bit virtual machine with a two-instruction set CPU capable of running Forth
Forth
1
star