This is my first attempt at writing a MIPS compiler. Basically all it does is it read the asm source file as text and then it will compile to hex and generate a binary file. This is the command line tool, the syntax is "mips_asm.exe source_file [debug (True of False)]". The example sources are all in the download
Basically all MIPS instruction of this website can be parsed. For more info see here https://en.wikibooks.org/wiki/MIPS_A...uction_Formats. I will only list psuedo instruction
Version 1.2
https://www.mediafire.com/file/63j2b...R_V1.2.7z/file
Version 1.1
http://www.mediafire.com/file/zzkb5m...mpiled.7z/file
- How to do a label
For branching this tool used 'label' as a location for branch. A @ sign indicates the label that the tool will jump to and a : sign defines a label.
- How to comment
This tool only support one-line comment. Command is '#' or '***' or '//'
- How to do a loop
Please note that break and continue is not yet implemented. Also the use of a label inside a loop is undefined so don't do that.
Psuedo-Instruction
Tool-Specified-Instruction
Basically all MIPS instruction of this website can be parsed. For more info see here https://en.wikibooks.org/wiki/MIPS_A...uction_Formats. I will only list psuedo instruction
Version 1.2
https://www.mediafire.com/file/63j2b...R_V1.2.7z/file
Version 1.1
http://www.mediafire.com/file/zzkb5m...mpiled.7z/file
- How to do a label
For branching this tool used 'label' as a location for branch. A @ sign indicates the label that the tool will jump to and a : sign defines a label.
Code:
beq t9, zero, @return nop :return jr ra nop
This tool only support one-line comment. Command is '#' or '***' or '//'
- How to do a loop
Please note that break and continue is not yet implemented. Also the use of a label inside a loop is undefined so don't do that.
Code:
BEGIN LOOP
RUN_AT_LEAST_ONCE TRUE # If RUN_AT_LEAST_ONCE is TRUE, DO is executed before checking condition
SET_REG_AS_CONDITION t9 # default is t9
INIT
move s0, zero # INIT is executed first
END
DO
addu t1, s0, t0
lbu t2, 0x0(t1)
ori t3, zero, 0x2
#BREAK WHEN t3 = t2
ori t3, zero, 0x3
#CONTINUE WHEN t3 = t2
sb t2, 0x0(s1)
slti t9, s0, 0x10 # t9 == 0 break, t9 != 0 continue
END
INCREMENT
addiu s0, s0, 1
END
END
Code:
move rd, rs # this is equivalent to 'addu rd, rs, zero' b @label # this is equivalent to 'beq zero,zero, @label'
Code:
The VARxxx instruction only work if your script passes a0 as the source function pointer. So if you decide to place the script at offset 0x2000 in RAM then when you call your compiled function a0 should contains 0x2000. AUTHORNAME your_name # This will add 16 bytes header of your name in the script SCRIPTNAME your_script_name # This will add 32 bytes header of the script name LOCALVAR_size 0x10 # this will add 0x10 bytes to the end of your binary script as a buffer # the VAR + load or VAR + store instructions access the content of the LOCALVAR buffer which is at the end of the script # instead of allocate more memory and slow down code's execution VARlbu rd, 0x04 VARlw rd, 0x04 VARsh rd, 0x08
Comment