Compare commits
3 Commits
3cb5ff77cc
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 22d1e5a740 | |||
| b92350f86d | |||
| e71a6ee3ee |
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,7 @@ int main(void) {
|
|||||||
|
|
||||||
printf("DIAL starts at %d\n", dial);
|
printf("DIAL starts at %d\n", dial);
|
||||||
|
|
||||||
while (fscanf(fptr, "%s %d", direction, &rotation) == 2) {
|
while (fscanf(fptr, "%1s%d", direction, &rotation) == 2) {
|
||||||
printf("DIRECTION %s ROTATION %d\n", direction, rotation);
|
printf("DIRECTION %s ROTATION %d\n", direction, rotation);
|
||||||
|
|
||||||
if (strcmp(direction, "L") == 0) {
|
if (strcmp(direction, "L") == 0) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
.p2align 4
|
.p2align 4
|
||||||
|
|
||||||
count:
|
count:
|
||||||
cmp w1, #0
|
cmp w1, wzr
|
||||||
b.eq count1
|
b.eq count1
|
||||||
b finish
|
b finish
|
||||||
count1:
|
count1:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ right1:
|
|||||||
b.eq finish
|
b.eq finish
|
||||||
b right
|
b right
|
||||||
loop0:
|
loop0:
|
||||||
mov w0, #0
|
mov w0, wzr
|
||||||
b right1
|
b right1
|
||||||
finish:
|
finish:
|
||||||
ret
|
ret
|
||||||
|
|||||||
2
aoc_25_1_2/Makefile
Normal file
2
aoc_25_1_2/Makefile
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
build:
|
||||||
|
gcc -g src/aoc25.c src/*.s -o out_a64
|
||||||
4136
aoc_25_1_2/aoc25_1_2.txt
Normal file
4136
aoc_25_1_2/aoc25_1_2.txt
Normal file
File diff suppressed because it is too large
Load Diff
40
aoc_25_1_2/src/aoc25.c
Normal file
40
aoc_25_1_2/src/aoc25.c
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
extern int left(unsigned long* drp);
|
||||||
|
extern int right(unsigned long* drp);
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
char direction[2];
|
||||||
|
unsigned long drp[] = {50, 0, 0}; /* dial - rotation - password */
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
FILE *fptr = fopen("aoc25_1_2.txt", "r");
|
||||||
|
|
||||||
|
if (fptr == NULL) {
|
||||||
|
printf("Error, puzzle input aoc25_1_2.txt not found\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("DIAL starts at %d\n", drp[0]);
|
||||||
|
|
||||||
|
while (fscanf(fptr, "%1s%d", direction, &drp[1]) == 2) {
|
||||||
|
printf("DIRECTION %s ROTATION %d\n", direction, drp[1]);
|
||||||
|
|
||||||
|
if (strcmp(direction, "L") == 0) {
|
||||||
|
retval = left(drp);
|
||||||
|
printf("DIAL is now %ld\n", drp[0]);
|
||||||
|
printf("PASSWORD is now %ld\n", drp[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(direction, "R") == 0) {
|
||||||
|
retval = right(drp);
|
||||||
|
printf("DIAL is now %ld\n", drp[0]);
|
||||||
|
printf("PASSWORD is now %ld\n", drp[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fptr);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
29
aoc_25_1_2/src/left.s
Normal file
29
aoc_25_1_2/src/left.s
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
.global left
|
||||||
|
.type left, "function"
|
||||||
|
.p2align 4
|
||||||
|
|
||||||
|
left:
|
||||||
|
ldr x1, [x0]
|
||||||
|
ldr x2, [x0, #8]
|
||||||
|
ldr x3, [x0, #16]
|
||||||
|
b left1
|
||||||
|
left1:
|
||||||
|
subs x1, x1, #1
|
||||||
|
b.eq pass0
|
||||||
|
b.lt loop99
|
||||||
|
b rotate
|
||||||
|
pass0:
|
||||||
|
add x3, x3, #1
|
||||||
|
b rotate
|
||||||
|
loop99:
|
||||||
|
mov x1, #99
|
||||||
|
b rotate
|
||||||
|
rotate:
|
||||||
|
subs x2, x2, #1
|
||||||
|
b.eq finish
|
||||||
|
b left1
|
||||||
|
finish:
|
||||||
|
str x1, [x0]
|
||||||
|
str x3, [x0, #16]
|
||||||
|
mov x0, xzr
|
||||||
|
ret
|
||||||
27
aoc_25_1_2/src/right.s
Normal file
27
aoc_25_1_2/src/right.s
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
.global right
|
||||||
|
.type right, "function"
|
||||||
|
.p2align 4
|
||||||
|
|
||||||
|
right:
|
||||||
|
ldr x1, [x0]
|
||||||
|
ldr x2, [x0, #8]
|
||||||
|
ldr x3, [x0, #16]
|
||||||
|
b right1
|
||||||
|
right1:
|
||||||
|
adds x1, x1, #1
|
||||||
|
cmp x1, #99
|
||||||
|
b.gt loop0
|
||||||
|
b rotate
|
||||||
|
loop0:
|
||||||
|
mov x1, xzr
|
||||||
|
add x3, x3, #1
|
||||||
|
b rotate
|
||||||
|
rotate:
|
||||||
|
subs x2, x2, #1
|
||||||
|
b.eq finish
|
||||||
|
b right1
|
||||||
|
finish:
|
||||||
|
str x1, [x0]
|
||||||
|
str x3, [x0, #16]
|
||||||
|
mov x0, xzr
|
||||||
|
ret
|
||||||
Reference in New Issue
Block a user