MIPS Assembly and working with bytes

In summary, the conversation discusses the process of putting a byte into register $s1 in MIPS assembly. The individual attempted to use the add instruction with a binary number, but encountered an error. Other suggestions were made, such as using the addi instruction or converting the binary number to hexadecimal or decimal. It is also mentioned that some MIPS assemblers may not support binary literal constants.
  • #1
RET80
15
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
  • #2
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.
 
  • #3
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.
 
  • #4
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.
 
  • #5
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?
 

1. What is MIPS Assembly?

MIPS Assembly is a low-level programming language used for writing code that can be directly executed by a computer's central processing unit (CPU). It is commonly used in embedded systems and is known for its efficient use of memory and speed.

2. How are bytes represented in MIPS Assembly?

In MIPS Assembly, bytes are represented as 8-bit binary numbers. Each byte can hold a value between 0 and 255, which is equivalent to a single character or symbol.

3. What is the difference between a byte and a word in MIPS Assembly?

A byte is a unit of measurement that consists of 8 bits, while a word is a unit of measurement that consists of 32 bits. In MIPS Assembly, a word is the default data size used for arithmetic and memory operations.

4. How do I work with bytes in MIPS Assembly?

To work with bytes in MIPS Assembly, you can use the lb (load byte) and sb (store byte) instructions. These instructions allow you to load a single byte from memory or store a single byte to memory, respectively.

5. Can I convert between bytes and other data types in MIPS Assembly?

Yes, you can convert between bytes and other data types in MIPS Assembly using the lbu (load byte unsigned) and sbu (store byte unsigned) instructions. These instructions allow you to load and store bytes as unsigned integers.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
14K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
16K
Back
Top