MIPS Assembly Code - Convert instruction code to binary

Click For Summary
SUMMARY

The discussion focuses on converting MIPS assembly instructions into 32-bit binary machine code using the PCSpim simulator. The example provided is the instruction "addi $t0, $t0, 1", which translates to the binary output "00100001 00001000 00000000 00000001". Participants emphasize the need to parse input strings and set the appropriate bits for output. The MIPS instruction set reference is crucial for understanding the encoding of instructions like ADDI, which follows a specific bit structure for operation, source, and destination registers.

PREREQUISITES
  • Understanding of MIPS assembly language syntax
  • Familiarity with the PCSpim simulator
  • Knowledge of binary encoding for MIPS instructions
  • Ability to manipulate strings in assembly language
NEXT STEPS
  • Study the MIPS instruction set reference for detailed encoding of various instructions
  • Learn how to parse strings in MIPS assembly to extract instruction components
  • Explore MIPS syscall functionality for input and output operations
  • Investigate examples of converting MIPS assembly to binary machine code
USEFUL FOR

Students learning MIPS assembly programming, developers working with low-level programming, and anyone interested in understanding machine code generation from assembly instructions.

JSGhost
Messages
26
Reaction score
0

Homework Statement



Write a single line MIPS assembly code as an input through the SPIM simulator console and the program will output a 32 bit MIPS machine code through the console. I'm using PCSpim to write the code.

An example,

I input this instruction in the console.

addi $t0,$t0,1

and the console outputs.

00100001 00001000 00000000 00000001

I'm trying to write it for other instruction codes as well.

Homework Equations



MIPS Syscall Sheet
https://www.student.cs.uwaterloo.ca/~isg/res/mips/traps

The Attempt at a Solution



la $a0, 8 # string into $a0
syscall
move $a1, $a0, 8

I just need an example for one instruction like using addi as a guide and I can do the rest. Or point in the right direction. I get stuck after getting the input from console. Should I store the "whole" string to one address? I know there are different ways of doing it like taking each character and check it but I'd rather take the whole code through a string.
 
Physics news on Phys.org
The link you gave won't be much help - it's just the MIPS system calls. What you need is the instruction set reference, showing how each instruction is encoded in a 32-bit number. Here's something that might be helpful - http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html

Here's an example from that site.
ADDI -- Add immediate (with overflow)
Description:
Adds a register and a sign-extended immediate value and stores the result in a register

Operation:
$t = $s + imm; advance_pc (4);

Syntax:
addi $t, $s, imm

Encoding:
0010 00ss ssst tttt iiii iiii iiii iiii

Here's how you read it - going left to right, the first 6 bits are the the code for the ADDI instruction. The next 5 bits are the register you're adding the value to. The next 4 bits are the register in which the sum will be stored, and the last 12 bits are the immediate value (a constant) that gets added to the first register.

You need to take an input string, such as "addi $t0, $t0, 1" and parse it so that you can set the appropriate bits in the output string of 1s and 0s.
 
Say for example, I put a string "addi $t0,$t0,1" in $a0. How do I put the binary form of that on the console? Do I need to make a comparison using function and define the binary form of that instruction using .asciiz?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
5K
Replies
1
Views
2K
  • · Replies 22 ·
Replies
22
Views
5K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
13
Views
39K
  • · Replies 12 ·
Replies
12
Views
11K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 1 ·
Replies
1
Views
24K