Skip to content

ornush/assembler-lab-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assembler Project

This project implements an assembler in C for a custom assembly language.

The assembler receives .as source files, expands macros, performs a first pass and a second pass, and generates the required output files according to the project specifications.

Compilation

To compile the project, run:

make

To clean compiled files:

make clean

Usage

Run the assembler with one or more file names, without the .as extension:

./assembler ps

Multiple files are supported:

./assembler file1 file2 file3

For example, running:

./assembler ps

will process the file:

ps.as

Output Files

The assembler may generate the following files:

  • .am – source file after macro expansion.
  • .ob – object file containing the encoded machine words.
  • .ent – entry symbols file, created only when valid .entry symbols exist.
  • .ext – external symbol references file, created only when external symbols are actually used.

If errors are detected, the assembler prints the relevant error messages and does not generate the final output files.

Project Structure

  • main.c – runs the assembler flow for each input file.
  • pre_assem.c / pre_assem.h – handles macro expansion and creates the .am file.
  • first_pass.c / first_pass.h – performs the first pass, builds the symbol table, and calculates instruction and data addresses.
  • second_pass.c / second_pass.h – performs the second pass, resolves symbols, handles entries and externals, and creates output files.
  • instruction_utils.c / instruction_utils.h – handles instruction parsing, addressing modes, opcode encoding, and operand encoding.
  • data_utils.c / data_utils.h – handles data directives such as .data, .string, and .mat.
  • symbol_table.c / symbol_table.h – manages the symbol table.
  • file_io.c / file_io.h – handles file operations and output file writing.
  • mcros.c / mcros.h – manages macro storage and lookup.
  • utils.c / utils.h – general helper functions.
  • makefile – builds the project.

Supported Directives

The assembler supports the following directives:

  • .data
  • .string
  • .mat
  • .entry
  • .extern

Supported Features

  • Macro definition and expansion.
  • Two-pass assembly process.
  • Symbol table management.
  • Instruction encoding.
  • Multiple addressing modes:
    • Immediate addressing
    • Direct addressing
    • Matrix/index addressing
    • Register addressing
  • Entry and external symbol handling.
  • Error reporting with line numbers.
  • Support for multiple input files in one run.

Error Handling

The assembler reports errors such as:

  • Undefined .entry symbols.
  • Undefined symbols.
  • Invalid symbols.
  • Invalid addressing modes.
  • Lines longer than the allowed maximum length.
  • Macro definition errors.
  • File opening or writing errors.

If errors are found, the assembler prints the errors and does not generate the final output files.

Notes

  • The project is written in ANSI C / C90 style.
  • The project is compiled using strict flags such as:
-ansi -Wall -pedantic
  • Debug prints were removed from the final version so that only required error messages are displayed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors