This repository contains the source code and documentation for a simple assembler developed in C++. The assembler is designed to translate assembly language code into machine code for a 32 bit ISA. It contains one main file, i.e., code.cpp. It includes file handling and handles the input of assembly code. This file includes all other six header files, which were made separately. This assembler supports six different instruction formats: I, R, S, SB, J, and UJ. Collectively 31 instructions are identified in all. Any other instruction will not be identified and lead to an error.
-
I: Immediate instructions.
-
R: Register instructions.
-
S: Store instructions.
-
SB: Branch instructions with signed offset.
-
J: Jump instructions.
-
UJ: Jump instructions with immediate values.
To use the assembler:
- Write your assembly language code in a text file named
assembly_code.asm
. - Then, we need to include all six header files (
I.h
,S.h
,U.h
,SB.h
,J.h
,R.h
) and the text file containing assembly code (assembly_code.asm
) in the folder wherecode.cpp
is located. - Provide the path to your assembly code (
assembly_code.asm
) as input to the assembler program called code.cpp. - Compile and execute the assembler program.
- It will generate the corresponding machine code, typically outputting it to another file named as
ans.mc
. - Hence, the code in 'ans.mc' will be your desired output for given assembly code.
To verify your machine code , you can use "Venus Simulator" and match it with the machine code generated by simulator. It should match the code generated in 'ans.mc' file.
- The .data: attribute has to be in a separate line.
- The .text: attribute should also be in a separate line.
- Label should be in different line than instruction.
- There would not be any instructions in front of a label; instructions should be on the next line after the label.
- The instruction can have spaces in between registers.
- If any unspecified instruction is given, the code will ignore that instruction.
This Project is contributed by-