Site Tools


ivss

Table of Contents

ivss (Project)

ivss is a project I built to assemble, link, and execute programs for a hypothetical 32-bit CPU. It's written in C and includes an assembler, a linker, and an emulator. Assembly source becomes an object file, the linker combines objects and places sections in memory, and the emulator executes the resulting program.

The machine has sixteen general-purpose registers, including the stack pointer and program counter, and three control registers: status, handler, and cause. Its instructions cover arithmetic, memory access, branches, calls, and interrupts. The assembler handles labels, directives, and symbol references, while the linker combines sections and resolves symbols. The emulator applies relocation records when loading the linked program. The object representation uses ELF64 structures even though the simulated machine is 32-bit.

For example, this program loads two values, adds them, and halts:

.section my_code
    ld $5, %r1
    ld $7, %r2
    add %r2, %r1
    halt
.end

Save it as main.s. After building the tools with make, assemble it, place its code at the emulator's initial program-counter address, and run it:

$ ./asembler -hex -o main.o main.s
$ ./linker -hex \
    -place=my_code@0x40000000 \
    -o program.hex \
    main.o
$ ./emulator program.hex

The assembler's -hex option writes the serialized object format expected by the linker. The emulator prints the register state after execution; r1 contains 0x0000000c, or twelve. The executable name asembler follows the current Makefile. Programs can also use memory-mapped terminal and timer devices, with interrupt handlers responding to input or timer events. The repository's assembly examples demonstrate these interactions, and -debug enables instruction tracing in the emulator.

Concepts

ivss.md · Last modified: by 127.0.0.1