Download presentation
Presentation is loading. Please wait.
Published byBernard Basil Patterson Modified over 8 years ago
1
1 M. Morris Mano Computer System Architecture Chapter 6: Programming the Basic Computer 박 찬식 http://gnc.chungbuk.ac.krchansp@chungbuk.ac.kr 교육관 325 호, T. 3259
2
목차 Introduction Machine Language Assembly Language The Assembler Program Loops Programming Arithmetic and Logic Operations Subroutines Input-Output Programming 2
3
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 … 1010 100 101 102 Memory PC AR IR AC CPU 200 Software Hardware
4
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
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
6 Programming Language … A200 7020 … 1010 100 101 102 200 Void main { … a = b; a++; …} _MAIN: … LDA, (B) INC A; … End Compiler & Linker Assembler & Linker Compiler … 1010001000000000 0111000000100000 … 0001000000010000 100 101 102 200 Hexadecimal Code Binary Code (Phase 1 + Phase 2) (Phase 1) (Phase 2)
7
7 Basic Computer Instructions n Memory-reference Instruction u Opcode = 000 ~ 110 n Register-reference Instruction n Input-Output Instruction OpcodeAddressI 15 14 12 11 0 1 1 1Register Operation0 15 14 12 11 0 1 1 1I/O Operation1 15 14 12 11 0
8
8 Memory-reference Instructions OpcodeAddressI 15 14 12 11 0 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
9 Register-reference Instructions 1 1 1Register Operation0 15 14 12 11 0 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
10 Input-Output Instructions 1 1 1I/O Operation1 15 14 12 11 0 SymbolCodeDescription INPF800Input Character to AC OUTF400Output Character from AC SKIF200Skip on input flag SKOF100Skip on output flag IONF080Interrupt ON IOFF040Interrupt OFF
11
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
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 000LDA004 001ADD005 002STA006 003HLT 0040053 005FFE9 0060000 0002004 0011005 0023006 0037001 0040053 005FFE9 0060000 0000010 0000 0000 0100 0010001 0000 0000 0101 0100011 0000 0000 0110 0110111 0000 0000 0001 1000000 0000 0101 0011 1011111 1111 1110 1001 1100000 0000 0000 0000 FORTRANAssembly Symbolic Hexadecimal Binary Computer Hardware
13
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
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
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
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
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
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
19 Translation to Binary (Cont.) From now on, Programming with Assembly Language is concerned Homework: Finish following Table ORG 100PC 100 LDA SUB1002107AR PC, PC PC+1,… CMA1017200 INC1027020 ADD MIN1031106 STA DIF1043108 HLT1057001 MIN,DEC 831060053 SUB,DEC -23107FFE9 DIF,HEX 01080000 END AssemblyHexadecimalMicrooperation
20
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
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 105 108 STA 10F 109 HLT 10A HEX 150 10B HEX 0 10C DEC -100 10D HEX 0 10E HEX 0 10F DEC 75 150 … … DEC 23 1B4 Can you trace this program ? Esp. AC, PTR and CTR ? CLA 104
22
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
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
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
25 Multiplication Program Specification of Program Multiplication of 8-bit positive numbers 8-bit x 8-bit = 16-bit Result Ex: 0000 1111B x 0000 1011B 00001111 x (00000001 + 00000010 + 00001000) = 00001111 + 00001111 x 2 + 00001111 x 8 = 00001111 + 00001111 << 1 + 00001111 << 3 = 00001111 + 00011110 + 01111000 = 10100101 Multiplication can be implemented with SHIFT and ADD instructions
26
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-8-7-6-5 X,HEX000F001E003C0078 Y,HEX000B000500020001 P,HEX0000F002D002D END
27
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 0001+00F0 ADDBHAC 00F1+00FF STACHCH 01F0 HLT AL,HEXFF0F AH,HEX00F0 BL,HEX00FF BH,HEX00FF CL,HEX0000E CH,HEX001F0 END
28
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
29 Shift Operations Basic Computer has CIR, CIL Implementation of Logical Shift shr: CLEshl: CLE CIR CIL E AC 0
30
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
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
32 Subroutine: Example ORG100 100LDAXAC 1234 101BSASH4SH4 102(=PC), PC 10A 102STAXX AC 103LDAYAC 4321 104BSASH4SH4 105(=PC), PC 10A 105STAYY AC 106HLT 107 X,HEX1234 108 Y,HEX4321 109 SH4,HEX0102105 10ACILAC 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)=105 110 MSK,HEXFFF0 END
33
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
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
35 Ex: Parameter Passing ORG200 200LDAXAC 7B95 201BSAORPC 208, OR 202 202HEX3AF6 203STAYY AC 204HLT 205X,HEX7B95 206Y,HEX0 207OR,HEX0202203 208CMAAC AC’ 209STATMPTMP AC 20ALDAOR IAC (202)=3AF6 20BCMAAC AC’ 20CANDTMPAC AC & TMP 20DCMAAC AC’ 20EISZOROR 202+1 20FBUNOR IPC (207)=203 210TMP,HEX0 END
36
36 Ex: Move a Block of Data 100BSAMVE MVE 101, PC MVE+1 101HEX100 102HEX200 103DEC-16 104HLT MVE,HEX0101102103104 LDAMVE IAC (101)=100 STAPT1PT1 AC ISZMVEMVE 101+1 LDAMVE IAC (102)=200 STAPT2PT2 AC ISZMVEMVE 102+1 LDAMVE IAC (103)=-16 STACTRCTR AC ISZMVEMVE 103+1 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,HEX0100101 … 10F110 PT2,HEX0200201… 20F210 CTR,HEX0-16D-15D… -10
37
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
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
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
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
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
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.