Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 1.62 KB

README.md

File metadata and controls

56 lines (38 loc) · 1.62 KB

Simple compiler

Requirements

  • Bison version 3.7.6
  • Flex version 2.6.4

build

Run make command.

Usage

Run ./compiler [Filename]. The output will be stored in [filename].out.

Inside the compiler

Register usage

  • We use $s1 as the base refrence of our local variables.
  • We use $s0 as the base refrence of our global variables.
  • S registers are callee preserved.
  • We use JALR for function calls. Return address is stored in $ra.
  • We use $t registers for computation purposes. These registers are caller preserved.

Stack

  • We use stack for the calculations and storing variables.

Function structure in stack

  1. return value
  2. return address (go to caller)
  3. preserved registers value ($s[0-1])
  4. local variables (including args)

function calls

First the caller put the input arguments on top of stack. and then calls the callee. The callee then stores the return address. Before returning, the callee brings the stack pointer on return value.