MIPS Assembly and working with bytes

Click For Summary

Discussion Overview

The discussion revolves around how to load a binary byte value into a register in MIPS Assembly language, specifically focusing on the challenges faced when using binary literals and the appropriate instructions for handling constants.

Discussion Character

  • Homework-related, Technical explanation, Debate/contested

Main Points Raised

  • One participant attempts to load the binary value 0b10101011 into register $s1 using the instruction "add $s1, $zero, 0b10101011" but encounters an error.
  • Another participant suggests using the "addi" instruction, indicating that immediate instructions are suitable for storing constants.
  • A later reply questions the validity of using binary literals in the assembler, proposing that the participant may need to convert the binary number to hexadecimal (0xAB) or decimal (171) instead.
  • There is a repeated assertion that the assembler may not support binary literal constants, leading to confusion about how to represent the value correctly.

Areas of Agreement / Disagreement

Participants express differing views on the use of binary literals in MIPS Assembly, with some suggesting alternatives while others remain uncertain about the assembler's capabilities. The discussion does not reach a consensus on the best approach.

Contextual Notes

Limitations include the potential lack of support for binary literals in certain MIPS assemblers and the need for conversion to other numeral systems. Specific assembler details are not provided, which may affect the applicability of suggested solutions.

Who May Find This Useful

Individuals learning MIPS Assembly language, those working on related homework assignments, or anyone interested in the nuances of using constants in assembly programming.

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?
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 4 ·
Replies
4
Views
6K
Replies
5
Views
17K
Replies
6
Views
3K
  • · Replies 2 ·
Replies
2
Views
15K
Replies
13
Views
39K