MIPS Assembly and working with bytes

AI Thread Summary
To load the binary value 0b10101011 into register $s1 in MIPS assembly, using direct binary notation is not supported by many assemblers. Instead, it is recommended to convert the binary to hexadecimal (0xAB) or decimal (171) before loading it. The instruction "add $s1, $zero, 0b10101011" fails because the assembler does not recognize the binary literal. Using immediate instructions like "addi" is suggested for storing constants. Ensuring compatibility with the specific assembler being used is crucial for successful execution.
RET80
Messages
15
Reaction score
0

Homework Statement


I need to put in a byte in register $s1 that is 0b10101011


Homework Equations


add
addi
lb
sb
$zero (if needed)


The Attempt at a Solution


I attempted at putting in a byte in register $s1 as follows:
add $s1, $zero, 0b10101011
however it throws an error, I can't use 0x10101011 because isn't that hex? it would throw a huge number at me otherwise. So how in the world do I load up a binary number into register $s1 ?
 
Physics news on Phys.org
Any takers? Anyone trained or have used Assembly before? I've used it for the 8051 intels but MIPS is a little different as to what you can and can't do.
 
Try addi, or add immediate value. What you're trying to store is a constant, rather than an address or the value of some register. Doing stuff with constants is what the immediate instructions are for.
 
Mark44 said:
Try addi, or add immediate value. What you're trying to store is a constant, rather than an address or the value of some register. Doing stuff with constants is what the immediate instructions are for.

Nope doesn't work. It considered the byte (as it is) 0b10101011 an invalid language element.
 
It might be the case that your MIPS assembler doesn't support binary literal constants. In that case, you probably need to convert your number to hexadecimal or decimal first (0xAB or 171). What assembler are you using?
 
Back
Top