Giter Site home page Giter Site logo

mips_assembler's Introduction

MIPS Assembler + Emulator

MIPS Assembler

목표

왼쪽과 같은 어셈블리 코드를 오른쪽과 같은 바이너리 코드로 변환하는것을 목표로 한다

과정

image

MIPS Assembler에서 지원해야 하는 명령어들은 위와 같이 정의되어있다.

image

3가지 종류의 Instruction 종류에 맞게 변환하는 작업을 거친다.

해결방법

fopen함수를 통해서 어셈블리 파일을 열었고, 한 줄을 읽는 것은 fgets 함수를 사용하였고 strtok() 함수를 사용해서 공백을 기준으로 단어를 받았습니다. 입력받은 단어가 .data 혹은 .text 이라면, 그 후로는 각각 data, text section이므로 한줄을 입력받 을때마다 cnt 를 증가시켜줬습니다. Data를 받을때는 data_section이라는 구조체를 활용하여 data를 읽고 적절한 구조체 변수에 값 들을 할당시켜줬습니다.

한 줄을 읽을 때 마다 pc값을 +4씩 증가시켜주었고, data section에서 text section으로 바뀔때는 메모리 hierarchy 구조에 맞게 0x400000으로 바꾼 후에 +4씩 증가시켜 줬습니다. 만약 입력받은 line이 공백이거나 label만 들어있는 경우에는 메모리를 차지하지 않기 때문에 구조체에 이 pc address를 할당하지 않았고 pc값고 증가시키지 않았습니다. Text를 받을때는 instr_one 이라는 구조체를 활용하여 text를 읽고 적절한 구조체 변수에 값을 할당시켜줬습니다.

Data, text section이 끝날 때 finish라는 단어를 구조체에 할당시켜줘서, 파일쓰기 과정에서 for loop를 돌 때 finish를 만나면 실행종료하게 만들었습니다. 파일을 읽는것과 동시에 o파일에 함수들을 쓰지 않았고, 한번 파일을 다 읽고 다시 구조체들을 for loop를 통해 돌리고 o파일에 작성하였습니다. o파일의 가장 위에는 text, data section의number 가장 마지막에는 value 값들을 출력해야 하는데, 이러한 경우에 순차적으로 o파일에 작 성시 순서가 꼬이기 때문입니다.

mips_assembler's People

Contributors

junhyungjang avatar

Watchers

 avatar

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.