From 649e5d53238c5a7cbb672a048e9e58490c1f1015 Mon Sep 17 00:00:00 2001 From: Srujun Thanmay Gupta Date: Thu, 24 Nov 2016 15:25:20 -0600 Subject: [PATCH] Fixed executable permissions and added sample program This is to test how createfs and elfconvert work. --- createfs | Bin elfconvert | Bin syscalls/Makefile | 2 +- syscalls/ece391factorial.c | 44 ++++++++++++++++++++++++++++++++++++ syscalls/to_fsdir/factorial | Bin 0 -> 5509 bytes 5 files changed, 45 insertions(+), 1 deletion(-) mode change 100644 => 100755 createfs mode change 100644 => 100755 elfconvert create mode 100644 syscalls/ece391factorial.c create mode 100755 syscalls/to_fsdir/factorial diff --git a/createfs b/createfs old mode 100644 new mode 100755 diff --git a/elfconvert b/elfconvert old mode 100644 new mode 100755 diff --git a/syscalls/Makefile b/syscalls/Makefile index e59b153..7bc758c 100644 --- a/syscalls/Makefile +++ b/syscalls/Makefile @@ -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 $@ $< diff --git a/syscalls/ece391factorial.c b/syscalls/ece391factorial.c new file mode 100644 index 0000000..a4cadfe --- /dev/null +++ b/syscalls/ece391factorial.c @@ -0,0 +1,44 @@ +#include + +#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; +} diff --git a/syscalls/to_fsdir/factorial b/syscalls/to_fsdir/factorial new file mode 100755 index 0000000000000000000000000000000000000000..3fff04cde64de2be694e025dbec65bd6aa4d0e42 GIT binary patch literal 5509 zcmeHGU279T6rF9hx-G%vMG)-63eoCIZ8h2te6h{cuYR{ts}`HKDO#HZ!)`?|v^W*A zEQP-G5BLXs3qb_aRvL;5ts?Y6M8uXzf}1b9_s*GfXJ%`Lh=Q9>zkKhi9Mj#$Da7Z1=OAH<_R31;yv#)4T`8Wo}jxlJatpX#uBfz3SJL zjpdJ3+y<9YsHW0_D*-%LBITeO%QOPUXo0ivGskC~zyG(+ET?H6b!PWLeb*DJp`eh) zv6x2W915?6=mLF@!hxdjo=g~&CELs7-h(P7nzi)_fRa6Byj}odTc};7TkM5*cw`}< zuP!bw4kl5Edcz~AT^^@8GG_;9u8y`48)u zJER3*DpY4Nfye_OYK=6)o29rla2@tcb6LOYhaKq3=2LX{`!{97yce1)F^6|tS%LE( zcbk`@jEHr0B0mR0sT_ERy@#?Y&6OO4zL{4Ll|Z}^yk!~A6s40{uPLyQZ377oY#Fpd zS5_Q;m^Bk1@v7qAI5ZxvS_m7jw^HrFt70xJzrIRnSPDkPupAnLNs5T$f$4F1Iv@qb z$-uZ2iQW!Oi;>ATJZ_{T5U!WRXfQA#O1FYm(quFe67K}>k3|B}iH2IzY2~$v#7x6f z`>`Fc9k3m+9k3m+9k3m+9k3m+9k3m+9k3m+9r%wNXly!h(tGN3b4%;l_6{HIJa_)W X#Y