29
기기 기기기 기기기기기 기기 기기기 기기기기기 Lecture #6 Lecture #6

기본 컴퓨터 프로그래밍

Embed Size (px)

DESCRIPTION

기본 컴퓨터 프로그래밍. Lecture #6. 강의 목차. Introduction Machine Language Assembly Language Assembler Program Loops Programming Arithmetic and Logic Operations Subroutines Input-Output Programming. 강의 개요 (1). 컴퓨터 시스템에서 하드웨어와 소프트웨어는 상호 영향을 미치기 때문에 컴퓨터 구조를 이해하기 위해서는 하드웨어와 소프트웨어 모두에 대한 지식이 필요 - PowerPoint PPT Presentation

Citation preview

Page 1: 기본 컴퓨터 프로그래밍

기본 컴퓨터 프로그래밍기본 컴퓨터 프로그래밍

Lecture #6Lecture #6

Page 2: 기본 컴퓨터 프로그래밍

강의 목차강의 목차

▶ Introduction▶ Machine Language▶ Assembly Language▶ Assembler▶ Program Loops▶ Programming Arithmetic and Logic Operations▶ Subroutines▶ Input-Output Programming

2컴퓨터시스템구조

Page 3: 기본 컴퓨터 프로그래밍

강의 개요 강의 개요 (1)(1)

▶ 컴퓨터 시스템에서 하드웨어와 소프트웨어는 상호 영향을 미치기 때문에 컴퓨터 구조를 이해하기 위해서는 하드웨어와 소프트웨어 모두에 대한 지식이 필요

▶ 소프트웨어 (Software)▷ 컴퓨터에서 실행하기 위해 작성된 프로그램▷ 프로그램 작성 일련의 기계명령어를 직접 , 간접적으로 기술하는 것▷ 사용자 위주 프로그래밍 언어의 필요성

Translate user-oriented symbolic program(alphanumeric character set) into binary programs recognized by the hardware

3컴퓨터시스템구조

Page 4: 기본 컴퓨터 프로그래밍

강의 개요 강의 개요 (2)(2)

▶ 기본 컴퓨터의 명령어 집합▷ 25 개의 기계어 명령어 지원▷ Memory Reference Instruction▷ Register Reference Instruction▷ Input-output Instruction

4컴퓨터시스템구조

Page 5: 기본 컴퓨터 프로그래밍

기계어 기계어 (1)(1)

▶ 프로그램 분류1) 고급 프로그래밍 언어

문제해결에 필요한 과정을 고려하여 개발된 언어 인간의 언어와 유사 컴파일러 (Compiler) 예 : 두 수의 더하기 (FOTRAN 프로그램 )

2) 기호 코드 (Symbolic Code) 어셈블리 언어 (Assembly Language)

– 이진 코드의 명령어를 기호로 표현 어셈블러 (Assembler)

5컴퓨터시스템구조

Page 6: 기본 컴퓨터 프로그래밍

기계어 기계어 (2)(2)

▶ 프로그램 분류3) 8 진수 또는 16 진수 코드

이진수 코드를 읽기 쉽게 8 진수 또는 16 진수로 표현

4) 이진 코드 / 기계어 (Machine Code) 실제 메모리 상에 로드되어 CPU 에 의해 실행되는 명령어 시퀀스

6컴퓨터시스템구조

Page 7: 기본 컴퓨터 프로그래밍

어셈블리 언어 어셈블리 언어 (1)(1)

▶ 어셈블리 언어 프로그램 작성 규칙▷ Documented and published in manuals(from the computer

manufacturer)▷ 정확한 번역을 위해 형식 규정을 잘 지켜 프로그램을 작성하여야 함 .

▶ 기본 컴퓨터의 어셈블리 프로그램 작성 규칙▷ 어셈블리 언어 프로그램의 각 줄은 세 개의 필드 (field) 로 구성

1) Label field : empty or symbolic address 2) Instruction field : machine instruction or pseudo-instruction 3) Comment field : empty or comment

▷ 기호 주소 : Symbolic Address(Label field) One, two, or three, but not more than three alphanumeric characters The first character must be a letter; the next two may be letters or

numerals A symbolic address is terminated by a comma(recognized as a label

by the assembler)

7컴퓨터시스템구조

Page 8: 기본 컴퓨터 프로그래밍

어셈블리 언어 어셈블리 언어 (2)(2)

▶ 기본 컴퓨터의 작성 규칙 ( 계속 )

▷ 명령어 필드 : Instruction Field 1) A memory-reference instruction(MRI)

– Ex) ADD OPR(direct address MRI), ADD PTR I(indirect address MRI) 2) A register-reference or input-output instruction(non-MRI)

– Ex) CLA(register-reference), INP(input-output) 3) A pseudoinstruction with(ORGN) or without(END) an operand : Tab. 6-

7– 의사 명령어 (Pseudoinstruction) 은 기계어 명령어가 아니고 어셈블러 (Assembler)

에게 필요한 정보만 제공

▷ 주석 필드 : Comment field must be preceded by a slash(recognized by assembler as comment)

8컴퓨터시스템구조

Page 9: 기본 컴퓨터 프로그래밍

어셈블리 언어 어셈블리 언어 (3)(3)

▶ 예제 프로그램 : 표 . 6-8▷ 83 -( -23 ) = 83 + ( 2’s Complement of -23)= 83 + 23

9컴퓨터시스템구조

Page 10: 기본 컴퓨터 프로그래밍

어셈블리 언어 어셈블리 언어 (4)(4)

▶ 어셈블리 프로그램의 이진 코드 변환 : 2-pass 어셈블러 ▷ 1) 1st scan pass : 사용자 정의 심볼 테이블 생성

▷ 2) 2nd scan pass : 이진 코드 변환

10컴퓨터시스템구조

Address Symbol Hexadecimal Address

MIN 106

SUB 107

DIF 108

Page 11: 기본 컴퓨터 프로그래밍

어셈블러 어셈블러 (1)(1)

▶ 어셈블러 (Assember)▷ 기호 - 언어 프로그램을 읽어 이진 프로그램으로 번역

▷ 소스 프로그램 (Source Program) 기호 - 언어로 작성된 입력 프로그램 ASCII 코드로 작성된 텍스트 데이터

▷ 목적 코드 (Object Code) 재배치 가능한 (relocatable) 이진 코드 프로그램

▷ 이진 코드 (Binary Code) 목적 코드와 라이브러리 등을 링크하여 실행 가능한 형태로 생성된 이진 코드

프로그램

11컴퓨터시스템구조

Page 12: 기본 컴퓨터 프로그래밍

어셈블러 어셈블러 (2)(2)

▶ 2- 패스 어셈블러 (2-Pass Assember)▷ 1-Pass Scan : 사용자 정의 주소 심볼 테이블 생성

Flowchart

LC(Location Counter) – 현재 처리되고 있는 명령어나 피연산자에 지정된 메모리 주소값을 저장

주소 심볼 테이블 : 표 . 6-11 참조

12컴퓨터시스템구조

Page 13: 기본 컴퓨터 프로그래밍

어셈블러 어셈블러 (3)(3)

▶ 2- 패스 어셈블러 (2-Pass Assember) ( 계속 )

▷ 2-Pass Scan : 이진 코드 변환 다음의 4 개의 테이블을 참고하여 어셈블리 명령어를 이진 코드로 변환 (1) 의사명령어 테이블 (2) MRI 테이블 (3) Non-MRI 테이블

(4) 주소 심볼 테이블

에러 진단 (Error Diagnostics)– 모호한 기계어 코드 , 정의가 안된 기호 주소 사용 등– 에러 메시지 출력

Flowchart : 다음 페이지 참조

13컴퓨터시스템구조

Page 14: 기본 컴퓨터 프로그래밍

어셈블러 어셈블러 (4)(4)

14컴퓨터시스템구조

Page 15: 기본 컴퓨터 프로그래밍

프로그램 루프프로그램 루프

▶ 프로그램 루프 (Program Loops)▷ A sequence of instructions that are executed many times

▶ 예 :▷ Sum of 100 integer numbers

Fortran 프로그램

▷ Symbolic Program : 표 . 6-13 주소 150 부터 100 개의

데이터를 더하기

15컴퓨터시스템구조

Page 16: 기본 컴퓨터 프로그래밍

산술 및 논리 연산 프로그래밍 산술 및 논리 연산 프로그래밍 (1)(1)

▶ Hardware implementation▷ Operations are implemented in a computer with one machine

instruction▷ Ex) ADD, SUB

▶ Software implementation▷ Operations are implemented by a set of instruction(Subroutine)▷ Ex) MUL, DIV

▶ 곱셈 프로그램 (Multiplication Program)▷ Positive Number Multiplication

X = multiplicand, Y = multiplier, P = Partial Product Sum

Y 를 AC 에 저장한 후 E 로 Circular Right E = 1 : P 에 1111 을 더함 E = 0 : 더하지 않음

16컴퓨터시스템구조

Page 17: 기본 컴퓨터 프로그래밍

산술 및 논리 연산 프로그래밍 산술 및 논리 연산 프로그래밍 (2)(2)

▶ 곱셈 프로그램 (Multiplication Program) ( 계속 )

17컴퓨터시스템구조

Page 18: 기본 컴퓨터 프로그래밍

산술 및 논리 연산 프로그래밍 산술 및 논리 연산 프로그래밍 (3)(3)

▶ 배정밀도 가산 (Double Precision Addition) : 32 bits▷ 하위 AL + BL 먼저 수행하여 E 를 상위에 반영 (AH + BH + E)

18컴퓨터시스템구조

Page 19: 기본 컴퓨터 프로그래밍

산술 및 논리 연산 프로그래밍 산술 및 논리 연산 프로그래밍 (4)(4)

▶ 논리 연산 (Logic Operations)▷ Logic Operation 중에서 OR 명령이 없다 (Tab. 6-1)▷ 추가하려면 더 긴 Instruction Format 필요▷ 해결방법 : DeMorgan’s theorem

19컴퓨터시스템구조

Page 20: 기본 컴퓨터 프로그래밍

▶ 시프트 연산 (Shift Operations)▷ Logical Shift : Zero must added to the extreme position

Shift Right

Shift Left

▷ Arithmetic Shift Right Positive ( + = 0)

Negative ( -= 1)

산술 및 논리 연산 프로그래밍 산술 및 논리 연산 프로그래밍 (5)(5)

20컴퓨터시스템구조

Page 21: 기본 컴퓨터 프로그래밍

▶ 서브루틴 (Subroutine)▷ 프로그램 내에서 여러 번 사용되는 공통된 명령어 집합▷ 기본 컴퓨터에서 주 프로그램과 서브루틴 사이의 링크는 BSA(Branch

and Save return Address) 명령어에 의해 실행▷ 서브루틴 예제 : Tab. 6-16

서브루틴 서브루틴 (1)(1)

21컴퓨터시스템구조

Page 22: 기본 컴퓨터 프로그래밍

▶ 서브루틴 파라미터와 데이터 링키지 (Data Linkage)▷ Parameter(or Argument) Passing

서브루틴이 호출될 때에는 주 프로그램은 서브루틴이 필요로 하는 데이터를 넘겨주어야 한다

▷ 2 가지 Parameter Passing 방법 1) Data transfer through the Accumulator

– Used for only single input and single output parameter 2) Data transfer through the Memory

– 여러 개의 Operand 전달가능– Operand are often placed in memory locations following the CALL

▷ 2 개의 Parameter Passing 예 : Tab. 6-17 First Operand and Result: Accumulator Second Operand: Inserted in location following the BSA

▷ BSA 후에 2 개 Operand 예 : Tab. 6-18 BSA 후에 2 개의 Operand 사용 Block 전송 Source 와 Destination Address 로 사용

서브루틴 서브루틴 (2)(2)

22컴퓨터시스템구조

Page 23: 기본 컴퓨터 프로그래밍

서브루틴 서브루틴 (3)(3)

23컴퓨터시스템구조

Page 24: 기본 컴퓨터 프로그래밍

서브루틴 서브루틴 (4)(4)

24컴퓨터시스템구조

Page 25: 기본 컴퓨터 프로그래밍

▶ One-character I/O▷ Programmed I/O 방식

입출력 프로그래밍 입출력 프로그래밍 (1)(1)

25컴퓨터시스템구조

Page 26: 기본 컴퓨터 프로그래밍

▶ Two-character I/O▷ Two character Packing

입출력 프로그래밍 입출력 프로그래밍 (2)(2)

26컴퓨터시스템구조

Page 27: 기본 컴퓨터 프로그래밍

▶ Store Input Character in Buffer

입출력 프로그래밍 입출력 프로그래밍 (3)(3)

27컴퓨터시스템구조

Page 28: 기본 컴퓨터 프로그래밍

▶ Compare Two Word

입출력 프로그래밍 입출력 프로그래밍 (4)(4)

28컴퓨터시스템구조

Page 29: 기본 컴퓨터 프로그래밍

▶ Interrupt Program▷ Interrupt Condition

Interrupt F/F R= 1 when IEN= 1 and [FGI or FGO= 1]

Save return address at 0000 Jump to 0001(Interrupt Start)

▷ Interrupt Service Routine(ISR) 1) Save Register (AC, E) 2) Check Input or Output Flag 3) Input or Output Service Routine 4) Restore Register (AC, E) 5) Interrupt Enable (ION) 6) Return to the running program

입출력 프로그래밍 입출력 프로그래밍 (5)(5)

29컴퓨터시스템구조

Modified Fetch Cycle 과 Reset 시에 IEN=0 가 된다(Ref. Fig. 5-15)