Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • iocla/tema-1-2025
  • albert_mark.stan/tema-1-2025
2 results
Show changes
Commits on Source (4)
Showing
with 187 additions and 115 deletions
......@@ -2,11 +2,11 @@
## Assignment: Simple C-to-Assembly Compiler
**Deadline soft**: 4 aprilie 2025, 11:55PM
**Deadline soft**: 6 aprilie 2025, 11:55PM
**Deadline hard**: 9 aprilie 2025, 11:55PM
**Deadline hard**: 11 aprilie 2025, 11:55PM
**Responsabili**
**Authors**
* Robert Grancsa
* Adelina Alexe
......@@ -27,15 +27,13 @@ The translation should be as simple as possible while covering basic arithmetic
## Conventions and Guidelines
Because we want to prevent you from having to juggle with registers and allocate memory for vectors.
Because we want to prevent you from having to juggle with registers, we'll use some simple conventions.
- **Basic Register Mapping:**
- `A``eax`
- `B``ebx`
- `C``ecx`
- `D``edx`
- When
- **Data types**
- We'll assume all of the data types are **4 bytes**
- When you see a number, we will treat it as a int (4 bytes)
......@@ -105,9 +103,9 @@ Similar to MUL, DIV works with EAX as the primary operand, but it also considers
| **C Code** | **ASM Code** |
|------------ |---------------- |
| `a = a * 3;` | `MUL 3` |
| `b = b * c;` | `MOV eax, ebx` |
| | `MUL ecx` |
| | `MOV ebx, eax` |
| `b = b * c;` | `MOV eax, ebx` |
| | `MUL ecx` |
| | `MOV ebx, eax` |
| `a = a / 3;` | `MOV eax, a` |
| | `DIV 3` |
| | `MOV a, eax` |
......@@ -134,17 +132,14 @@ SHL (Shift left) and SHR (Shift right) are bitwise shift instructions.
- SHL: Moves bits to the left, filling the rightmost bits with zeros. Each shift effectively **multiplies** the value by 2.
- Example: `00001100` (`12` in decimal) shifted left by 1 becomes `00011000` (`24` in decimal).
- SHR: Moves bits to the right, filling the leftmost bits with zeros. Each shift effectively **divides** the value by 2.
- Example: `00001100` (`12` in decimal) shifted left by 1 becomes `00000110` (`6` in decimal).
| **C Code** | **ASM Code** |
|------------- |---------------- |
| `a = a << 1` | `SHL eax, 1` |
| `b = b >> 2` | `SHR ebx, 2` |
### Conditional Statements
#### CMP Instrunction
......@@ -235,7 +230,7 @@ Coding style can be run directly in the checker, by pressing `C`, or by using th
- \>= 5 of `WARNING` => -5 points
- \>= 1 of `ERROR` => -10 points
## Mentiuni
## Notes
- The implementation can be done in any file, and the executable must be named
`transpiler`, situated in the root of the folder, same as the initial makefile does
......
d = d * 8;
c = c * c;
c = c * a;
c = c * b;
b = b * 4;
d = d * 7;
c = c * 8;
c = c * a;
c = c * d;
b = b * 0;
b = b * 1;
b = b * c;
......
while (d == 85) {
c = c * 7;
a = a * 9
a = a * 9;
b = b >> 27;
d = d - 5;
}
......
......@@ -10,7 +10,7 @@ for (b = 0; b < 75; b = b + 1) {
d = 69;
}
for (b = 0; b <= 86; b = b + 1) {
a = a * 2
a = a * 2;
}
for (a = 0; a < 66; a = a + 1) {
b = b + 28;
......
d = 77;
b = 23;
a = 96;
a = 23;
c = 58;
MOV edx, 77
MOV ebx, 23
MOV eax, 96
MOV eax, 23
MOV ecx, 58
a = c;
d = d;
d = 59;
b = b;
c = b;
a = c;
b = 76;
b = 89;
MOV eax, ecx
MOV edx, edx
MOV edx, 59
MOV ebx, ebx
MOV ecx, ebx
MOV eax, ecx
MOV ebx, 76
MOV ebx, 89
d = d & 42;
b = b ^ 41;
a = a ^ 39;
AND edx, 42
XOR ebx, 41
XOR eax, 39
c = c & 73;
d = d & 45;
a = a & 6;
d = d & a;
a = a | 19;
b = b ^ a;
a = a & 44;
d = d ^ 89;
d = d & 20;
a = a & 41;
AND ecx, 73
AND edx, 45
AND eax, 6
AND edx, eax
OR eax, 19
XOR ebx, eax
AND eax, 44
XOR edx, 89
AND edx, 20
AND eax, 41
a = a + d;
c = c + 26;
b = b + b;
b = b + 63;
ADD eax, edx
ADD ecx, 26
ADD ebx, ebx
ADD ebx, 63
c = c + 65;
b = b + d;
b = b + 20;
d = d + a;
b = b + d;
d = d + 23;
c = c + b;
c = c + 52;
a = a + 83;
ADD ecx, 65
ADD ebx, edx
ADD ebx, 20
ADD edx, eax
ADD ebx, edx
ADD edx, 23
ADD ecx, ebx
ADD ecx, 52
ADD eax, 83
a = a - a;
d = d - b;
c = c - b;
a = a - 55;
b = b - 16;
SUB eax, eax
SUB edx, ebx
SUB ecx, ebx
SUB eax, 55
SUB ebx, 16
b = b - 55;
b = b - 22;
b = b - 70;
b = b - 90;
b = b - 50;
d = d - 82;
a = a - 67;
d = d - 83;
b = b - 28;
b = b - b;
SUB ebx, 55
SUB ebx, 22
SUB ebx, 70
SUB ebx, 90
SUB ebx, 50
SUB edx, 82
SUB eax, 67
SUB edx, 83
SUB ebx, 28
SUB ebx, ebx
c = c * 8;
c = c * 1;
c = c * 6;
MOV eax, edx
MUL 8
MOV edx, eax
MOV eax, ecx
MUL ecx
MOV ecx, eax
MOV eax, ecx
MUL ebx
MOV ecx, eax
b = b * 10;
b = b * 4;
b = b * 9;
c = c * c;
c = c * 6;
c = c * a;
c = c * 7;
b = b * 0;
MOV eax, ebx
MUL 4
MOV ebx, eax
MOV eax, edx
MUL 7
MOV edx, eax
MOV eax, ecx
MUL 8
MOV ecx, eax
MOV eax, ecx
MUL edx
MOV ecx, eax
MOV eax, ebx
MUL 0
MOV ebx, eax
MOV eax, ebx
MUL 1
MOV ebx, eax
MOV eax, ebx
MUL ecx
MOV ebx, eax
MOV eax, edx
MUL ebx
MOV edx, eax
MOV eax, ebx
MUL edx
MOV ebx, eax
d = d / d;
b = b / c;
d = d / b;
c = c / a;
MOV eax, ebx
DIV 8
MOV ebx, eax
MOV eax, ebx
DIV 4
MOV ebx, eax
Error
MOV eax, ecx
DIV 5
MOV ecx, eax
MOV eax, ecx
DIV ecx
MOV ecx, eax
d = d / b;
d = d / c;
c = c / 7;
d = d / d;
c = c / 5;
b = b / 5;
c = c / c;
d = d / 8;
d = d / 4;
MOV eax, ecx
DIV 2
MOV ecx, eax
MOV eax, ecx
DIV 9
MOV ecx, eax
MOV eax, ebx
DIV 8
MOV ebx, eax
MOV eax, ebx
DIV 6
MOV ebx, eax
MOV eax, ecx
DIV ebx
MOV ecx, eax
MOV eax, ecx
DIV ecx
MOV ecx, eax
MOV eax, ebx
DIV ebx
MOV ebx, eax
MOV eax, ebx
DIV 5
MOV ebx, eax
MOV eax, ebx
DIV 2
MOV ebx, eax
MOV eax, ecx
DIV ebx
MOV ecx, eax
a = a >> 23;
a = a << 28;
a = a >> 2;
a = a << 14;
d = d >> 14;
SHR edx, 20
SHR eax, 24
SHR ebx, 4
SHR ebx, 7
SHL edx, 2
b = b >> 1;
b = b >> 31;
c = c << 21;
d = d << 26;
a = a << 31;
a = a >> 10;
a = a >> 21;
d = d >> 3;
d = d << 19;
d = d >> 25;
SHR ecx, 17
SHR eax, 2
SHR ecx, 16
SHR edx, 11
SHR edx, 10
SHL eax, 0
SHL ebx, 29
SHL edx, 8
SHL ecx, 29
if (c >= 23)
if (d == 20)
if (a < 0)
if (b > 58)
if (d < 17)
CMP edx, 8
JL end_label
MOV eax, ebx
MUL edx
MOV ebx, eax
end_label:
CMP edx, 14
JNE end_label
OR ebx, ebx
MOV eax, edx
MUL ebx
MOV edx, eax
SHL edx, 1
SUB eax, eax
end_label:
CMP edx, 67
JG end_label
Error
end_label:
CMP eax, 96
JG end_label
SUB edx, ecx
end_label:
CMP edx, 82
JNE end_label
SUB eax, 10
SUB ebx, 72
end_label: