Skip to content

Add pseudo instruction support (ble, blt, bge, bgt, move, li)#1

Open
otonomee wants to merge 10 commits into
Beebeeoii:masterfrom
otonomee:feature/add-ble-instruction
Open

Add pseudo instruction support (ble, blt, bge, bgt, move, li)#1
otonomee wants to merge 10 commits into
Beebeeoii:masterfrom
otonomee:feature/add-ble-instruction

Conversation

@otonomee

@otonomee otonomee commented Jun 7, 2026

Copy link
Copy Markdown

Summary

Adds support for 6 MIPS pseudo-instructions with step-by-step educational output showing how
they expand into real instructions:

  • Comparison: ble, blt, bge, bgt (expand to slt + branch)
  • Utility: move (expands to add), li (expands to ori or lui+ori)

Example

Input: ble $s0, $0, End
Output shows:

  • Pseudo-instruction detection
  • Expansion into slt $at, $0, $s0 + beq $at, $0, End
  • Explanations for each step
  • Binary and hex output for each expanded instruction

otonomee added 10 commits June 7, 2026 13:53
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.
@otonomee otonomee force-pushed the feature/add-ble-instruction branch from 3e7eb57 to b095127 Compare June 7, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant