Skip to content
Snippets Groups Projects
Commit 5725a4ff authored by 이소현's avatar 이소현
Browse files

Update README.md

parent a01acf80
Branches
No related tags found
No related merge requests found
......@@ -371,3 +371,100 @@ int count_one(unsigned int a)
```
## lesson08
1. 컴파일과 실행시 순서
> 1. compile : compile 명령
> 2. 모든 #으로 이루어진 것들이 숫자로 바뀜 (#define)
> 3. link assembler : scanf, printf 등과 연결 (내가 쓴 함수들과 붙여줌) 후 실행파일 생성
>> * link 에는 dynamic 과 static이 있다.
> 4. loader
2. #if, #ifdef, #ifndef, #elif, #else, #endif
> * cpp 실행시 실행되는 것이다.
> * #if로 시작시 #endif로 끝나야 한다.
> * #ifdef 로 시작시 #endif로 끝나야 한다.
3. #s 사용시 string 으로 만들어 준다.
> * ex) #define str(s) #s 이고 str(p="foo\n";) 일때 #s 로 인해 "p=\"foo\\n\";" 로 자동으로 바꾸어 준다.
4. Concatenation
> * 파라메터가 여러번 쓰이고 싶을 때나 ##을 사용하여 띄어쓰기 하고 싶지 않을 때 사용한다.
5. optimization을 하다보면 코드 크기가 커진다.
6. #define
> * 함수가 호출될 때에는 memory에 stack을 만든다. 따라서 그냥 함수보다는 그냥 코드에 쓰는 것이 성능이 더 좋지만 함수를 여러번 많이 호출하는 상황이 온다면 긴 코드를 여러번 실행하는 것 보다는 함수를 쓰는 것이 더 이득이다.
> * 위에서 말한듯이 함수를 호출할 때 성능이 더 좋을 때도 있고 안 좋을 때도 있지만 #define을 사용하면 언제나 성능이 제일 좋다.
7. gcc 컴파일 옵션
> 1. -c : .o file로 생성해준다.
> 2. -g : 디버깅을 하기 위한 옵션
> 3. -pg : 프로파일을 하기 위한 옵션
> 4. -O : 최적화 옵션, 있어도 쓰이지 않는 코드 등을 삭제시켜준다.
8. -o 컴파일 옵션 순서
> 1. cc -c : .o file을 먼저 생성해야 한다.
> 2. cc -S : 어셈블리파일을 생성한다.
> 3. cc -o
9. _ _LINE_ _ & #if 사용 코드
```c
#include <stdio.h>
int add(int *a, int *b, int *c)
{
*c = *a + *b;
}
int main()
{
int a = 100;
int b = 200;
int c = 999;
// int * == long long
fprintf(stdout, "%d : %lld %llx\n", a,(long long) &a,(long long) &a);
fprintf(stdout, "%d : %lld %llx\n", b, (long long)&b, (long long)&b);
add(&a, &b ,&c);
//c = a+b
fprintf(stdout, "%s %d : %d\n",__FILE__, __LINE__,c);
fprintf(stdout, "%s %d : %d\n",__FILE__, __LINE__,c);
fprintf(stdout, "%s %d : %d\n",__FILE__, __LINE__,c);
#define ERR_DATA 2000
#if ERR_DATA > 1000
#error 1024
#else
#warning ERR_DATA
#endif
fprintf(stdout, "%s %d : %d",__FILE__, __LINE__,c);
}
```
10. 프로젝트 관련 설명
* 과제 목표 : 임베디드 시스템을 위한 고정소수점 수학 라이브러리 개발
> * 고정소수점의 반대어 : 부동소수점(floating point)
> 1. 부동 소수점 :
>> * [signed bit][exponent].[mantissa] 로 이루어짐
>> * 계산은 (-2S+1)*1.m*2^(e-127) 로 한다.
> 2. 고정 소수점 :
>> * 맨 앞의 수는 signed bit 이다.
>> * .의 위치를 Q_NUM 으로 define
>> * (ex) a(10) = 2342000 일때 23420.00 의 위치에 점이 찍히면 ar = a(10) * 10^(-2) 이다.
* 고정 소수점 코드
```c
#include <stdio.h>
#include <math.h>
#define FX_Q_NUM 16
int main()
{
int ia;
float fa;
fscanf(stdin, "%d", &ia);
fprintf(stdout, "%d : %f %f\n", ia, (float)ia, (float)ia*powf(2.0f, -16));
fscanf(stdin, "%f", &fa);
fprintf(stdout, "%f : %d %d\n, fa, (int)fa, (int)(fa*powf(2.0f,16)));
}
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment