EGG Docs

Usage

Running the emulator with an Assembly file will assemble it and start a machine to run it on. By default, the machine is a RISC-V IM 32 bits. Use the flag -a or -arch to change the architeture. Run egg -h to see all command line options and egg -l to see all supported architetures.

The Assembly syntax is architeture-dependent. Though, a library is provided for creating assembler, so backends may use the same overall syntax (both RISC-V and MIPS uses it).

Assembly

An example follows:

; Semicolon makes a comment til the end of line.

; A label is defined with :.
label:
    ; Instruction arguments starts with destination.
    addi t0, zero, 2

    ; You may also put instructions after the labels.
label2: add t0, t0, t0

    ; There's no parenthesis as in RARS, store uses common immediates.
    sb t0, ra, 3

    ; Hex, octal and binary immediates are supported.
    addi t1, zero, 0xff
    addi t1, zero, 0b010110
    addi t1, zero, 0o644
    addi t1, zero, 0755 ; A leading 0 also defines an octal.

; A # defines a literal til the end of the line.
; Literals are inserted unchanged to the binary (as 'db' in other assemblers).
; If a % is followed by two hex digits, the hex value is inserted instead. Use
; %% to escape it.
msg:
#Hello, World!%0a

; Some directives are supported. "bitsxx" ones creates literal numbers in the
; code, with the bit length specified:
.bits8 0xca 0xfe 0xba 0xbe 0xde 0xad 0xbe 0xef
.bits16 0xcafe 0xbabe 0xdead 0xbeef
.bits32 0xcafebabe 0xdeadbeef
.bits64 0xcafebabedeadbeef
; The "space" directive adds some bytes of spacing in the code:
.space 16
; The "include" directive "copy-pastes" another file in the code:
.include other-asm.asm

Each architeture folder has test Assembly files you may use as examples.

Calls

Standard calls handled by the emulator are as follows. Refer to the architeture documentation on how to perform them:

Debugger

The debugger interface is kinda similar to gdb, though much smaller. Use the -d flag to enter debugger uppon startup. There’s no need of run command, as there’s no process. The next or the continue commands may be used to start running the program normally. Use help to see all available commands.

RISC-V IM 32

Assembly

The RISC-V implementation for EGG uses the standard Assembly syntax. It implements the registers and instructions from the base integer set and the multiplication extension described in this document.

Environment calls

Environment call numbers are placed in the a7 register, and arguments are placed in a0 and a1.

An ebreak instruction will perform a BREAK call.

Example

Example program (writes “Hello, World!”, breaks a line and exits):

    addi a7, zero, 3
    addi a0, zero, msg
    addi a1, zero, 14
    ecall
    ebreak

msg:
#Hello, World!%0a

Memory

The assembled program is loaded at the address 0 on the machine startup, and the pc register is set to 0. The stack pointer register is not initialized: the program should initialize it if it wants to use the stack.

MIPS32

Assembly

The MIPS32 implementation for EGG uses the standard Assembly syntax.

Environment calls

Environment call numbers are placed in the v0 register, and arguments are placed in a0 and a1.

An break instruction will perform a BREAK call.

Memory

The assembled program is loaded at the address 0 on the machine startup, and the pc register is set to 0.

Sagui

Sagui is a fantasy 8 bit RISC architecture created by Dr. Marco Zanata, professor at Universidade Federal do Paraná. The implementation in EGG has one extension: a instruction movr r0, r0 is actually interpreted as a BREAK system call.

It uses the standard Assembly syntax.

Sagui instructions

REDUX-V

O REDUX-V é uma versão 8-bits do RISC-V.

Ele usa a sintaxe Assembly padrão do EGG.

redux-v