Coder Social home page Coder Social logo

mipssembler's Introduction

MIPSsembler

A tiny MIPS assembler written in Rust.

memo

MIPS(Microprocessor without Interlocked Pipeline Stages)

Basic instruction formats

R (Register)

and $17, $17, $0

+-----------+-------+-------+-------+----------+----------+
| opcode(6) | rs(5) | rt(5) | rd(5) | shamt(5) | funct(6) |
+-----------+-------+-------+-------+----------+----------+
| 000000    | 10001 | 00000 | 10001 | 00000    | 100100   |
+-----------+-------+-------+-------+----------+----------+

I (Immediate)

addiu $17, $17, 0x1

+-----------+-------+-------+-----------------------------+
| opcode(6) | rs(5) | rt(5) | immediate(16)               |
+-----------+-------+-------+-----------------------------+
| 001001    | 10001 | 10001 | 0000000000000001            |
+-----------+-------+-------+-----------------------------+

J (Jump)

j lab1

+-----------+---------------------------------------------+
| opcode(6) | address(26)                                 |
+-----------+---------------------------------------------+
| 000010    | 00000100000000000000000110                  |
+-----------+---------------------------------------------+

Memory allocation

$sp +---------------+ 0x7ffffffc
    | Stack         | 
    +-------+-------+
    |       |       |
    |       v       |
    |               |
    |       ^       |
    |       |       |
    +-------+-------+
    | Heap          |
$gp +---------------+ 0x10008000
    | Static(Data)  |
    +---------------+ 0x10000000
    | Text(Code)    |
 PC +---------------+ 0x00400000
    | Reserved      |
    +---------------+ 0x00000000

Example

$ mipssembler input.s output.o

input.s

	.data
data1:	.word	100
data2:	.word	200
data3:	.word	0x12345678
	.text
main:
	and	$17, $17, $0
	and	$18, $18, $0
	la	$8, data1
	la	$9, data2
	and	$10, $10, $0
lab1:
	and	$11, $11, $0
lab2:
	addiu	$17, $17, 0x1
	addiu	$11, $11, 0x1
	or	$9, $9, $0
	bne	$11, $8, lab2
lab3:
	addiu	$18, $18, 0x2
	addiu	$11, $11, 1
	sll	$18, $17, 1
	srl	$17, $18, 1
	and	$19, $17, $18
	bne	$11, $9, lab3
lab4:
	addu	$5, $5, $31
	nor	$16, $17, $18
	beq	$10, $8, lab5
	j	lab1
lab5:
	ori	$16, $16, 0xf0f0

output.o

00000000000000000000000001011000
00000000000000000000000000001100
00000010001000001000100000100100
00000010010000001001000000100100
00111100000010000001000000000000
00111100000010010001000000000000
00110101001010010000000000000100
00000001010000000101000000100100
00000001011000000101100000100100
00100110001100010000000000000001
00100101011010110000000000000001
00000001001000000100100000100101
00010101011010001111111111111100
00100110010100100000000000000010
00100101011010110000000000000001
00000000000100011001000001000000
00000000000100101000100001000010
00000010001100101001100000100100
00010101011010011111111111111010
00000000101111110010100000100001
00000010001100101000000000100111
00010001010010000000000000000001
00001000000100000000000000000110
00110110000100001111000011110000
00000000000000000000000001100100
00000000000000000000000011001000
00010010001101000101011001111000

License

This project is licensed under the MIT License - see the LICENSE file for details.

mipssembler's People

Contributors

parksb avatar

Stargazers

roy lieu avatar Krupananda Reddy avatar Sohye Choi avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

adutilleul

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.