Monday, August 31, 2020

command for using "help50" to help you debug errors

help50 make buggy1

cs50, lec2


linking - combining 0s and 1s from our source code and the various libraries

links the various 0s and 1s into an overall program in machine code


assembling - taking assembly code and converting to 0s and 1s

this portion is also done by the clang compiler


compiling - although this is often used as a generalized and simplified term, it actually has a more precise definition

compiling is taking your source code (after being pre-processed) and converting it into assembly code


for example:


...
main:                                                 # @main
        .cfi_startproc
#   BB#0:
        pushq      %rbp
.Ltmp0:
        .cfi_def_cfa_offset  16
.Ltmp1:
        .cfi_offset  %rbp,  -16
        movq    %rsp, %rbp
Ltmp2:
        .cfi_def_cfa_register   %rbp
        subq      $16, %rsp
        xor1      %eax, %eax
        mov1     %eax, %edi
        movabsq        $.L.str, %rsi
        movb      $0, %al
        callq       get_string
        movabsq        $.L.str, %rdi
        movq       %rax, -8(%rbp)
        movq        -8(%rbp), %rsi
        movb       %0, %al
        callq            printf
        ...





cs50, lec2


pre-processing

in this step, the pre-processor goes through your code, and copy pastes relevant code from .h header files into your code

for example:


#include <cs50.h>
#include <stdio.h>

int main(void)
{
string s = get_string("what is your name\n");
printf("hello, %s\n", s);
}


becomes

....
string get_string(string prompt);
void printf(string format, .....);
....

int main(void)
{
string s = get_string("what is your name\n");
printf("hello, %s\n", s);
}

.................the actual code pasted in is simplified here, but this is enough to illustrate the concept......





cs50, lec2






The term "compile" is often used as an "over-simplification" of 4 actions:

pre-processing
compiling
assembling
linking

.......these 4 steps are invoked when we run clang or make


cs50, lec2


get a string and print a string (lec2 reviewing lec1)

#include <cs50.h>
#include <stdio.h>

int main(void)
{
string s = get_string("what is your name?\n");
printf("hi, %s\n", s);
}


cs50, lec2 (reviewing lec1)


stdio.h ....... manifestation of a library, a header file

cs50, lec2