본문으로 바로가기

어셈블리 프로그래밍 심화4

category Pwnable 2018. 7. 27. 15:30

반복문 : for, while


- while 반복문


1
2
3
4
5
6
7
8
9
10
int cnt = 10;
 
int main()
{
    while( cnt > 0 ) {
        printf("%d\n", cnt);
        cnt--;
    }
    return 0;
}
cs


- for 반복문


1
2
3
4
5
6
7
8
9
10
int cnt = 10;
 
int main()
{
    for( ; cnt > 0; cnt --){
        printf("%d\n", cnt);
        cnt--;
    }
    return 0;
}
cs


for, while 반목문은 거의 동일하게 표현된다는것을 알 수 있다.


어셈블리로 표현하면 아래와 같이 표현할 수 있다.





EX) 문자열을 압력받아서 거꾸로 표현하는 어셈블리 프로그램을 작성하시오



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
 
char buffer[1024];
int end = 0;
 
int main()
{
    printf("input: ");
    gets(buffer);
 
    while ( buffer[end!= NULL )
        end++;
    end--;
 
    whileend >= 0 ){
        printf("%c", buffer[end]);
        end--;
    }
 
    printf("\n");
    return 0;
}
cs



어셈블리로 표현하면 아래와 같이 나타낼 수 있다.