Registers
Registers
¶
Registers Component Provides a 32-bit MIPS register file implementation with:
-
32 general-purpose registers ($0-$31)
-
Program Counter (PC) special register
-
Register naming conventions following MIPS architecture
Source code in sim/registers.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
get_register_name(register_number)
¶
Get MIPS Register Name
Converts register number to standard MIPS register name
Parameters:
register_number (int): Register number (0-31)
Returns:
str: Register name (e.g., "$zero", "$t0", "$sp")
"Invalid": If register_number is outside valid range
Register naming follows MIPS conventions:
$0: $zero (constant 0)
$1: $at (assembler temporary)
$2-$3: $v0-$v1 (values)
$4-$7: $a0-$a3 (arguments)
$8-$15: $t0-$t7 (temporaries)
$16-$23: $s0-$s7 (saved)
$24-$25: $t8-$t9 (temporaries)
$26-$27: $k0-$k1 (kernel)
$28: $gp (global pointer)
$29: $sp (stack pointer)
$30: $fp (frame pointer)
$31: $ra (return address)
Source code in sim/registers.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
read_register(register_number)
¶
Read Value from Register
Parameters:
register_number (int): Register number (0-31)
Returns:
int: 32-bit value stored in specified register
Raises:
ValueError: If register_number is outside valid range (0-31)
Source code in sim/registers.py
25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
reset()
¶
Reset Register File State
Initializes all general-purpose registers to 0
Resets program counter (PC) to 0
Returns:
None
Source code in sim/registers.py
15 16 17 18 19 20 21 22 23 |
|
write_register(register_number, value)
¶
Write Value to Register
Parameters:
register_number (int): Register number (0-31)
value (int): 32-bit value to write
Notes:
- Writing to $zero (register 0) is silently ignored
- Values are masked to 32 bits (& 0xFFFFFFFF)
Raises:
ValueError: If register_number is outside valid range (0-31)
Source code in sim/registers.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|