1 M. Morris Mano Computer System Architecture Chapter 6: Programming the Basic Computer 박 찬식 교육관 325 호,

Slides:



Advertisements
Similar presentations
Cpe 252: Computer Organization1 Lo’ai Tawalbeh Programming The Basic Computer Chapter 6:
Advertisements

Chapter 16 Control Unit Operation No HW problems on this chapter. It is important to understand this material on the architecture of computer control units,
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Chapter 16 Control Unit Implemntation. A Basic Computer Model.
Chapter 15 IA 64 Architecture Review Predication Predication Registers Speculation Control Data Software Pipelining Prolog, Kernel, & Epilog phases Automatic.
Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009
COMPUTER INSTRUCTIONS
Computer System Architecture Dept. of Info. Of Computer Chap. 6 Programming the Basic Computer 6-1 Chap. 6 Programming the Basic Computer n 6-1 Introduction.
April 14, 2007CCSC-Central Plains Region1 Use of a Simulator and an Assembler in Teaching Input-Output Processing and Interrupt Handling Soe Than Department.
Chapter 6: Programming The Basic Computer CPIT 210
Bus Architecture Memory unit AR PC DR E ALU AC INPR 16-bit Bus IR TR
Computer System Architecture ESGD2204
Chapter No 5 Basic Computer Organization And Design.
1 Basic Computer Organization & Design Computer Organization Computer Architectures Lab BASIC COMPUTER ORGANIZATION AND DESIGN Instruction Codes Computer.
Eng. Mohammed Timraz Electronics & Communication Engineer University of Palestine Faculty of Engineering and Urban planning Software Engineering Department.
Bus Architecture Memory unit AR PC DR E ALU AC INPR 16-bit Bus IR TR
CONTROL UNIT OPERATION MICROPROGRAMMED CONTROL. 2.
Exam2 Review Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
Lecture 14 Today’s topics MARIE Architecture Registers Buses
Chapter # 6 PROGRAMING THE BASIC COMPUTER.
PROGRAMMING THE BASIC COMPUTER
1 Purpose of This Chapter In this chapter we introduce a basic computer and show how its operation can be specified with register transfer statements.
M. Mateen Yaqoob The University of Lahore Spring 2014.
Lec 5 Basic Computer Organization
M. Mateen Yaqoob The University of Lahore Spring 2014
COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent.
Computer Organization 1 Instruction Fetch and Execute.
1 Basic Computer Organization & Design Computer Organization Prof. H. Yoon BASIC COMPUTER ORGANIZATION AND DESIGN Instruction Codes Computer Registers.
Instruction.
Ch5. 기본 컴퓨터의 구조와 설계.
8085 processor.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Basic Computer The following discussions are based on a fictitious computer called “Basic Computer” by the author of the textbook It’s a much better way.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Introduction A computer system includes both hardware and software. The designer should be familiar with both of them. This chapter introduces some basic.
1 BASIC COMPUTER ORGANIZATION AND DESIGN Instruction Codes Computer Registers Computer Instructions Timing and Control Instruction Cycle Memory Reference.
PROGRAMMING THE BASIC COMPUTER
Basic Computer Organization and Design
PROGRAMMING THE BASIC COMPUTER
Assembly Language Programming of 8085
COMPUTER ARCHITECTURE
Symbol Hex Code Description I=0 I=1
PROGRAMMING THE BASIC COMPUTER
Computer Organization and Design
BASIC COMPUTER ORGANIZATION AND DESIGN
MICROPROGRAMMED CONTROL
INDEX UNIT-III PPT SLIDES
BASIC COMPUTER ORGANIZATION AND DESIGN
BASIC COMPUTER ORGANIZATION AND DESIGN
BIC 10503: COMPUTER ARCHITECTURE
Instructions - Type and Format
By: A. H. Abdul Hafez CAO, by Dr. A.H. Abdul Hafez, CE Dept. HKU
سازمان و طراحي کامپيوتر پايه.
Assembler CASE Tool.
PROGRAMMING THE BASIC COMPUTER
Programming The Basic Computer
Chap. 6 Programming the Basic Computer
Instruction and Control II
Programming The Basic Computer
Fundamentals of Computer Organisation & Architecture
Chapter 8 Central Processing Unit
MARIE: An Introduction to a Simple Computer
By: A. H. Abdul Hafez Computer Architecture and Organization: L06: Stored program and Instruction code.
Computer Architecture and Organization: L07: Control Sequence
PROGRAMMING THE BASIC COMPUTER
Chapter 6 Programming the basic computer
MICROPROGRAMMED CONTROL
MICROPROGRAMMED CONTROL
Chapter 7 Microprogrammed Control
Presentation transcript:

1 M. Morris Mano Computer System Architecture Chapter 6: Programming the Basic Computer 박 찬식 교육관 325 호, T. 3259

목차 Introduction Machine Language Assembly Language The Assembler Program Loops Programming Arithmetic and Logic Operations Subroutines Input-Output Programming 2

3 … AR  PC (100) PC  PC + 1 ADD_BUS  AR IR  DATA_BUS Decode IR “LD A, (B)” AR  B (200) ADD_BUS  AR IR  DATA_BUS AC  IR AR  PC (101) PC  PC + 1 ADD_BUS  AR IR  DATA_BUS Decode IR “INC A” AC  AC + 1 … a = b; a++; … Computer System … LD A,(B) INC A … Memory PC AR IR AC CPU 200 Software Hardware

4 Introduction Computer System includes  Hardware  Software  Application Program: Does not concerns HW  System calls in OS: Concerns HW  Compiler: Application Program to Object Code  Linker: Allocate address to Object Code  Object Code includes Machine Instructions and Data  But in this course, Assembly Language is used

5 Introduction (Cont.) Assembly Language  Symbolic notation of Machine Instruction  Ex: CLA Vs. 7800H  Assembler  from Assembly Language to Binary Instruction Two way to get Assembler Program  Directly Write Program  Compiler

6 Programming Language … A … Void main { … a = b; a++; …} _MAIN: … LDA, (B) INC A; … End Compiler & Linker Assembler & Linker Compiler … … Hexadecimal Code Binary Code (Phase 1 + Phase 2) (Phase 1) (Phase 2)

7 Basic Computer Instructions n Memory-reference Instruction u Opcode = 000 ~ 110 n Register-reference Instruction n Input-Output Instruction OpcodeAddressI Register Operation I/O Operation

8 Memory-reference Instructions OpcodeAddressI Symbol CodeDescription AND0xxx8xxxAND memory word to AC ADD1xxx9xxxADD memory word to AC LDA2xxxAxxxLoad memory word to AC STA3xxxBxxxStore Content of AC in memory BUN4xxxCxxxBranch Unconditionally BSA5xxxDxxxBranch and Save Return Address ISZ6xxxExxxIncrement and Skip if Zero

9 Register-reference Instructions 1 1 1Register Operation SymbolCodeDescription CLA7800Clear AC CLE7400Clear E CMA7200Complement AC CME7100Complement E CIR7080Circulate Right AC and E CIL7040Circulate Left AC and E INC7020Increment AC SPA7010Skip next instruction if AC positive SNA7008Skip next instruction if AC negative SZA7004Skip next instruction if AC zero SZE7002Skip next instruction if E is zero HLT7001Halt Computer

10 Input-Output Instructions 1 1 1I/O Operation SymbolCodeDescription INPF800Input Character to AC OUTF400Output Character from AC SKIF200Skip on input flag SKOF100Skip on output flag IONF080Interrupt ON IOFF040Interrupt OFF

11 Machine Language Program  A list of Instructions or Statement for directing the computer to perform a required data processing Machine Language Program  Binary Code  But for convenience, Hexadecimal Code is preferred  Symbolic Code or Assembly Code is easy to understand

12 Machine Language: Example INTEGER A, B, C DATA A,83 B,-23 C=A+B END ORG 0 LDA A ADD B STA C HLT A,DEC83 B,DEC-23 C,DEC0 END 000LDA ADD STA HLT FFE FFE FORTRANAssembly Symbolic Hexadecimal Binary Computer Hardware

13 Assembly Language for Basic Computer Each line of Assembly Language program is arranged in three Fields  Label field: Empty or Symbolic Address  Instruction field: Machine instruction or Pseudoinstruction  Comment field: Empty or Comments Ex: Label Instruction Comment LDA X LDA X/Load X to AC ONE,LDA X/Load X to AC

14 Assembly Language (Cont.) Symbolic Address  Not more than Three Alphanumeric characters  First Character should be Letter  Terminated by Comma Comments  Start with Slash (/)  Explaining the program, Easy to understand  Not Converted to Binary Code

15 Assembly Language (Cont.) Instruction Field  MRI (Memory Reference Instruction)  Symbol for MRISymbolic AddressIndirect ADDOPR ADDOPRI MUST occurs at Label Field  Non-MRI: Register reference or I/O Instruction  Symbol for MRINO Symbolic Address CLA  Pseudoinstruction with or without Operand

16 Assembly Language (Cont.) n Pseudoinstruction u Not Machine instruction but instruction for assembler control SymbolInformation for the assembler ORG NHexadecimal N is the memory location for the Instruction or Operand listed in the following line ENDDenotes the End of symbolic Program DEC NSigned decimal number N to be converted to Binary HEX NHexadecimal number N to be converted to Binary

17 Assembly Language: Example TypeLabelInstructionComments PseudoIns.ORG 100/Origin of program is location 100H MRILDA SUB/Load SUB to AC Non-MRICMA/Complement AC Non_MRIINC/Increment AC MRIADD MIN/Add MIN to AC MRISTA DIF/Store AC to DIF PseudoIns.HLT/Halt Computer PseudoIns.MIN,DEC 83/MIN value PseudoIns.SUB,DEC -23/SUB value PseudoIns.DIF,HEX 0/DIF will saved here PseudoIns.END/End of Program

18 Translation to Binary Assembler translate Assembly Language (Source Program) to Binary Code (Object Program)  For more information, See Section 6-4  1st Pass: Generate Address Symbol Table  2nd Pass: Machine instructions are translated by means of table lookup procedure Pseudoinstruction Table MRI Table Non-MRI Table Address Symbol Table  Error Diagnostics Syntax error, Not defined symbolic address,...

19 Translation to Binary (Cont.) From now on, Programming with Assembly Language is concerned Homework: Finish following Table ORG 100PC  100 LDA SUB AR  PC, PC  PC+1,… CMA INC ADD MIN STA DIF HLT MIN,DEC SUB,DEC FFE9 DIF,HEX END AssemblyHexadecimalMicrooperation

20 Program Loops Program Loop  A sequence of instructions that are executed many times, each time with a different set of data  Fortran Example (SUM = A(1)+…+A(100)) DIMENSION A(100) INTEGER SUM, A SUM = 0 DO 3 J =1,100 3SUM = SUM + A(J)

21 Program Loops (cont.) ORG 100 LDA ADS STA PTR LDA NBR STA CTR CLA LOP,ADD PTR I ISZ PTR ISZ CTR BUN LOP STA SUM HLT ADS,HEX 150 PTR,HEX 0 NBR, DEC -100 CTR,HEX 0 SUMHEX 0 ORG 150 DEC 75. DEC 23 END LDA 10B 100 STA 10C 101 LDA 10D 102 STA 10E 103 ADD 10C I 105 ISZ 10C 106 ISZ 10E 107 BUN STA 10F 109 HLT 10A HEX B HEX 0 10C DEC D HEX 0 10E HEX 0 10F DEC … … DEC 23 1B4 Can you trace this program ? Esp. AC, PTR and CTR ? CLA 104

22 Program Loops (cont.) ORG 100 LDA ADSAC  150H STA PTRPTR  150H LDA NBRAC  -100D STA CTRCTR  -100D CLAAC  0H LOP,ADD PTR IAC  0+(150H)=0+75D AC  75D+(151H) … AC  AC+23D ISZ PTRPTR  150H+1 PTR  151H+1 … PTR  1B4H+1 ISZ CTRCTR  -100D+1 CTR  -99D+1 … CTR  -1D+1 BUN LOPPC  LOP PC  LOPSKIP STA SUMSUM  AC HLTHALT ADS,HEX 150 PTR,HEX 0 NBR, DEC -100 CTR,HEX 0 SUMHEX 0 ORG 150 DEC 75. DEC 23 END

23 Program Loops (Cont.) Why Assembly Language is so lengthy  We need following Variables  Pointer for Operand Address  Counter for Loop Control  AC for Scratch Pad  But our Basic Computer has Only One register  Pointer and Counter should be in Memory  If Computer has lots of registers  INDEX register for Pointer and Counter  Memory Access time can be reduced  For more information, see section 8-5

24 Programming Arithmetic and Logic Operations Implementation of Arithmetic and Logic Op  By Hardware  Complex ALU, but Fast  One Machine instruction for operation  For more information, Refer Chapter 10  By Software  Simple ALU, but Slow  A set of instructions for operation  Our Basic Computer has Only one arithmetic instruction (ADD), Others are programmed using basic instruction

25 Multiplication Program Specification of Program  Multiplication of 8-bit positive numbers  8-bit x 8-bit = 16-bit Result Ex: B x B  x ( ) = x x 8 = << << 3 = =  Multiplication can be implemented with SHIFT and ADD instructions

26 Multiplication Program (cont.) ORG100 LOP,CLEE  0E  0E  0 LDAYAC  000BAC  0005AC  0002 CIRE  1, AC  0005E  1, AC  0002 E  0, AC  0001 STAYY  0005Y  0002 Y  0002 SZE BUN ONEPC  ONEPC  ONE BUNZRO PC  ZRO ONE,LDAXAC  000FAC  001E ADDPAC  000F+0AC  001E+000F STAPP  ACP  AC CLEE  0E  0 ZRO,LDAXAC  000FAC  001EAC  003C CILE  0, AC  001EE  0, AC  003C E  0, AC  0078 STAXX  ACX  AC X  AC ISZCTRCTR  1-8CTR  1-7 CTR  1-6 BUNLOPPC  LOPPC  LOP PC  LOP HLT CTR,DEC X,HEX000F001E003C0078 Y,HEX000B P,HEX0000F002D002D END

27 Double Precision Addition Double Precision  A number stored in Two memory word  Used for great accuracy  Ex: 00F0FF0F + 00FF00FF = 01F0000E ORG 100 LDAALAC  FF0F ADDBLE  1, AC  000E (1000E=FF0F+00FF) STACLCL  000E CLAAC  0 CILE  0, AC  0001 ADDAHAC  F0 ADDBHAC  00F1+00FF STACHCH  01F0 HLT AL,HEXFF0F AH,HEX00F0 BL,HEX00FF BH,HEX00FF CL,HEX0000E CH,HEX001F0 END

28 Logic Operations Basic Computer has AND, CMA, CLA Implementation of OR  DeMorgan’s theorem: A # B = (A’ & B’)’ LDAA/AC  A CMA/AC  A’ STATMP/TMP  A’ LDAB/AC  B CMA/AC  B’ ANDTMP/AC  B’&A’ CMA/AC  (B’&A’)’

29 Shift Operations Basic Computer has CIR, CIL Implementation of Logical Shift shr: CLEshl: CLE CIR CIL E AC 0

30 Shift Operations Implementation of Arithmetic Right Shift ashr: CLE/E  0 SPA/if AC>0 (MSB of AC is 0), Skip CME/else E  1 CIR /Circulate E and AC AC

31 Subroutines Subroutine  A set of common instructions that can be used in program many times  Basic Computer has BSA instruction  Branch and Save Return Address MACRO  Assembler Utility for not common but Similar instructions

32 Subroutine: Example ORG LDAXAC  BSASH4SH4  102(=PC), PC  10A 102STAXX  AC 103LDAYAC  BSASH4SH4  105(=PC), PC  10A 105STAYY  AC 106HLT 107 X,HEX Y,HEX SH4,HEX ACILAC  cil(AC) AC  cil(AC) 10BCILAC  cil(AC)AC  cil(AC) 10CCILAC  cil(AC)AC  cil(AC) 10DCILAC  cil(AC)AC  cil(AC) 10EANDMSKAC  AC & FFF0 AC  AC & FFF0 10FBUNSH4 IPC  (109)=102PC  (109)= MSK,HEXFFF0 END

33 Subroutine Linkage  Procedure for branching subroutine and returning to main program Basic Computer (Only ONE register)  BSA SUB-->call  BUN SUB I-->return Generally  Stack and Stack Pointer is used  Stack saves Return address  Stack Pointer is Index Register pointing the location of Stack

34 Subroutine Parameters and Data Linkage Subroutine needs Input(Output) Parameters from(to) Main routine  Using Registers  Basic Computer has AC only One Input - One Output  The more register, The Easier  Using Memory  Basic Computer: Predefined Location  Generally Stack is used for parameter passing

35 Ex: Parameter Passing ORG LDAXAC  7B95 201BSAORPC  208, OR  HEX3AF6 203STAYY  AC 204HLT 205X,HEX7B95 206Y,HEX0 207OR,HEX CMAAC  AC’ 209STATMPTMP  AC 20ALDAOR IAC  (202)=3AF6 20BCMAAC  AC’ 20CANDTMPAC  AC & TMP 20DCMAAC  AC’ 20EISZOROR  FBUNOR IPC  (207)= TMP,HEX0 END

36 Ex: Move a Block of Data 100BSAMVE MVE  101, PC  MVE+1 101HEX HEX DEC HLT MVE,HEX LDAMVE IAC  (101)=100 STAPT1PT1  AC ISZMVEMVE  LDAMVE IAC  (102)=200 STAPT2PT2  AC ISZMVEMVE  LDAMVE IAC  (103)=-16 STACTRCTR  AC ISZMVEMVE  LOP,LDAPT1 IAC  (100)…AC  (10F) STAPT2 I(200)  AC…(20F)  AC ISZPT1PT1  100+1…PT1  110 ISZPT2PT2  200+1…PT2  210 ISZCTRCTR  1-16…CTR  0 BUNLOPPC  LOP BUNMVE IPC  (MVE)=104 PT1,HEX … 10F110 PT2,HEX … 20F210 CTR,HEX0-16D-15D… -10

37 CIF,SKI/Check Input Flag BUNCIF/Flag=0, No Input INP/Flag=1, Read Character OUT/Echo Character STACHR/Store to CHR HLT CHR,HEX0 Input-Output Programming Programmed I/O  8 bit Input-Output LDACHR/AC  ’W’ COF,SKO/Check Output Flag BUNCOF/Flag=0, Not Ready OUT/Flag=1, Output Character HLT CHR,HEX0057/’W’ IF AC(L) OF AC(L)

38 Character Manipulation Program to Store Input Characters in a Buffer  Buffer Address is 500H LDAADS/AC  500 STAPTR/PTR  500 LOP,BSAIN2/AC  2 character STAPTR I/(PTR)  AC ISZPTR/PTR  PTR+1 BUNLOP/PC  LOP HLT ADS,HEX500 PTR,HEX0 IN2,HEX0 FST,SKI BUNFST INP OUT BSASH4 SCD,SKI BUNSCD INP OUT BUNIN2 I

39 Program Interrupt Programmed IO  Most of CPU time is spent at checking IF or OF  Loss of CPU time  Easy to Implement Interrupt  CPU request I/O to device  CPU goes to do Other jobs  Device Interrupt CPU when I/O operation is Done  CPU performs Interrupt Service Routine

40 Interrupt Service Routine Interrupt Occurs  See Chapter 5, for Interrupt cycle  IEN  0, (0)  PC, PC  1 Save Contents of processor registers  Basic Computer has AC and E registers Check which Flag is Set  IF(FGI) and OF(FGO) Flag  Priority of Interrupt: Which is serviced first? Service the device whose flag is set Restore Contents of processor registers Turn the Interrupt facility On  IEN  1, for Next interrupt Return to the running program

41 Ex: ISR 0ZRO,HEX0 1BUNSRV … 200SRV, STASAC CIR STASE SKI BUNNXT INP OUT STAPT1 I ISZPT1 NXT,SKO BUNEXT LDAPT2 I OUT ISZPT2 EXT,LDASE CIL LDASAC ION BUNZRO I SAC, SE, PT1, PT2, 100CLA 101ION 102LDAX 103ADDY 104STAZ … Interrupt Occurs

42 Homework ISR Example  Describe all procedure with  operation  Trace ZRO,SAC,SE,PT1,PT2  Which is Higher Priority ? 6-1, 6-9, 6-12, 6-13, 6-21, 6-24, 6-28