포인터변수를 이용한 연산
#include <stdio.h>

int main()
{

  int i=3, *ip=&i;    // 포인터변수ip에 변수i의 주소값을 넣음
  printf("%d\n", *ip);  // 포인터변수ip가 가리키는 변수값 출력 (3)
  i=*ip+25;        // 변수i에 포인터변수ip가 가리키는 변수값+25를 함(3+25)
  printf("%d\n", i);    // 출력결과 28
  return 0;
}




주소 값의 연산
#include <stdio.h>

int main()
{

  short snum=5, *sp=&snum;
  float fnum=2.3f, *fp=&fnum;

  printf("sp volue : %p\n", sp);        // sp가 가리키는 변수의 주소값
  printf("sp plus volue : %p\n", ++sp); // sp가 가리키는 변수의 주소값 증가
  printf("fp volue : %p\n", fp);        // fp가 가리키는 변수의 주소값
  printf("fp plus volue : %p\n", ++fp); // fp가 가리키는 변수의 주소값 증가
  return 0;
}


_M#]


텍스트 화일
#include <stdio.h>

int main()
{

  int score;

  char name[10];    // 10문자로 구성된 배열 변수
  FILE *fpin, *fpout;  // 파일 포인터 변수의 선언

  fpin=fopen ("text.in""r");  // text.in 파일 읽기
  fpout=fopen ("text.out""w");  // test.out 파일 쓰기(없으면 만듬)

  while(!feof (fpin))  // 파일의 끝(end-of-file)이 아니면 0반환
  {
    fscanf (fpin, "%s %d", name, &score);  // 파일로부터 읽기
    printf("%s\t%d\n", name, score);    // 화면에 출력
    fprintf(fpout, "%s\t%d\n", name, score);// 파일에 기록
  }
  fclose (fpin);
  fclose (fpout);
  return 0;
}
text.in 파일을 메모장으로 미리만들어 내용을 적어줌.




Source Insight는 컴파일러가 아닌 분석 프로그램이다. 사용법을 알아보자

Project 탭에서 New Project를 클릭하여 새로운 프로젝트를 만들어준다. 단축키(알트+쉬프트+N)
그러면 다음과 같은 화면창이 나타난다.

특별한건 없다. New project name에 자신이 원하는 이름을 아무거나 입력하면 된다. 필자는 atmegatest라 정함.
그리고 아래쪽에 폴더의 경로가 보일것이다. 위의 그림은 미리 정해진 기본 경로이며 이것은 옆에 브라우져를 클릭
하여 자신이 원하는 경로로 임의로 바꿀수 있다. 필자는 D:\ProjectA\source insight로 정함. OK 클릭.


새 프로젝트의 이름을 정하고 ok를 누르면 위의 화면이 나오는것을 알수있다. 여기에서는 자신이 보고싶은
파일의 경로를 찾아서 ok를 눌러주면 된다. 필자의 경우 D:\projectA 폴더의 main.c파일을 보기위함.


File Name 이란곳이 2곳이 보일것이다. 첫번째 맨위는 빠른 탐색창으로 보시는게 편할것이다. 저곳에 c: 치고 엔터를 치면 경로가 C드라이브로 바뀌는 것을 알수있다. 그리고 오른쪽의 File name에서 원하는 파일을 더블클릭하면
아래쪽의 Project Files라는 큰 네모창으로 이동하는 모습을 볼수 있다. 옆에 show부분을 체크해제하면 모든 파일을
볼수가 있다. 

(클릭하면 원본 사이즈로 볼수 있습니다.)
자신이 보고자하는 하당파일을 더블클릭해서 파일을 열어보면 오른쪽에 창이 뜨는 것을 볼수 있습니다.(main.c)
그것에서 저는 DDRC를 보기위해서 DDRC에 마우스 커서를 올려놓고 컨트롤+왼쪽 클릭을 해줬습니다. 그러면
가운데에 보이는 것처럼 Multiple Locations라는 창이 하나 뜰겁니다. 그곳에서 자신이 사용하는 칩의 헤더 파일을
찾아서 클릭후 select를 클릭해서 헤더파일을 띄워줍니다.

DDRF를 쫒아가 보자
#define DDRF      _SFR_MEM8(0x61) ↓↓
#define _SFR_MEM8(mem_addr) _MMIO_BYTE(mem_addr) ↓↓
#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr)) // uint8_t 캐스팅

DDRF=0xFF; ☜ _SFR_MEM8(0x61)=0xFF; ☜ _MMIO_BYTE(0x61)=0xFF; ☜ (*(volatile uint8_t *)(0x61))=0xFF;(최종형태)




#include <stdio.h>
// 함수의 이름도 주소값을 갖고 있다.
int main()
{
  int a=3;

  printf("printf adress : %08x\n", printf);  //printf함수주소값
  printf("main adress : %08x\n", main);    //main함수주소값
  printf("a adress : %08x\n"&a);      //변수a의 주소값

  return 0;
}


#include <stdio.h>

int main()
{
  int inum, *ip;
  short *sp;
  
  inum=0x0F5A0B43;
  ip=&inum;      // inum의 주소값을 넣음.(inum을 가리킨다. 0012FF7C)
  
  printf("inum: %x *ip : %p \n", inum, ip);
  sp=(short*)ip; //(casting) ip가 갖고있는 주소값을 넣음.(inum을 가리킨다. 0012FF7C)
  printf("sp : %p, *sp : %x\n"
sp*sp);
  // sp가 갖고있는 주소값출력, sp가 가리키고 있는 주소의 변수값을 출력
  sp++;          // sp가 inum의 세번째 바이트를 가리킨다.(0012FF7E)
  printf("sp :%p, *sp : %x\n", sp, *sp); 
  
  return 0;
}

 


little

endian

 

0012FF78

7CFF1200

ip

0012FF7C

430B5A0F

inum

0012FF80

7CFF1200

sp

 

메모리

(4byte)

 

Simbol Table

type

name

address

int

inum

0012FF7C

int*

ip

0012FF78

short*

sp

0012FF80

 *(에스테리스크)는 포인터형에서 사용될 경우는 가리키고있는 주소의 변수값을 가져오게된다.(inum값)
   붙이지 않을 경우는 가리키고있는 주소값을 가져오게 된다. (0012FF7C)

아 죽것다. ㅡ.ㅠ

int A = 0x12345678;

7

8

5

6

3

4

1

2

little indian

 

unsigned int A = 0x12345678;

unsigned short *SP = (short*)&A

unsigned char *CP = (char*)&A

 

printf(“%x\n”, *SP); 5678 출력

printf(“%x\n”, *CP); 78 출력

 

 

 

992

1000

CP

996

1000

SP

1000

7

8

5

6

3

4

1

2

A

 

add

 

ress

메모리(4byte) 





Float example.svg
n = (-1)^s \times
           (m2^{-23})\times
           2^{x - 127}

41c8 000016 = 0100 0001 1100 1000 0000 0000 0000 00002

then we break it down into three parts; sign bit, exponent and significand.

Sign bit: 0
Exponent: 1000 00112 = 8316 = 131
Significand: 100 1000 0000 0000 0000 00002 = 48000016

We then add the implicit 24th bit to the significand

Significand: 1100 1000 0000 0000 0000 00002 = C8000016

and decode the exponent value by subtracting 127

Raw exponent: 8316 = 131
Decoded exponent: 131 - 127 = 4

Each of the 24 bits of the significand, bit 23 to bit 0, represents a value, starting at 1 and halves for each bit, as follows

bit 23 = 1
bit 22 = 0.5
bit 21 = 0.25
bit 20 = 0.125
bit 19 = 0.0625
.
.
bit  0 = 0.00000011920928955078125

The significand in this example has three bits set, bit 23, bit 22 and bit 19. We can now decode the significand by adding the values represented by these bits.

Decoded significand: 1 + 0.5 + 0.0625 = 1.5625 = C80000/223

Then we need to multiply with the base, 2, to the power of the exponent to get the final result

1.5625 × 24 = 25

Thus

41c8 0000   = 25

+ Recent posts