part1/part1.c
/* part1.c -- This is part 1 of lab 0, CSCI2467, Fall 2016 */
#include
#include "student.h"
int main () /* in this case we don't care about command line arguments */
{
/* create a struct of type student_info called student */
/* then call the make_student() function from student.c
* to fill it with information */
struct student_info student = make_student ();
/* Now start printing out what's stored in student.
* \n represents the newline character
* %d is for substituting integer values */
printf ("ID number: %d\n\n", student.id);
/* %s is for substituting a character array */
printf ("Name: %s\n\n", student.name);
/* we reference individual array elements with [0] [1] etc */
printf ("CS Courses taken: ");
for (int i=0;i<8;i++)
printf("CSCI%d , ",student.csci_classes[i]);
printf ("\n\n");
printf ("UNO Email id: %s\n\n",student.UNO_Email);
printf ("Number of Semesters I have previously Attended: %d\n\n",student.sem_Num);
printf ("What I want most out of this class?\n%s\n\n",student.objective);
printf ("My non-CS interest: %s\n\n",student.hobby);
printf ("Reason for studying Computer Science:\n%s\n\n", student.reason);
printf ("Anything Else about me:\n%s\n\n",student.anythingElse);
return 0; /* 0 is typically returned when no errors have occurred */
};
part1/makefile
part1: student.c part1.c
gcc -o part1 part1.c student.c
part1/student.h
/* student.h */
/* define a struct for storing student information */
struct student_info {
int id;
char name[80]; /* 80 characters should be more than enough to store a name, right? */
/* need more stuff here */
char UNO_Email[50];
int sem_Num;
char objective[200];
char hobby[50];
char anythingElse[200];
//NEW STUFF ENDS HERE
int csci_classes[20]; /* has anyone taken more than 20 CS classes? */
char reason[400]; /* This means my reason for studying CS must be
less than 400 characters, or I will have to
increase the array size. */
};
/* this is a function prototype, the function itself is in student.c */
struct student_info make_student(void);
part1/part1
part1/README
You can compile this program by running:
gcc part1.c student.c -o part1
part1/student.c
#include
#include "student.h"
struct student_info make_student(void){
struct student_info me;
me.id = 2481382;
strcpy(me.name, "Katelyn Reneé Nolan"); /* strcpy is necessary */
me.csci_classes[0]=1581; /* array indices always being with 0 */
me.csci_classes[1]=1583;
me.csci_classes[2]=2120;
me.csci_classes[3]=2121;
me.csci_classes[4]=2125;
me.csci_classes[5]=2450;
me.csci_classes[6]=2467;
me.csci_classes[7]=3301;
strcpy(me.UNO_Email,"[email protected]");
me.sem_Num=3;
strcpy(me.objective,"I want to learn how to c programming properly");
strcpy(me.hobby,"Reading Book");
strcpy(me.anythingElse,"I Also have cerebral palsy");
strcpy(me.reason, "I always love working on computers");
return me;
}
part2/hello
part2/hello-bits
00000000: 00100011 01101001 01101110 01100011 01101100 01110101 #inclu
00000006: 01100100 01100101 00100000 00111100 01110011 01110100 de 0000000c: 01100100 01101001 01101111 00101110 01101000 00111110 dio.h>
00000012: 00001010 00100011 01100100 01100101 01100110 01101001 .#defi
00000018: 01101110 01100101 00100000 01010010 01000101 01010100 ne RET
0000001e: 01010101 01010010 01001110 01010110 01000001 01001100 URNVAL
00000024: 01010101 01000101 00100000 00110110 00110111 00001010 UE 67.
0000002a: 00001010 01101001 01101110 01110100 00100000 01101101 .int m
00000030: 01100001 01101001 01101110 00101000 00101001 00001010 ain().
00000036: 01111011 00001010 00100000 00100000 00100000 00100000 {.
0000003c: 01101001 01101110 01110100 00100000 01110010 01100101 int re
00000042: 01110100 01110110 01100001 01101100 00100000 00111101 tval =
00000048: 00100000 01010010 01000101 01010100 01010101 01010010 RETUR
0000004e: 01001110 01010110 01000001 01001100 01010101 01000101 NVALUE
00000054: 00111011 00001010 00001010 00100000 00100000 00100000 ;..
0000005a: 00100000 01110000 01110010 01101001 01101110 01110100 print
00000060: 01100110 00101000 00100010 01001000 01100101 01101100 f("Hel
00000066: 01101100 01101111 00100000 01110111 01101111 01110010 lo wor
0000006c: 01101100 01100100 00101110 01011100 01101110 00100010 ld.\n"
00000072: 00101001 00111011 00001010 00001010 00100000 00100000 );..
00000078: 00100000 00100000 01110010 01100101 01110100 01110101 retu
0000007e: 01110010 01101110 00100000 01110010 01100101 01110100 rn ret
00000084: 01110110 01100001 01101100 00111011 00001010 01111101 val;.}
0000008a: 00001010 .
part2/answers2.txt
In the hello.i file, the cpp compiler has imported the code from all the file included using #include commands.
It is in this phase that the checking is done to ensure all included files do exist and are available for reading. Also if any of the included file has any error it is caught in this stage.
This is a type of interpreter stage where all imported file's code is checked for errors before the actual program code is compiled.
part2/hello.s
.file "hello.c"
.text
.section .rodata
.LC0:
.string "Hello world."
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
#space is allocated for retval
.cfi_def_cfa_register 6
subq $16, %rsp
#value is placed in retval
movl $67, -4(%rbp)
leaq .LC0(%rip), %rdi
#Printf is called here
call puts@PLT
movl -4(%rbp), %eax
leave
.cfi_def_cfa 7, 8
#Program returns on this command
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Debian 10.2.1-6) 10.2.1 20210110"
.section .note.GNU-stack,"",@progbits
part2/hello-xxd
00000000: 2369 6e63 6c75 6465 203c 7374 6469 6f2e #include 00000010: 683e 0a23 6465 6669 6e65 2052 4554 5552 h>.#define RETUR
00000020: 4e56 414c 5545 2036 370a 0a69 6e74 206d NVALUE 67..int m
00000030: 6169 6e28 290a 7b0a 2020 2020 696e 7420 ain().{. int
00000040: 7265 7476 616c 203d 2052 4554 5552 4e56 retval = RETURNV
00000050: 414c 5545 3b0a 0a20 2020 2070 7269 6e74 ALUE;.. print
00000060: 6628 2248 656c 6c6f 2077 6f72 6c64 2e5c f("Hello world.\
00000070: 6e22 293b 0a0a 2020 2020 7265 7475 726e n");.. return
00000080: 2072 6574 7661 6c3b 0a7d 0a retval;.}.
part2/hello.c
#include
#define RETURNVALUE 67
int main()
{
int retval = RETURNVALUE;
printf("Hello world.\n");
return retval;
}
part2/hello-att.s
.file "hello.c"
.text
.section .rodata
.LC0:
.string "Hello world."
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl $67, -4(%rbp)
leaq .LC0(%rip), %rdi
call puts@PLT
movl -4(%rbp), %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Debian 10.2.1-6) 10.2.1 20210110"
.section .note.GNU-stack,"",@progbits
part2/hello.i
# 1 "hello.c"
# 1 ""
# 1 ""
# 31 ""
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "" 2
# 1 "hello.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 27 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 1 3 4
# 33 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 461 "/usr/include/features.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 1 3 4
# 452 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4
# 453...