Ata Elahi Computer Systems Digital Design, Fundamentals of Computer Architecture and Assembly Language AtaElahi SouthernConnecticutStateUniversity NewHaven,CT,USA ISBN978-3-319-66774-4 ISBN978-3-319-66775-1 (eBook) https://doi.org/10.1007/978-3-319-66775-1 LibraryofCongressControlNumber:2017952347 ©SpringerInternationalPublishingAG2018 ThisSpringerimprintispublishedbySpringerNature TheregisteredcompanyisSpringerInternationalPublishingAG Theregisteredcompanyaddressis:Gewerbestrasse11,6330Cham,Switzerland Preface This textbook is the result of my experiences teaching computer systems at the Computer Science Department at Southern Connecticut State University since 1986. The book is divided into three sections: Digital Design, Introduction to Computer Architecture and Memory, and ARM Architecture and Assembly Lan- guage. The Digital Design section includes a laboratory manual with 12 experi- ments using Logisim software to enforce important concepts. The ARM ArchitectureandAssemblyLanguagesectionincludesseveralexamplesofassem- blylangaugeprogramsusingKeilμVision5developmenttools. Intended Audience This book is written primarily for a one semester course as an introduction to computer hardware and assembly language for students majoring in Computer Science,InformationSystemsandEngineeringTechnology. Organization Thematerialofthisbookispresentedinsuchawaythatnospecialbackgroundis requiredtounderstandthetopics. Chapter1–SignalsandNumberSystems:AnalogSignal,DigitalSignal,Binary Numbers, Addition and Subtraction of binary numbers, IEEE 754 Floating Point representations,ASCII,Unicode,SerialTransmission,andParallelTransmission. Chapter2–BooleanLogicsandLogicGates:BooleanLogics,BooleanAlgebra Theorems,LogicGates,IntegrateCircuit(IC),BooleanFunction,TruthTableofa functionandusingBooleanTheoremstosimplifyBooleanFunctions. Chapter 3 – Minterms, Maxterms, Karnaugh Map (K-Map) and Universal Gates: Minterms, Maxterms, Karnaugh Map (K-Map) to simplify Boolean Func- tions,Don’tCareConditionsandUniversalGates. Chapter 4 – Combinational Logic: Analysis of Combination Logic, Design of Combinational Logic, Decoder, Encoder, Multiplexer, Half Adder, Full Adder, Binary Adder, Binary Subtractor, Designing Arithmetic Logic Unit (ALU) and BCDtoSevenSegmentDecoder. Chapter5–SynchronousSequentialLogic:SequentialLogicsuchasS-RLatch, D-Flip Flop, J-K Flip Flop, T-Flip Flop, Register, Shift Register, Analysis of Sequential Logic, State Diagram, State Table, Flip Flop Excitation Table and DesigningCounter. Chapter 6 – Introduction to Computer Architecture: Components of a Micro- computer,CPUTechnology,CPUArchitecture,InstructionExecution,Pipelining, PCI,PCIExpress,USB,andHDMI. Chapter 7 – Memory: Memory including RAM, SRAM, DISK, SSD, Memory Hierarchy, Cache Memory, Cache Memory Mapping Methods, Virtual Memory, PageTableandthememoryorganizationofacomputer. Chapter8–ARMArchitectureandInstructionsPartI:ARMProcessorArchi- tecture,andARMInstructionSetsuchasDataProcessing,Shift,Rotate,Uncondi- tionalInstructionsandConditionalInstructions,StackOperation,Branch,Multiply InstructionsandseveralexamplesofconvertingHLLtoAssemblylanguage. Chapter 9 – ARM Instructions Part II: This chapter is the continuation of Chapter 8 which covers Load and Store Instructions, Pseudo Instructions, ARM AddressingModeanddatarepresentationinmemory. Chapter10–ARMAssemblyLanguageProgrammingUsingKeilDevelopment Tools:CovershowtouseKeildevelopmentsoftwareforwritingassemblylanguage usingARMInstructions,CompilingAssemblyLanguageandDebugging. InstructionResources:Theinstructionresourcescontains • LaboratoryexperimentsusingLogisim. • Solutionstotheproblemsofeachchapter. NewHaven,CT,USA AtaElahi Contents 1 SignalsandNumberSystems. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 AnalogSignals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2.1 CharacteristicsofanAnalogSignal. . . . . . . . . . . . . . 3 1.3 DigitalSignals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.4 NumberSystem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.4.1 ConvertingfromBinarytoDecimal. . . . . . . . . . . . . 6 1.4.2 ConvertingfromDecimalIntegertoBinary. . . . . . . . 7 1.4.3 ConvertingDecimalFractiontoBinary. . . . . . . . . . . 8 1.4.4 ConvertingfromHextoBinary. . . . . . . . . . . . . . . . . 9 1.4.5 BinaryAddition. . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.5 ComplementandTwo’sComplement. . . . . . . . . . . . . . . . . . 11 1.5.1 SubtractionofUnsignedNumberUsingTwo’s Complement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.6 Unsigned,SignedMagnitude,andSignedTwo’s ComplementBinaryNumber. . . . . . . . . . . . . . . . . . . . . . . . . 12 1.7 BinaryAdditionUsingSignedTwo’sComplement. . . . . . . . . 13 1.8 FloatingPointRepresentation. . . . . . . . . . . . . . . . . . . . . . . . 14 1.8.1 SinglePrecisionRepresentation. . . . . . . . . . . . . . . . 15 1.9 Binary-CodedDecimal(BCD). . . . . . . . . . . . . . . . . . . . . . . . 16 1.10 CodingSchemes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.10.1 ASCIICode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.10.2 UniversalCodeorUnicode. . . . . . . . . . . . . . . . . . . . 17 1.11 ParityBit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.12 Clock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.13 TransmissionModes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 1.13.1 AsynchronousTransmission. . . . . . . . . . . . . . . . . . . 22 1.13.2 SynchronousTransmission. . . . . . . . . . . . . . . . . . . . 23 1.14 TransmissionMethods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 1.14.1 SerialTransmission. . . . . . . . . . . . . . . . . . . . . . . . . 24 1.14.2 ParallelTransmission. . . . . . . . . . . . . . . . . . . . . . . . 24 1.15 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2 BooleanLogicsandLogicGates. . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.2 BooleanLogicsandLogicGates. . . . . . . . . . . . . . . . . . . . . . 30 2.3 IntegratedCircuit(IC)Classifications. . . . . . . . . . . . . . . . . . 33 2.4 BooleanAlgebraTheorems. . . . . . . . . . . . . . . . . . . . . . . . . . 36 2.5 BooleanFunction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.6 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 3 Minterms,Maxterms,KarnaughMap(K-Map), andUniversalGates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 3.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 3.2 Minterms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 3.3 Maxterms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 3.4 KarnaughMap(K-Map). . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 3.4.1 Three-VariableMap. . . . . . . . . . . . . . . . . . . . . . . . . 53 3.4.2 Four-VariableK-Map. . . . . . . . . . . . . . . . . . . . . . . . 57 3.5 SumofProducts(SOP)andProductofSums(POS). . . . . . . . 58 3.6 Don’tCareConditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 3.7 UniversalGates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 3.7.1 UsingNANDGates. . . . . . . . . . . . . . . . . . . . . . . . . 62 3.7.2 UsingNORGates. . . . . . . . . . . . . . . . . . . . . . . . . . 63 3.7.3 ImplementationofLogicFunctionsUsingNAND GatesorNORGatesOnly. . . . . . . . . . . . . . . . . . . . 64 3.7.4 UsingNANDGates. . . . . . . . . . . . . . . . . . . . . . . . . 64 3.7.5 UsingNORGates. . . . . . . . . . . . . . . . . . . . . . . . . . 65 3.8 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 4 CombinationalLogic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 4.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 4.2 AnalysisofCombinationalLogic. . . . . . . . . . . . . . . . . . . . . . 72 4.3 DesignofCombinationalLogic. . . . . . . . . . . . . . . . . . . . . . . 72 4.4 Decoder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 4.4.1 ImplementingaFunctionUsingaDecoder. . . . . . . . 76 4.5 Encoder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 4.6 Multiplexer(MUX). . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . 77 4.6.1 DesigningLargeMultiplexerUsingSmaller Multiplexers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 4.6.2 ImplementingFunctionsUsingMultiplexer. . . . . . . . 83 4.7 HalfAdder,FullAdder,BinaryAdder,andSubtractor. . . . . . 84 4.7.1 4-BitBinaryAdder. . . . . . . . . . . . . . . . . . . . . . . . . 87 4.7.2 Subtractor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 4.8 ALU(ArithmeticLogicUnit). . . . . . . . . . . . . . . . . . . . . . . . 88 4.9 Seven-SegmentDisplay. .. . . . .. . . . .. . . . .. . . . . .. . . . .. 89 4.10 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 5 SynchronousSequentialLogic. . . . . . . . . . . . . . . . . . . . . . . . . . . 97 5.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 5.2 S-RLatch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 5.3 DFlip-Flop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 5.4 J-KFlip-Flop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.5 TFlip-Flop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 5.6 Register. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 5.7 FrequencyDividerUsingJ-KFlip-Flop. . . . . . . . . . . . . . . . . 102 5.8 AnalysisofSequentialLogic. . . . . . . . . . . . . . . . . . . . . . . . . 104 5.9 StateDiagram. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . 106 5.10 Flip-FlopExcitationTable. . . . . . . . . . .. . . . . . . . . . . . . .. . 107 5.11 Counter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 5.12 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 6 IntroductiontoComputerArchitecture. . . . . . . . . . . . . . . . . . . . 115 6.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 6.2 ComponentsofaMicrocomputer. . . . . . . . . . . . . . . . . . . . . . 115 6.2.1 CentralProcessingUnit(CPU). . . . . . . . . . . . . . . . . 116 6.2.2 CPUBuses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 6.2.3 32-BitVersus64-BitCPU. . . . . . . . . . . . . . . . . . . . 118 6.3 CPUTechnology. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 6.4 CPUArchitecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 6.5 IntelMicroprocessorFamily. . . . . . . . . . . . . . . . . . . . . . . . . 120 6.6 MulticoreProcessors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 6.7 CPUInstructionExecution. . . . . . . . . . . . . . . . . . . . . . . . . . 123 6.8 DiskController. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 6.9 MicrocomputerBus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 6.9.1 ISABus. . . . .. . . . . .. . . . .. . . . . .. . . . .. . . . . .. 127 6.9.2 MicrochannelArchitectureBus. . . . . . . . . . . . . . . . . 127 6.9.3 EISABus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 6.9.4 VESABus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 6.9.5 PCIBus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 6.9.6 UniversalSerialBUS(USB). . . . . . . . . . . . . . . . . . . 128 6.9.7 USBArchitecture. . . . . . . . . . . . . . . . . . . . . . . . . . . 129 6.9.8 PCIExpressBus. . . . . . . . . . . . . . . . . . . . . . . . . . . 131 6.9.9 PCIExpressArchitecture. . . . . . . . . . . . . . . . . . . . . 131 6.9.10 PCIExpressProtocolArchitecture. . . . . . . . . . . . . . 132 6.10 FireWire. .. . . . . . . .. . . . . . .. . . . . . .. . . . . . .. . . . . . .. . 132 6.10.1 HDMI(High-DefinitionMultimediaInterface). . . . . . 133 6.11 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 7 Memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 7.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 7.2 SemiconductorMemory. . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 7.3 HardDisk. .. . . . . . . . . . . .. . . . . . . . . . . .. . . . . . . . . . . .. 142 7.4 Solid-StateDrive(SSD). . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 7.5 MemoryHierarchy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 7.5.1 VirtualMemory. . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 7.5.2 MemoryOrganizationofaComputer. . . . . . . . . . . . 155 8 AssemblyLanguageandARMInstructionsPartI. . . . . . . . . . . . 161 8.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 8.2 InstructionSetArchitecture(ISA). . . . . . . . . . . . . . . . . . . . . 162 8.2.1 ClassificationofInstructionBasedon NumberofOperands. . . . . . . . . . . . . . . . . . . . . . . . 162 8.3 ARMProcessorArchitecture. . . . . . . . . . . . . . . . . . . . . . . . . 163 8.4 ARMRegisters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 8.5 ARMInstructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 8.5.1 DataProcessingInstructions. . . . . . . . . . . . . . . . . . . 167 8.5.2 CompareandTestInstructions. . . . . . . . . . . . . . . . . 169 8.5.3 RegisterSwapInstructions(MOVandMVN). . . . . . 170 8.5.4 ShiftandRotateInstructions. . . . . . . . . . . . . . . . . . . 171 8.5.5 ARMUnconditionalInstructionsandConditional Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 8.6 ARMDataProcessingInstructionFormat. . . . . . . . . . . . . . . 174 8.7 StackOperationandInstructions. . . . . . . . . . . . . . . . . . . . . . 177 8.8 Branch(B)andBranchwithLinkInstruction(BL). . . . . . . . . 178 8.8.1 BandBLInstructionFormat. . . . . . . . . . . . . . . . . . 179 8.9 Multiply(MUL)andMultiply-Accumulate (MLA)Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 8.9.1 MultiplyInstructionFormat. . . . . . . . . . . . . . . . . . . 180 8.10 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 8.11 ProblemsandQuestions. . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 9 ARMInstructionsPartII. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 9.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 9.2 ARMDataTransferInstructions. . . . . . . . . . . . . . . . . . . . . . 185 9.2.1 ARMPseudoInstructions. . . . . . . . . . . . . . . . . . . . . 186 9.2.2 StoreInstructions(STR). . . . . . . . . . . . . . . . . . . . . . 187 9.3 ARMAddressingMode. . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 9.3.1 ImmediateAddressing. . . . . . . . . . . . . . . . . . . . . . . 188 9.3.2 Pre-indexed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 9.3.3 Pre-indexedwithWriteBack. . . . . . . . . . . . . . . . . . 189 9.3.4 Post-indexAddressing. . . . . . . . . . . . . . . . . . . . . . . 190 9.4 SwapMemoryandRegister(SWAP). . . . . . . . . . . . . . . . . . . 191 9.5 BitsFieldInstructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 9.5.1 BFC(BitFieldClearInstruction). . . . . . . . . . . . . . . 191 9.5.2 BFI(BitInsertionInstruction). . . . . . . . . . . . . . . . . . 192 9.6 DataRepresentationandMemory. . . . . . . . . . . . . . . . . . . . . 192 9.7 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 10 ARMAssemblyLanguageProgrammingUsingKeil DevelopmentTools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 10.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 10.2 KeilDevelopmentToolsforARMAssembly. . . . . . . . . . . . . . 198 10.2.1 AssemblingaProgram. . . . . . . . . . . . . . . . . . . . . . . . 201 10.2.2 RunningtheDebugger/Simulator. . . . . . . . . . . . . . . . 204 10.2.3 ProgramTemplate. . . . . . . . . . . . . . . . . . . . . . . . . . . 208 10.3 ProgrammingRules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 10.4 DataRepresentationandMemory. . . . . . . . . . . . . . . . . . . . . . 209 10.5 Directives. .. . . . . . . .. . . . . . .. . . . . . .. . . . . . .. . . . . . .. . 209 10.5.1 DataDirective. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 10.6 MemoryinμVisionv5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 10.7 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 Appendix:DigitalDesignLaboratoryExperiments UsingLOGISIM. . . .. . . . . . . . .. . . . . . . . . .. . . . . . . . .. . . . . . . . . .. 217 References. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 Chapter 1 Signals and Number Systems Objectives:Aftercompletingthischapter,youshouldbeableto: (cid:129) Explainthebasiccomponentsofacomputer. (cid:129) Distinguishbetweenanaloganddigitalsignal. (cid:129) Learnthecharacteristicsofsignal. (cid:129) Convertdecimalnumberstobinaryandviceversa. (cid:129) Learnadditionandsubtractionofbinarynumbers. (cid:129) Representfloatingnumbersinbinary. (cid:129) Convertfrombinarytohexadecimalandviceversa. (cid:129) Distinguishbetweenserialandparalleltransmission. 1.1 Introduction Numericalvalueshavebecomeanintegralpartofourdailylives.Numericalvalues canberepresentedbyanalogordigital;examplesincludeananalogwatch,digital watch, or thermometer. The following are advantages of digital representation of numericalvaluescomparedtoanalogrepresentation: 1. Digitalrepresentationismoreaccurate. 2. Digitalinformationareeasiertostore 3. Digitalsystemsareeasiertodesign. 4. Noisehaslesseffect. 5. Digitalsystemscaneasilybefabricatedinanintegratedcircuit. A digital signal is a discrete signal (step by step), and an analog signal is a continuoussignal.Digitalsystemsarewidelyusedanditsapplicationscanbeseen in computers, calculators, and cell phones. In a digital system, information is transferredbetweencomponentsofthedigitalsystemintheformofdigitalsignals.