Skip to content

Commit 8fef99e

Browse files
committed
Refine documentation
1 parent 3b9d203 commit 8fef99e

File tree

2 files changed

+68
-11
lines changed

2 files changed

+68
-11
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,15 @@ Ran 52 tests in 8.842s
7777
OK
7878
```
7979

80-
Check the messages generated by `make help` to learn more.
80+
### Command Line Options
81+
AMaCC supports the following command line options:
82+
* `-s` : Print source and generated intermediate representation (IR)
83+
* `-o <file>` : Create executable file and terminate normally
84+
* `-fsigned-char` : Use signed char for char type (default is unsigned)
85+
86+
If no options are specified, the compiled code is executed immediately (if there were no compile errors) with any additional command line arguments passed to the program.
87+
88+
Check the messages generated by `make help` to learn more about build targets.
8189

8290
## Benchmark
8391
AMaCC is able to generate machine code really fast and provides 70% of the performance of `gcc -O0`.

docs/IR.md

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,75 @@ top to bottom illustrated as following:
7676
| | | 11 | | 22 | -> the result we get
7777
```
7878

79-
## Instructsion sets
79+
## Instruction sets
80+
81+
### Memory and Stack Operations
8082

8183
| opcode | format | ARM instructions | comments |
8284
|-----------|-------------------|-------------------------------|------------------------------------------------------------------|
8385
|LEA | LEA \<offset\> |add r0, r11, #\<offset> |fetch arguments inside sub function |
8486
|IMM | IMM \<num\> |mov r0, #20 |put immediate \<num\> into general register |
85-
|JMP | JMP \<addr\> |b \<addr\> |set PC register to \<addr\> |
86-
|JSR | JSR \<addr\> |bl \<addr\> |stores current execution position and jump to \<addr\> |
87-
|LEV | LEV |add sp, r11, #0; pop {r11, pc} |fetch bookkeeping info to resume previous execution |
88-
|ENT | ENT \<size\> |push {r11, lr} ;add r11, sp, #0|called when we are about to enter the function call to "make a new calling frame".It will store the current PC value onto the stack, and save \<size\> bytes to store the local variable for function.|
89-
|ADJ | ADJ \<size\> |add sp, sp, #\<size\> |adjust the stack(to remove argument from frame) |
9087
|LI | LI |ldr r0, [r0] |loads an integer into general register from a given memory address which is stored in general register before execution|
9188
|SI | SI |pop {r1};str r0, [r1] |stores the integer in general register into the memory whose address is stored on the top of the stack|
9289
|LC | LC |ldrb r0, [r0] |loads an character into general register from a given memory address which is stored in general register before execution|
9390
|SC | SC |pop {r1}; strb r0, [r1] |stores the character in general register into the memory whose address is stored on the top of the stack|
9491
|PSH | PSH |push {r0} |pushes the value in general register onto the stack |
9592

93+
### Control Flow Operations
94+
95+
| opcode | format | ARM instructions | comments |
96+
|-----------|-------------------|-------------------------------|------------------------------------------------------------------|
97+
|JMP | JMP \<addr\> |b \<addr\> |set PC register to \<addr\> |
98+
|JSR | JSR \<addr\> |bl \<addr\> |stores current execution position and jump to \<addr\> |
99+
|BZ | BZ \<addr\> |cmp r0, #0; beq \<addr\> |branch on zero (conditional jump if general register is zero) |
100+
|BNZ | BNZ \<addr\> |cmp r0, #0; bne \<addr\> |branch on not zero (conditional jump if general register is not zero)|
101+
102+
### Function Call Operations
103+
104+
| opcode | format | ARM instructions | comments |
105+
|-----------|-------------------|-------------------------------|------------------------------------------------------------------|
106+
|ENT | ENT \<size\> |push {r11, lr} ;add r11, sp, #0|called when we are about to enter the function call to "make a new calling frame".It will store the current PC value onto the stack, and save \<size\> bytes to store the local variable for function.|
107+
|ADJ | ADJ \<size\> |add sp, sp, #\<size\> |adjust the stack(to remove argument from frame) |
108+
|LEV | LEV |add sp, r11, #0; pop {r11, pc} |fetch bookkeeping info to resume previous execution |
109+
110+
### Arithmetic Operations
111+
112+
| opcode | format | ARM instructions | comments |
113+
|-----------|-------------------|-------------------------------|------------------------------------------------------------------|
114+
|ADD | ADD |pop {r1}; add r0, r1, r0 |addition: r0 = stack_top + r0 |
115+
|SUB | SUB |pop {r1}; sub r0, r1, r0 |subtraction: r0 = stack_top - r0 |
116+
|MUL | MUL |pop {r1}; mul r0, r1, r0 |multiplication: r0 = stack_top * r0 |
117+
|DIV | DIV |pop {r1}; udiv r0, r1, r0 |division: r0 = stack_top / r0 |
118+
|MOD | MOD |pop {r1}; udiv r2, r1, r0; mul r2, r2, r0; sub r0, r1, r2|modulo: r0 = stack_top % r0|
119+
120+
### Bitwise Operations
121+
122+
| opcode | format | ARM instructions | comments |
123+
|-----------|-------------------|-------------------------------|------------------------------------------------------------------|
124+
|OR | OR |pop {r1}; orr r0, r1, r0 |bitwise OR: r0 = stack_top \| r0 |
125+
|XOR | XOR |pop {r1}; eor r0, r1, r0 |bitwise XOR: r0 = stack_top ^ r0 |
126+
|AND | AND |pop {r1}; and r0, r1, r0 |bitwise AND: r0 = stack_top & r0 |
127+
|SHL | SHL |pop {r1}; lsl r0, r1, r0 |shift left: r0 = stack_top << r0 |
128+
|SHR | SHR |pop {r1}; lsr r0, r1, r0 |shift right: r0 = stack_top >> r0 |
129+
130+
### Comparison Operations
131+
132+
| opcode | format | ARM instructions | comments |
133+
|-----------|-------------------|-------------------------------|------------------------------------------------------------------|
134+
|EQ | EQ |pop {r1}; cmp r1, r0; moveq r0, #1; movne r0, #0|equal: r0 = (stack_top == r0) ? 1 : 0|
135+
|NE | NE |pop {r1}; cmp r1, r0; movne r0, #1; moveq r0, #0|not equal: r0 = (stack_top != r0) ? 1 : 0|
136+
|LT | LT |pop {r1}; cmp r1, r0; movlt r0, #1; movge r0, #0|less than: r0 = (stack_top < r0) ? 1 : 0|
137+
|GT | GT |pop {r1}; cmp r1, r0; movgt r0, #1; movle r0, #0|greater than: r0 = (stack_top > r0) ? 1 : 0|
138+
|LE | LE |pop {r1}; cmp r1, r0; movle r0, #1; movgt r0, #0|less or equal: r0 = (stack_top <= r0) ? 1 : 0|
139+
|GE | GE |pop {r1}; cmp r1, r0; movge r0, #1; movlt r0, #0|greater or equal: r0 = (stack_top >= r0) ? 1 : 0|
140+
141+
### System Operations
142+
143+
| opcode | format | ARM instructions | comments |
144+
|-----------|-------------------|-------------------------------|------------------------------------------------------------------|
145+
|SYSC | SYSC |(varies) |system call |
146+
|CLCA | CLCA |(cache clear) |clear cache, used by JIT compilation |
147+
96148
## Function call example
97149

98150
```c
@@ -178,7 +230,4 @@ cmp r0, 0
178230
beq 0xff4a31d4
179231
```
180232
181-
| opcode | format | ARM instructions | comments |
182-
| ------------ | ----------- | ---------------------------- | -------- |
183-
| BZ | BZ <value> |cmp r0, 0;beq \<address\> |branch on zero
184-
| BNZ | BNZ <value> |cmp r0, 0;bne \<address\> |branch on not zero
233+
**Note**: The BZ and BNZ instructions are now included in the main instruction set table above under "Control Flow Operations".

0 commit comments

Comments
 (0)