과제 슬라이드(new) - Memory & Storage Architecture Lab.

Download Report

Transcript 과제 슬라이드(new) - Memory & Storage Architecture Lab.

Seoul National University
IA32 Assembly Programming Assignment
AnSu Na ([email protected])
Memory & Storage Architecture Lab.
School of Computer Science and Engineering
Seoul National University
1
Seoul National University
목차

Introduction

Assignment program

Grading criteria

Example codes

Development environment & tolls

Submission
2
Seoul National University
Assembly Language
text
C program (p1.c p2.c)
Compiler (gcc -S)
text
Asm program (p1.s p2.s)
Assembly language
Assembler (gcc or as)
binary
Object program (p1.o p2.o)
Linker (gcc or ld)
binary
Static libraries
(.a)
Executable program (p)
3
Seoul National University
IA32 Assembly Language



Intel Architecture 32bit
CISC
From intel 80386 microprocessor
4
Seoul National University
Assignment


과제 목적
 Assembly Programing을 경험
과제 내용
 n-queen problem을 해결하는 프로그램 구현
 IA32 assembly language 사용
 File I/O 구현

System call
5
Seoul National University
N-Queen Problem

n행 n열의 체스 보드에 n개의 퀸을 다음과 같은
규칙을 따라 배치하는 문제
1) 어떠한 서로 다른 두 퀸도 같은 나라에
속하지 않음
2) 어떠한 서로 다른 두 퀸도 서로 공격할 수
없어야 함
6
Seoul National University
N-Queen Problem

n행 n열의 체스 보드에 n개의 퀸을 다음과 같은
규칙을 따라 배치하는 문제
1) 어떠한 서로 다른 두 퀸도 같은 나라에
속하지 않음
2) 어떠한 서로 다른 두 퀸도 서로 공격할 수
없어야 함
7
Seoul National University
DFS


Depth-first search
Algorithm for traversing or searching tree or graph
8
Seoul National University
Assignment Program


주어진 n에 대한 n-queen problem의 모든 해를 찾고 퀸의 배치와
해의 개수를 출력
입출력 ㅡ File I/O 로 구현
 입력 : input.txt
 출력 : output.txt
 Input.txt와 output.txt는 모두 프로그램과 같은 디렉토리에 존재
9
Seoul National University
Input Format

input.txt

첫 번째 줄 : n의 개수

나머지 줄 : n의 값
 Line-by-line
2
2
8
# n의 값이 2개 주어짐
#n=2
#n=8
input.txt의 예
k
n1
n2
…
nk-1
nk
# n의 값이 k개 주어짐
# n = n1
# n = n2
# n = nk-1
# n = nk
input.txt의 일반적 표현
10
Seoul National University
Output Format

output.txt

첫 번째 줄 : n의 개수

나머지 줄 : n-queen problem의 해
 주어진 모든 n에 대해 다음 값을 반복 출력


1) n의 값
2) 가능한 모든 퀸의 배치
– 빈칸 : ‘-’
– 퀸 : ‘q’
– 각 배치는 빈 줄로 구분

3) 해의 개수
number_of_n = 2
=======================
n=2
number_of_solutions = 0
=======================
n=8
---q---------q-------q
-q---------q--q-----------q-# 빈 줄로 구분
---q---. . ..
. . ..
#총 92개 표시
number_of_solutions = 92
=======================
ouput.txt의 예
11
Seoul National University
Grading Criteria
항목
점수
main
10점
main함수를 구현
Result
40점
주어진 n에 대해 바른 해를 출력
Input Output Format
10점
입출력 형식을 따라 주어진 모든 n에 대해 해
를 구함
File I/O
20점
input.txt에 저장된 값을 읽어 output.txt에 처
리된 값을 출력
20점
알고리즘 및 설계과정 (5점)
구현 및 시현 (7점)
File I/O (3점)
어려웠던 점 / 해결 방법 / 느낀 점 (5점)
Report



기준
100점 만점
각 항목의 점수는 독립적으로 주어짐
보고서를 제외한 항목은 컴파일 및 실행이 되지 않을 시 0점
12
Seoul National University
Putty

Telnet program


Host : martini.snu.ac.kr
Port : 22
Connection Type : SSH

Download

 http://www.chiark.greenend.org.uk/~sgtath
am/putty/download.html
13
Seoul National University
Putty - Login

ID & pass word
 타과 학생들은 홈페이지에
올린 ID와 암호 확인
14
Seoul National University
vi/vim – Text Editor #1


Visual display editor
2가지 모드
 입력 모드
 명령 모드
시작할 때 기본 모드
 모드 전환 (Common case)
 명령모드 : ‘i’ 혹은 ‘insert’키로 입력모드 전환
 입력모드 : ‘ESC’키로 명령모드 전환

15
Seoul National University
vi/vim – Text Editor #2

기본적인 명령
 저장
명령모드에서 ‘:w’ 입력
 나가기
 명령모드에서 ‘:q’ 입력
 저장하고 나가기
 명령모드에서 ‘:wq’입력
 저장하지 않고 나가기
 명령모드에서 ‘!q’입력


Reference
 http://wiki.kldp.org/KoreanDoc/html/Vim_Guide-KLDP/Vim_GuideKLDP.html
16
Seoul National University
Compile, Assemble, and Link

Compile
 Assembly 파일 형성
 ex ) $ gcc –S filename.c
=> filename.s

Assemble & Link
 Executable 파일 형성
 ex1 ) $ gcc filename.s
=> a.out
 ex2 ) $ gcc –o newname filename.s
=> newname
17
Seoul National University
System call - printf


줄 바꿈 없는 stdout 출력
Stack을 통해 String이 있는
주소를 넘겨 받아 해당
String을 출력한 후 리턴
18
Seoul National University
System call - puts


줄 바꿈 있는 stdout 출력
Stack을 통해 String이 있는
주소를 넘겨 받아 해당
String을 출력한 후 줄
바꿈을 출력하고 리턴
19
Seoul National University
System call - getf


$ gcc –O1 –S getf.c

stdin 입력
%ebx에 저장되어 있는
pstr의 시작 주소를 스택을
통해 넘겨 받음
리턴 값
 해당 시작 주소를 반환
정상 동작
 Null (0x0)
 입력 끝이거나 오류 발생

20
Seoul National University
Debugging

Tool
 gdb

gdb 실행
 gdb [프로그램명]
 주의 : -g 옵션 사용하여 컴파일 해야 디버깅 가능
 ex) $ gcc –g –o main main.c
$ gdb main
21
Seoul National University
Debugging

기본적인 명령어
 디버깅할 프로그램 실행
(gdb) run
gdb 종료
 (gdb) q
정보보기
 (gdb) info
레지스터 값 모두 보기
 (gdb) info registers
브레이크 포인트 잡기
 (gdb) break [line number]
레지스터 하나만 보기
 (gdb) info register [register name]eax
 ex ) (gdb) info register eax






22
Seoul National University
제출방식

Due Date
 2013년 10월 27일(일요일) 11:59 PM 까지
 1일 delay 당 5점씩 감점
 제출 기한 일주일 후 까지 제출 가능


(11월 3일 11:59 PM까지 가능)
메일로 보고서와 소스코드 제출
 메일제목 : [컴구조과제]학번_이름
 첨부파일 : 학번_이름.zip으로 함께 압축하여 제출


ex) 제
목 : [컴구과제]2013-00000_나안수
첨부파일 : 2013-00000_나안수.zip
메일주소 : [email protected]
23