Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified createfs
100644 → 100755
Empty file.
Empty file modified elfconvert
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion syscalls/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CFLAGS += -Wall -nostdlib -ffreestanding
LDFLAGS += -nostdlib -ffreestanding
CC = gcc

ALL: cat grep hello ls pingpong counter shell sigtest testprint syserr
ALL: cat grep hello ls pingpong counter shell sigtest testprint syserr factorial

%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
Expand Down
44 changes: 44 additions & 0 deletions syscalls/ece391factorial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdint.h>

#include "ece391support.h"
#include "ece391syscall.h"

#define BUFSIZE 10

int main ()
{
uint8_t buf[BUFSIZE];
uint32_t cnt, i, num;

ece391_fdputs(1, (uint8_t*)"Enter number to calculate factorial of:\n");
if (-1 == (cnt = ece391_read(0, buf, BUFSIZE-1)) ) {
ece391_fdputs(1, (uint8_t*)"Can't read the number from keyboard.\n");
return 3;
}
buf[cnt] = '\0';

num = 0;
i = 0;
while (buf[i] >= '0' && buf[i] <= '9')
{
num *= 10;
num += (uint32_t)(buf[i] - '0');
i++;
}

cnt = 1;
while (num != 0)
{
cnt *= num;
num--;
}

uint8_t out[BUFSIZE];
ece391_itoa(cnt, out, 10);

ece391_fdputs(1, (uint8_t*)"Factorial: ");
ece391_fdputs(1, out);
ece391_fdputs(1, (uint8_t*)"\n");

return 0;
}
Binary file added syscalls/to_fsdir/factorial
Binary file not shown.