I'm kind of firm with x86-64 assembly (not an expert maybe), but many aspects are similar from one platform's assembler to the next, so I'm also trying to answer questions that are not actually in my range of knowledge, and I've stumbled upon several questions about MIPS assembly.
This wakened my interest in details, so I've checked several online ressources for detailed information. mips.com has a lot to read, but just for my quick information:
Is the $zero
register just conventional zero or hardware zero?
Some sources say it is conventionally zero, others claim it is always zero. Or do the latter simply assume it is zero, because it conventionally is?
Thanks in advance for clarification (and/or pointers to a specific doc from MIPS' site, so I don't need to crawl information that I actually don't need).
The zero register is a special register that is hard-wired to the integer value 0 . This register is found in many RISC instruction set architectures such as MIPS and RISC-V. On those architectures writing to that register is always discarded and reading its value will always result in a 0 being read.
The MIPS R2000 CPU has 32 registers. 31 of these are general-purpose registers that can be used in any of the instructions. The last one, denoted register zero, is defined to contain the number zero at all times.
The registers that are visible in assembly language are called general purpose registers and floating point registers. There are 32 general purpose registers. Each general purpose register holds a 32 bit pattern. In assembly language, these registers are named $0, $1, $2, ... , $31 .
You can simply use the $zero register as a reference and write its value, which is 0 or 0b00000000, into the register you want to clear up.
The definitive answer to this can be found in MIPS32® Architecture for Programmers Volume I: Introduction to the MIPS32® Architecture (pdf), available at mips.com (registration required). According to Section 2.4.8.1 in that document:
Two of the CPU general-purpose registers have assigned functions:
r0 is hard-wired to a value of zero, and can be used as the target register for any instruction whose result is to be discarded. r0 can also be used as a source when a zero value is needed.
r31 is the destination register used by JAL, BLTZAL, BLTZALL, BGEZAL, and BGEZALL without being explicitly specified in the instruction word. Otherwise r31 is used as a normal register.
The remaining registers are available for general-purpose use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With