CPS 4150 Computer Organization Chapter 2-2 Fall 2006 Ching-Song Don Wei.

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

Chapter 3 Basic Input/Output
Instruction execution and sequencing
Chapter 2 Instruction Set Architecture
Addressing Modes (Week4)
There are two types of addressing schemes:
Instruction Set Architecture Classification According to the type of internal storage in a processor the basic types are Stack Accumulator General Purpose.
Memory Locatıons and Addresses (Week 3)
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
The University of Adelaide, School of Computer Science
Instruction Set Architecture & Design
TK 2633 Microprocessor & Interfacing
Execution of an instruction
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Room: Timbalan Pengarah Pusat Komputer Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 4: Introduction.
TK 2633 Microprocessor & Interfacing
Basic Input/Output Operations
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
Chapter
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
Machine Instruction Characteristics
CSC Computer Organization Lecture 4: Machine Instructions and Programs Terrence Mak.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Chapter 2-3 Addressing Modes
Chapter 2-2 Assembly Instructions Number Systems Number Systems Assembly Instructions Assembly Instructions Branch Branch Next Lecture Next Lecture  Addressing.
Execution of an instruction
MAL 3 - Procedures Lecture 13. MAL procedure call The use of procedures facilitates modular programming. Four steps to transfer to and return from a procedure:
Chapter 2-4 Subroutines and Stacks Subroutines Parameter Passing Stack Frame Additional Instructions Next Lecture   Chapter 3: ARM Instruction Set Architecture.
9/20/6Lecture 2 - Prog Model Architecture, Data Types and Addressing Modes.
55:035 Computer Architecture and Organization Lecture 2.
Introduction to Computer Organization and Architecture Lecture 2 By Juthawut Chantharamalee wut_cha/home.htm.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Topics covered: Instruction Set Architecture CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Computer Architecture Lecture – 4.  Discussed individual functional units of the computer.  But to form a fully computational unit, they must be connected.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
What is a program? A sequence of steps
Second word first word Figure 2.5. Memory words. n bits last word i th word.
Computer Organization Instructions Language of The Computer (MIPS) 2.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
1 Pertemuan 5 Bahasa Rakitan: I Matakuliah: T0324 / Arsitektur dan Organisasi Komputer Tahun: 2005 Versi: 1.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Computer Architecture. Instruction Set “The collection of different instructions that the processor can execute it”. Usually represented by assembly codes,
Computer Organization
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Overview of Instruction Set Architectures
Figure 8.1 of course package
Microprocessor and Assembly Language
Machine Instructions and Programs contd:
Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 4 – The Instruction Set Architecture.
Microcomputer Programming
Computer Organization and Assembly Language (COAL)
ECE 445 CS1251 Computer Organization Carl Hamacher
Instructions - Type and Format
Figure 2.1. Binary, signed-integer representations.
Subroutines and the Stack
Chapter 8 Central Processing Unit
The University of Adelaide, School of Computer Science
ECEG-3202 Computer Architecture and Organization
Figure 8.1 of course package
ECEG-3202 Computer Architecture and Organization
Chapter 6 Programming the basic computer
Where is all the knowledge we lost with information? T. S. Eliot
Computer Organization and Assembly Language
COMPUTER ORGANIZATION AND ARCHITECTURE
Computer Operation 6/22/2019.
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

CPS 4150 Computer Organization Chapter 2-2 Fall 2006 Ching-Song Don Wei

2.6 Assembly Language Assembly program = mnemonics + syntax Assembly program (source program) assembler  object program MOVE R0,SUM Mnemonic MOVE represents the binary pattern (OP code). Register 0, source operands Destination, in memory  Absolute mode

2.6 Assembly Language Immediate mode ADD #5,R3 Or ADDI 5,R3 Indirect mode MOVE #5,(R2) OR MOVEI 5,(R2)

2.6.1 Assembly Directives For example: SUMEQU200 This directive informs assembler that the name SUM should be replaced by the value 200. No corresponding object code for this

NUM2 NUMn NUM1 R0Clear R0,SUM R1 #4,R2 (R2),R0 Figure Memory arrangement for the program in Figure SUM N LOOP Decrement Add Move #NUM1,R2 N,R1Move Branch>0

MemoryAddressing addressordata labelOperationinformation AssemblerdirectivesSUMEQU200 ORIGIN204 NDATAWORD100 NUM1RESERVE400 ORIGIN100 StatementsthatSTARTMOVEN,R1 generateMOVE#NUM1,R2 machineCLRR0 instructionsLOOPADD(R2),R0 ADD#4,R2 DECR1 BGTZLOOP MOVER0,SUM AssemblerdirectivesRETURN ENDSTART Figure Assembly language representation for the program in Figure Where to place data block First data Reserve 400 bytes Starting address

2.6.2 Execution of Program Two pass asembler – –As the assembler scans through a source program, it keeps track of all names and the numerical values that correspond to them in a symbol table. – –When a name appears a second time, it is replaced with its value from the table. – –But, when a name appears as an operand before it is given a value, it needs two-pass assembler.

2.7 Basic I/O operations

Register DATAIN, a status control flag, SIN, is set to 1 to inform the processor to read the contens of DATAIN. When the character is transferred to the processor, SIN is automatically cleared to 0. Same as in Display, when SOUT equals 1, the display is ready to receive character.

2.7 Basic I/O operations The processor monitors SOUT and when SOUT is set to 1, the processor transfers a character code to DATAOUT. The Buffer registers, DATAIN, DATAOUT, SIN and SOUT are part of circuitry called device interface.

2.7 Basic I/O operations Instructions to that can check the state of the status flags and transfer data between the processor and the I/O. For DATAIN and SIN in Keyboard READWAITBranch to READWAIT if SIN = 0 input from DATAIN to R1 Initial state of SIN is 1. The branch operation normally implemented by two machine instruction.

2.7 Basic I/O operations For DATOUT and SOUT in display READWAITBranch to READWAIT if SOUT = 0 input from R1 to DATAOUT Initial state of SOUT is 0 The branch operation normally implemented by two machine instruction.

2.7 Basic I/O operations In memory-mapped I/O, which some memory address values are used to refer to peripheral device buffer registers such as DATAIN and DATAOUT. Include bit b 3 in device registers INSTATUS and OUTSTATUS corresponds to SIN and SOUT, respectively.

2.7 Basic I/O operations The implementation of READ and WRITE operations can be implemented by machine instruction sequence: READWAITTestbit#3,INSTATUS Branch=0READWAIT MoveByteDATAIN,R1 WRITEWAIT Testbit#3,OUTSTATUS Branch=0WRITEWAIT MoveByteR1,DATAOUT

Move#LOC,R0InitializepointerregisterR0topointtothe addressofthefirstlocationinmemory wherethecharactersaretobestored. READTestBit#3,INSTATUSWaitforacharactertobeentered Branch=0READinthekeyboardbufferDATAIN. MoveByteDATAIN,(R0)TransferthecharacterfromDATAINinto thememory(thisclearsSINto0). ECHOTestBit#3,OUTSTATUSWaitforthedisplaytobecomeready. Branch=0ECHO MoveByte(R0),DATAOUTMovethecharacterjustreadtothedisplay bufferregister(thisclearsSOUTto0). Compare#CR,(R0)+CheckifthecharacterjustreadisCR (carriagereturn).IfitisnotCR,then Branch 00 READbranchbackandreadanothercharacter. Also,incrementthepointertostorethe nextcharacter. Figure A program that reads a line of characters and displays it.

2.8 Stacks and Queues In order to organize the control and information linkage between the main and subroutine, a data structure, stack is used. LIFO last in first out with push and pop operations. The first element is placed in location of BOTTOM.

2.8 Stacks and Queues Figure A stack of words in the memory. register Stack pointer 17 BOTTOM 0 SP Current top element element Bottom Stack 2 k

2.8 Stacks and Queues A processor register is used to keep track of the address of the element of the stack that is at the top at any time. For a byte-addressable memory with 32-bit word length, the push operation : Subtract#4,SP MoveNEWITEM,(SP)

2.8 Stacks and Queues Subtract 4 from SP and places the new information in location pointed by SP Move word from location NEWITEM onto the top of the stack. The pop operation: Move(SP),ITEM Add#4,SP

2.8 Stacks and Queues For autoincrement and Autodecrement addressing mode: MoveNEWITEM,-(SP) Move(SP)+,ITEM

Figure Effect of stack operations on the stack in Figure (b) After pop into ITEM(a) After push from NEWITEM ITEM SP Stack SP NEWITEM

2.8 Stacks and Queues Check the stack location before pop and push operation.

SAFEPOPCompare#2000,SPChectoseeifthestackpointercontains Branch>0EMPTYERRORanaddressvaluegreaterthan2000.Ifit does,thestackisempty.Branchtothe routineEMPTYERRORforappropriate action. Move(SP)+,ITEMOtherwise,popthetopofthestackinto memorylocationITEM. SAFEPUSHCompare#1500,SPChecktoseeifthestackpointer Branch0FULLERRORcontainsanaddressvalueequal toorlessthan1500.Ifitdoes,the stackisfull.Branchtotheroutine FULLERRORforappropriateaction. MoveNEWITEM,(SP)Otherwise,pushtheelementinmemory locationNEWITEMontothestack.  – Figure Checking for empty and full errors in pop and push operations. (b) Routine for a safe push operation (a) Routine for a safe pop operation

2.9 Subroutines The way in which a computer makes it possible to call and return from subroutines is referred to as its subroutine linkage. The returning address is stored in a register called link register. The subroutine Call instruction is just a special branch instruction that performs the following operations:

2.9 Subroutines – –Store the contents of the PC in the link register – –Branch to the target address specified by the instruction The Return instruction: – –Branch to the address contained in the link register

2.9 Subroutines ReturnCall Figure Subroutine linkage using a link register Link PC Return 1000 location Memory Calling program Memory location Call SUB next instruction Subroutine SUB first instruction

2.9.1 Nested Subroutines Subroutine nesting: – –One subroutine calls another anther subroutine. The return addresses are generated and used in a last-in-first-out order. A stack, called processor stack, can be used for this purpose. A register is designated as the stack pointer, SP.

2.9.1 Nested Subroutines The Call instruction pushes the contents of the PC onto the processor stack and loads the subroutine address into the PC. The Return instruction pops the return address from the processor stack into the PC.

2.9.2 Parameter Passing Many ways to implement parameter passing: – –Placed in processor registers – –Placed in processor stack If processor register is used: – –The register can be accessed by subroutine and calling program.

2.9.2 Parameter Passing Callingprogram MoveN,R1R1servesasacounter. Move#NUM1,R2R2pointstothelist. CallLISTADDCallsubroutine. MoveR0,SUMSaveresult.... Subroutine LISTADDClearR0Initializesumto0. LOOPAdd(R2)+,R0Addentryfromlist. DecrementR1 Branch >0 LOOP Return tocallingprogram.

2.9.2 Parameter Passing Using stack is more flexible

Assumetopofstackisatlevel1below. Move#NUM1,(SP)Pushparametersontostack. MoveN,(SP) CallLISTADDCallsubroutine (topofstackatlevel2). Move4(SP),SUMSaveresult. Add#8,SPRestoretopofstack (topofstackatlevel1).... LISTADDMoveMultipleR0R2,(SP)Saveregisters (topofstackatlevel3). Move16(SP),R1Initializecounterton. Move20(SP),R2Initializepointertothelist. ClearR0Initializesumto0. LOOPAdd(R2)+,R0Addentryfromlist. DecrementR1 Branch >0 LOOP MoveR0,20(SP)Putresultonthestack. MoveMultiple(SP)+,R0R2Restoreregisters. Return tocallingprogram. [R2] [R1] [R0] Returnaddress n NUM1 Level3 Level2 Level1 – – ––    Figure Program of Figure 2.16 written as a subroutine; parameters passed on the stack. (a) Calling program and subroutine (b) Top of stack at various times –

2.9.3 The Stack Frame The space – stack frame constitute a private work space for the subroutine, created at the time the subroutine is entered and freed up when the subroutine returns control to the calling program. Frame pointer (FP) is for convenient access to the parameters passed to the subroutine and to the local memory variables used by subroutine only.

2.9.3 The Stack Frame The parameter can be accessed by using addresses 8(FP), 12(FP), … The content of FP remains fixed throughout the execution of the subroutine. The content of SP always points to the top element in the stack.

2.9.3 The Stack Frame Figure A subroutine stack frame example. SP (stack pointer) FP (frame pointer) saved [R1] saved [R0] Stack frame for called subroutine Return address localvar3 localvar2 localvar1 saved [FP] Old TOS param2 param1 param3 param4 (top-of-stack)

2.9.3 The Stack Frame Four parameters are pushed into stack Return address of calling program is pushed into stack Saving the current content of FP Copy the SP to the FP Allocate the space for local variables Saving the current content of R1 and R2 into stack.

2.9.3 The Stack Frame Subroutine is now executing its task. When subroutine is done, the subroutine pops the saved value of R1 and R0 back into those registers, removes the local variables from the stack frame Old value of FP  FP Return address will be used for returning to calling program