1 / 29

기본 컴퓨터 프로그래밍

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

Download Presentation

기본 컴퓨터 프로그래밍

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 기본 컴퓨터 프로그래밍 Lecture #6

  2. 강의 목차 • Introduction • Machine Language • Assembly Language • Assembler • Program Loops • Programming Arithmetic and Logic Operations • Subroutines • Input-Output Programming 컴퓨터시스템구조

  3. 강의 개요 (1) • 컴퓨터 시스템에서 하드웨어와 소프트웨어는 상호 영향을 미치기 때문에 컴퓨터 구조를 이해하기 위해서는 하드웨어와 소프트웨어 모두에 대한 지식이 필요 • 소프트웨어(Software) • 컴퓨터에서 실행하기 위해 작성된 프로그램 • 프로그램 작성  일련의 기계명령어를 직접,간접적으로 기술하는 것 • 사용자 위주 프로그래밍 언어의 필요성 • Translate user-oriented symbolic program(alphanumeric character set) intobinary programs recognized by the hardware 컴퓨터시스템구조

  4. 강의 개요 (2) • 기본 컴퓨터의 명령어 집합 • 25 개의 기계어 명령어 지원 • Memory Reference Instruction • Register Reference Instruction • Input-output Instruction 컴퓨터시스템구조

  5. 기계어 (1) • 프로그램 분류 • 고급 프로그래밍 언어 • 문제해결에 필요한 과정을 고려하여 개발된 언어 • 인간의 언어와 유사 • 컴파일러(Compiler) • 예: 두 수의 더하기(FOTRAN 프로그램) • 기호 코드(Symbolic Code) • 어셈블리 언어(Assembly Language) • 이진 코드의 명령어를 기호로 표현 • 어셈블러(Assembler) 컴퓨터시스템구조

  6. 기계어 (2) • 프로그램 분류 • 8진수 또는 16진수 코드 • 이진수 코드를 읽기 쉽게 8진수 또는 16진수로 표현 • 이진 코드 / 기계어(Machine Code) • 실제 메모리 상에 로드되어 CPU에 의해 실행되는 명령어 시퀀스 컴퓨터시스템구조

  7. 어셈블리 언어 (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) 컴퓨터시스템구조

  8. 어셈블리 언어 (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) 컴퓨터시스템구조

  9. 어셈블리 언어 (3) • 예제 프로그램 : 표. 6-8 • 83 -( -23 ) = 83 + ( 2’s Complement of -23)= 83 + 23 컴퓨터시스템구조

  10. 어셈블리 언어 (4) • 어셈블리 프로그램의 이진 코드 변환 : 2-pass 어셈블러 • 1) 1st scan pass : 사용자 정의 심볼 테이블 생성 • 2) 2nd scan pass : 이진 코드 변환 컴퓨터시스템구조

  11. 어셈블러 (1) • 어셈블러(Assember) • 기호-언어 프로그램을 읽어 이진 프로그램으로 번역 • 소스 프로그램(Source Program) • 기호-언어로 작성된 입력 프로그램 • ASCII 코드로 작성된 텍스트 데이터 • 목적 코드(Object Code) • 재배치 가능한(relocatable) 이진 코드 프로그램 • 이진 코드(Binary Code) • 목적 코드와 라이브러리 등을 링크하여 실행 가능한 형태로 생성된 이진 코드 프로그램 컴퓨터시스템구조

  12. 어셈블러 (2) • 2-패스어셈블러(2-Pass Assember) • 1-Pass Scan : 사용자 정의 주소 심볼 테이블 생성 • Flowchart  • LC(Location Counter) – 현재 처리되고 있는 명령어나 피연산자에 지정된 메모리 주소값을 저장 • 주소 심볼 테이블 : 표.6-11 참조 컴퓨터시스템구조

  13. 어셈블러 (3) • 2-패스어셈블러(2-Pass Assember) (계속) • 2-Pass Scan : 이진 코드 변환 • 다음의 4개의 테이블을 참고하여 어셈블리 명령어를 이진 코드로 변환 (1) 의사명령어 테이블 (2) MRI 테이블 (3) Non-MRI 테이블 (4) 주소 심볼 테이블 • 에러 진단(Error Diagnostics) • 모호한 기계어 코드, 정의가 안된 기호 주소 사용 등 • 에러 메시지 출력 • Flowchart : 다음 페이지 참조 컴퓨터시스템구조

  14. 어셈블러 (4) 컴퓨터시스템구조

  15. 프로그램 루프 • 프로그램 루프(Program Loops) • A sequence of instructions that are executed many times • 예: • Sum of 100 integer numbers • Fortran 프로그램 • Symbolic Program : 표. 6-13  • 주소 150부터 100 개의 데이터를 더하기 컴퓨터시스템구조

  16. 산술 및 논리 연산 프로그래밍 (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 : 더하지 않음 컴퓨터시스템구조

  17. 산술 및 논리 연산 프로그래밍 (2) • 곱셈 프로그램(Multiplication Program) (계속) 컴퓨터시스템구조

  18. 산술 및 논리 연산 프로그래밍 (3) • 배정밀도 가산(Double Precision Addition) : 32 bits • 하위 AL + BL 먼저 수행하여 E를 상위에 반영(AH + BH + E) 컴퓨터시스템구조

  19. 산술 및 논리 연산 프로그래밍 (4) • 논리 연산(Logic Operations) • Logic Operation 중에서 OR명령이 없다(Tab. 6-1) • 추가하려면 더 긴 Instruction Format 필요 • 해결방법: DeMorgan’s theorem 컴퓨터시스템구조

  20. 산술 및 논리 연산 프로그래밍 (5) • 시프트 연산(Shift Operations) • Logical Shift : Zero must added to the extreme position • Shift Right • Shift Left • Arithmetic Shift Right • Positive ( + = 0) • Negative ( -= 1) 컴퓨터시스템구조

  21. 서브루틴 (1) • 서브루틴(Subroutine) • 프로그램 내에서 여러 번 사용되는 공통된 명령어 집합 • 기본 컴퓨터에서 주 프로그램과 서브루틴 사이의 링크는 BSA(Branch and Save return Address) 명령어에 의해 실행 • 서브루틴 예제 : Tab. 6-16 컴퓨터시스템구조

  22. 서브루틴 (2) • 서브루틴 파라미터와 데이터 링키지(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로 사용 컴퓨터시스템구조

  23. 서브루틴 (3) 컴퓨터시스템구조

  24. 서브루틴 (4) 컴퓨터시스템구조

  25. 입출력 프로그래밍 (1) • One-character I/O • Programmed I/O 방식 컴퓨터시스템구조

  26. 입출력 프로그래밍 (2) • Two-character I/O • Two character Packing 컴퓨터시스템구조

  27. 입출력 프로그래밍 (3) • Store Input Character in Buffer 컴퓨터시스템구조

  28. 입출력 프로그래밍 (4) • Compare Two Word 컴퓨터시스템구조

  29. 입출력 프로그래밍 (5) • 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 Modified Fetch Cycle과 Reset 시에 IEN=0가 된다 (Ref. Fig. 5-15) 컴퓨터시스템구조

More Related