-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding inline exercises to lab/interactiune-c-assembly
Adding 1-inline-for, 2-inline-rotate and 3-inline-rtdscp and reordering the exercises accordingly. Signed-off-by: Andreia Ocanoaia <[email protected]>
- Loading branch information
1 parent
8068505
commit 75a7501
Showing
121 changed files
with
250 additions
and
41 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
laborator/content/interactiune-c-assembly/01-inline-for/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/inline_for.asm |
3 changes: 3 additions & 0 deletions
3
laborator/content/interactiune-c-assembly/01-inline-for/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PROGNAME := inline_for | ||
include ../../utils/Makefile.generic | ||
|
29 changes: 29 additions & 0 deletions
29
laborator/content/interactiune-c-assembly/01-inline-for/inline_for.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <stdio.h> | ||
|
||
#define NUM 100 | ||
|
||
int main(void) | ||
{ | ||
size_t n = NUM; | ||
size_t sum = 0; | ||
|
||
__asm__ ( | ||
"xor eax, eax\n\t" /* collect the sum in eax */ | ||
/* use ecx to go through items, start from n */ | ||
"mov ecx, %1\n" | ||
"add_to_sum:\n\t" | ||
"add eax, ecx\n\t" | ||
"loopnz add_to_sum\n\t" | ||
/* place sum in output register */ | ||
"mov %0, eax\n\t" | ||
: "=r" (sum) /* output variable */ | ||
: "r" (n) /* input variable */ | ||
: "eax", "ecx" | ||
); /* registers used in the assembly code */ | ||
|
||
printf("sum(%u): %u\n", n, sum); | ||
|
||
return 0; | ||
} |
1 change: 1 addition & 0 deletions
1
laborator/content/interactiune-c-assembly/02-inline-rotate/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/inline_rotate.asm |
3 changes: 3 additions & 0 deletions
3
laborator/content/interactiune-c-assembly/02-inline-rotate/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PROGNAME := inline_rotate | ||
include ../../utils/Makefile.generic | ||
|
34 changes: 34 additions & 0 deletions
34
laborator/content/interactiune-c-assembly/02-inline-rotate/inline_rotate.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <stdio.h> | ||
|
||
#define NUM 0x12345678 | ||
|
||
int main(void) | ||
{ | ||
size_t n = NUM; | ||
size_t rot_left = 0; | ||
size_t rot_right = 0; | ||
|
||
__asm__ ("" | ||
/* TODO: Use rol instruction to shift n by 8 bits left. | ||
* Place result in rot_left variable. | ||
*/ | ||
|
||
/* TODO: Use ror instruction to shift n by 8 bits right. | ||
* Place result in rot_right variable. | ||
*/ | ||
/* TODO: Declare output variables - preceded by ':'. */ | ||
/* TODO: Declare input variables - preceded by ':'. */ | ||
/* TODO: Declared used registers - preceded by ':'. */ | ||
); | ||
|
||
/* NOTE: Output variables are passed by address, input variables | ||
* are passed by value. | ||
*/ | ||
|
||
printf("init: 0x%08x, rot_left: 0x%08x, rot_right: 0x%08x\n", | ||
n, rot_left, rot_right); | ||
|
||
return 0; | ||
} |
1 change: 1 addition & 0 deletions
1
laborator/content/interactiune-c-assembly/03-inline-rdtscp/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/inline_cpuid.asm |
3 changes: 3 additions & 0 deletions
3
laborator/content/interactiune-c-assembly/03-inline-rdtscp/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PROGNAME := inline_rtdscp | ||
include ../../utils/Makefile.generic | ||
|
20 changes: 20 additions & 0 deletions
20
laborator/content/interactiune-c-assembly/03-inline-rdtscp/inline_rdtscp.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <stdio.h> | ||
|
||
int main(void) | ||
{ | ||
char rdtscp_str[13]; | ||
|
||
__asm__ ("" | ||
/* TODO: Make rdtscp call and copy string in rdtscp_str. | ||
* After rdtscp call result is placed in (EDX:EAX registers). | ||
*/ | ||
); | ||
|
||
rdtscp_str[12] = '\0'; | ||
|
||
printf("rdtscp string: %s\n", rdtscp_str); | ||
|
||
return 0; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
laborator/content/interactiune-c-assembly/solution/02-inline-rotate/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/inline_rotate.asm |
3 changes: 3 additions & 0 deletions
3
laborator/content/interactiune-c-assembly/solution/02-inline-rotate/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PROGNAME := inline_rotate | ||
include ../../../utils/Makefile.generic | ||
|
45 changes: 45 additions & 0 deletions
45
laborator/content/interactiune-c-assembly/solution/02-inline-rotate/inline_rotate.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <stdio.h> | ||
|
||
#define NUM 0x12345678 | ||
|
||
int main(void) | ||
{ | ||
size_t n = NUM; | ||
size_t rot_left = 0; | ||
size_t rot_right = 0; | ||
|
||
__asm__ ( | ||
/* Use rol instruction to shift n by 8 bits left. | ||
* Place result in rot_left variable. | ||
*/ | ||
"mov eax, %1\n\t" | ||
"rol %1, 8\n\t" | ||
"mov %0, eax\n\t" | ||
: "=r" (rot_left) | ||
: "r" (n) | ||
: "eax" | ||
); | ||
|
||
__asm__ ( | ||
/* Use ror instruction to shift n by 8 bits right. | ||
* Place result in rot_right variable. | ||
*/ | ||
"mov eax, %1\n\t" | ||
"ror eax, 8\n\t" | ||
"mov %0, eax\n\t" | ||
: "=r" (rot_right) | ||
: "r" (n) | ||
: "eax", "ecx" | ||
); | ||
|
||
|
||
/* NOTE: Output variables are passed by address, input variables | ||
* are passed by value. | ||
*/ | ||
printf("init: 0x%08x, rot_left: 0x%08x, rot_right: 0x%08x\n", | ||
n, rot_left, rot_right); | ||
|
||
return 0; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.