Add pseudo instruction support (ble, blt, bge, bgt, move, li)#1
Open
otonomee wants to merge 10 commits into
Open
Add pseudo instruction support (ble, blt, bge, bgt, move, li)#1otonomee wants to merge 10 commits into
otonomee wants to merge 10 commits into
Conversation
Implemented detection and expansion for 6 MIPS pseudo-instructions: - Comparison branches (ble, blt, bge, bgt) expand to slt + beq/bne - move expands to add with $0 - li expands to ori (16-bit) or lui + ori (32-bit) Each expansion includes educational explanations for the generated instructions to aid learning.
…dler - Replace all sprintf calls with snprintf (64 for instructions, 128 for explanations) - Add NULL pointer checks in both isPseudoInstruction() and expandPseudoInstruction() - Add operand count validation before accessing operands array - Fix 16-bit immediate range check from (-32768, 65535) to (-32768, 32767) - Initialize operand pointers to NULL to prevent unconditional access
Implements forward conversion from MIPS assembly to 32-bit binary: - R-type: handles standard (rd,rs,rt), shift (rd,rt,shamt), and jr (rs) formats - I-type: supports load/store (rt,offset(rs)), branch (rs,rt,offset), lui (rt,imm), and immediate ops (rt,rs,imm) - J-type: jump instructions with 26-bit address - Proper handling of signed immediates via two's complement - Helper functions mipsToOpCode and mipsToFnCode for instruction lookup
Changed R-type and I-type register/immediate buffers from inline string literal initialization to explicit strcpy calls. This ensures the decimalToBinary function correctly interprets buffer lengths via strlen, preventing potential buffer corruption issues.
Added test-pseudo-cases.txt with comprehensive test coverage for all pseudo-instructions: ble, blt, bge, bgt, move, and li (both 16-bit and 32-bit immediate values). All tests verified working correctly with expected expansions.
Add comprehensive documentation for pseudo-instruction support including: - Updated Features section highlighting automatic expansion - Complete list of supported real MIPS instructions (R/I/J-type) - Detailed pseudo-instruction expansion table - Example outputs for both pseudo-instructions and regular instructions
Add .gitignore to exclude build artifacts (binaries, object files) and internal documentation from version control. Clean build verification confirms all features working correctly.
3e7eb57 to
b095127
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for 6 MIPS pseudo-instructions with step-by-step educational output showing how
they expand into real instructions:
ble,blt,bge,bgt(expand toslt+ branch)move(expands toadd),li(expands tooriorlui+ori)Example
Input:
ble $s0, $0, EndOutput shows:
slt $at, $0, $s0+beq $at, $0, End