MIPS Assembly and working with bytes

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 5K views
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?