You are on page 1of 16
ONLINE © JAIN Self-Learning Material : MCA tion: All Semester: 1 Course Name: Computer Organization & Architecture Course Code: 21VMCOC105 Unit Name: Machine Instructions and Programs Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. This file is meant for personal use by nandinibj.hp@gmail.com only. Sharing or publishing the contents in part or full is liable for legal action, Table of Contents UNIT2 1 Overview 1 Objectives 1 Leaming Outcomes 1 Pre-Unit Preparatory Material 2 2.1. Introduction 2 2.2 Assembly Language 3 2.3 Basic Input and Output Operations 7 24 Subroutines 10 2.5 Additional Instructions ul 2.6 Encoding of Machine Instructions 12 2.7 Conclusion 12 28 Glossary 14 Post-Unit Reading Material 18 References 19 Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. This file is meant for pérsonal use by nandinibj.hp@gmail.com only. Sharing or publishing the contents in part or ful is liable for legal action, UNIT 2 MACHINE INSTRUCTIONS AND PROGRAMS ‘Addressing Modes, Assembly Language, Basic Input and Output Operations, Subroutines, Additional Instructions, Encoding of Machine Instructions, +« Overview The methods for addressing typically used to access operations at processor registers & memory locations are addressed. The emphasis is on the fundamental concepts. We use a traditional way to define the system instructions & operating procedures typical of processors. Ensuring that we present complete and practical programming with simple tasks, appropriate instructions and methods of addressing are implemented. At the assembly language stage, these general programs are listed. Symbolic names are displayed in assembly language as computer instructions and addressing data. This unit deals with the machine instructions, Basic Input and Output Operations, Additional Instructions, and Assembly Language. + Objectives You'll learn in this unit — 1. Computer instructions and execution of the program, including call and return branching and subroutine operations. 2. Computer commands, data and programs assembly language. 3. Input/Output Program-controlled. 4, Address register and memory operand access methods. + Learning Outcomes At the end of this Unit, you would - ¥ Recall & Understand Addres ing Methods ¥ Assembly Language for representing machine instructions Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. ‘This file is meant for personal use by nandinibj.hp@gmail.com only. Sharing or publishing the contents in part or full is liable for legal action, + Pre-Unit Preparatory Material > “Varinder Hennessy J., Patterson D.: Computer Architecture: a quantitative approach, second edition, Morgan Kaufmann Publishers, Ine, San Francisco, 1997” > Flynn, M. J.: Computer Architecture: Pipelined and parallel processor design, Jones & Bartlett, 1995. 2.11Introduction Machine code is a series of instructions directed by a central processing unit of a computer (CPU). The tasks performed by the instructions, such as a load, a jump, or an ALU operation, in a CPU register or memory on a data unit. A sequence of such instructions is included in each program directly implemented by a CPU. The machine instruction's general format. [Label:] Mnemonic [Operand, Operand] [; Comments] * Brackets specify that a field is optional + Mark is a first byte address of the instruction in which it appears allocated to the label.. It must be followed by “:” ‘© Space inclusion is subjective, except for adding at least one space; no space contributes to uncertainty. ‘* Comment field begins with a semicolon “ Example Here: MOV RS5,#25H ;load 25H into RS Computer Instructions are commands or programs that can be recognized and executed in a machine code (computer). © A computer instruction requires multiple bytes in the memory informing the processor to run a single machine ‘+ Inthe main memory, the processor sees machine instructions and performs one operation per machine for each instruction, © The set is named the machine language program for main memory instructions Proprietary content. Alll rights reserved. Unauthorised use or distribution prohibited. ‘This file is melant for personal use by nandinibj.hp@gmail.com only. ‘Sharing or publishing the contents in part or full is liable for legal action, 2.2Assembly Language We now have a few clear examples of language assembly programmes. Typically a program works on the data in the memory of the machine, This knowledge can be arranged in a number of ways. We can write them into a list if we want to keep track of the names of the students. In order to provide information with names such as telephone numbers or marks in different classes, this information can be organized in a table format, The programmers use the so-called data structures organizations to represent the measured data. That includes lists, arrays, queues, etc. Programs typically provide high-level written language, so that constants, local and global variables, indicators and arrays can be used by the programmer. The programmer should be able to use the devices in the instruction set of the machine on which the program is carried out in the assembly language while converting a high level of language into assembly language. The numerous ways that an operand position is defined in a statement are referred to as address modes. The most important approaches found in modem processors can be found in this section.A summary is provided in Table 2.1 Table 2.1 Generic addressing modes Name Assembler syntax Addressing function immediate value Operand= Value Register Ri BA = Ri Absolute (Direct) Loe BA = Loc Indirect (Re) EA = [Rd (Loc) EA = [LOC] Index x(RD EA = [Ri] Base with index (RiRD EA=(R] [RI Base with index X(RLRA) EA= IR [RJ and offset Relative x(Ppe) EA = [PC] Autoincrement (RD+ EA = [Ri] Autodecrement (RD EA = effective address Value =a signed number Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. This file is meant for personal use by nandinibj.hp@gmail.com only. Sharing or publishing the contents in part or ful is liable for legal action, ‘An instruetion's operational area defines what to do. This procedure is performed on some data that is contained in the main or machine records. The selection of an operand depends on the style of the instruction during the program.. The purpose of the use of address modes is: 1) To offer programming flexibility to the consumer. 2) Reduces the bits number in the command sector. Forms of Ways of addressing Below, we spoke one by one about various forms of modes: 1) Immediate Mode The operand is stated in this mode in the instructions themselves. An immediate style command has an operand field instead of an address field, ADD 7, which means Add 7 to the accumulator material, for example. Here, 7 is an operand. 2) Register Mode The operand is stored in the register in this mode and is placed on the CPU. You can enter the address of the register where the operand is stored in the instructions. Instruction SE recsteraaes The instructions in this style specify a register which contains the operand’s memory address. 3) Register Indirect Mode ‘The register thus comprises the operand address slightly more than the operand. Proprietary content. Alll rights reserved. Unauthorised use or distribution prohibited. This file is meant for personal use by nandinibj.hp@gmail.com only ‘Sharing or publishing the contents in part or full is liable for legal action, instruction (BBBRE ornare = ‘Operand 4) Auto Increment/Decrement Mode ‘Therefore, after or before its value has been used, the register is increased or decreased. 5) Direct Addressing Mode In this mode, the operand address itself is efficient. # Single data access memory comparison. © no further estimate to find the operand’s effective address. = temooy [Oo Gass a For example: ADD R1, 4000 — The 4000 is an efficient operating address. NOTE: The position where operand is present would be an effective address. ©) Indirect Addressing Mode ‘The address box indicates the address where the successful memory address is located in this situation. This slows down running, as it involves several operand memory searches. Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. ‘This file is méant for personal use by nandinibj.hp@gmail.com only. Sharing or publishing the contents in part or ful is liable for legal action, (ie stress memory Cal to = Operand 7) Displacement Addressing Mode In order to obtain the effective address of the operand, the contents of the indexed register relate to the address portion of the instruction. EA =A + (R), Two values A, baseline value, and R are present in the address field, displacement value or inversely. This address field contains two values. 8) Relative Addressing Mode It is a mode change variant of Displacement. ‘This incfudes PC(Program Counter) contents to address the portion of the active address instructions, EA ~A + (PC), where EA is an effective address & PC is program counter. The operand is A cell outside the present cell (the one pointed to by PC). 9) Base Register Addressing Mode It is another variant of the mode addressing Displacement. This can be described as EA = A + (R), with A being displaced & R keeping the baseline point. 10) Stack Addressing Mode The operand is in this mode at the top of the stack. For instance, this command will POP the top two items from the stack, add them, and then PUSH the result to the top of the stack, Benefits of Assembly Language Awareness of the assembly language offers: © OS, processor & BIOS interface of programs; Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. This file is meant for personal use by nandinibj.hp@gmail.com only. Sharing or publishing the contents in part or ful is liable for legal action, © Memory data & other outside devices presentation; © How the processor accesses, executes, accesses & processes the data; © How to control external devices with software. Other benefits of using assembly language are: © less memory & running time are required; ¢ It enables difficult tasks in hardware-specifie ways; ¢ Itis suitable for time-critical jobs; ‘© Itis ideally suited to interrupt service and other resident memory applications. Syntax of Assembly Language Statements One statement per line is entered in assembly language statements. The following format is applied in each statement: There are optional fields in the square brackets. There are two parts of the basic instruction, the first is the instruction name (or mnemonic) to be executed and the second is the criteria for the operand or command.Below are some examples of common statements of assembly language: 2.3Basic Input and Output Operations In the form of a byte sequence called stream data will be pa -d to/from the output/input unit, The stream from an input device is called the Input Operation, like a keyboard, to the main memory. On the other hand, streams flowing from the main memory to a computer such as a screen are known as the output operation. Systems input-output (1/0) transfers information between the main device storage and the outside world. The 1/0 framework contains /O devices (peripherals), 1/0 control units, and /O Proprietary content. All rights reserved. Unauthorised use of distribution prohibited. This file is meant for personal use by nandinibj.hp@gmail.com only. Sharing or publishing the contents in part or full is liable for legal action, transaction(s) software via the 1/0 operation chain. 1/0 may be categorized as serial, i.e., one bit at a time or in parallel to pass bit streams, Parallel devices have a broader data bus and can therefore send one or more bytes of data in words 1/0 is a concerted work of hardware and software, like any other operation in a computer system, For a particular 1/0 unit, a device driver is called the program executed for an I/O transaction. An example of a 1/0 transaction is to read a disk-to- memory block of data, This program is just a series of /O operations (instructive instructions), which allows data to be passed between peripheral devices and main memory (Q.V.) and to monitor the connected peripheral devices by the central processing unit (CPU). Thus, 1/0 operations are of two classes: ‘© control operations and © data transfer operations. CPU Managed 1/0 Input-output architectures can be classified into two major categories. In the first category the CPU has the burden of carrying out the transfers among the I/O device & the main memory. As the size of the system grows, this becomes a burden on the CPU and can slow down the whole system. Therefore, in the second category, which includes more sophisticated systems, I/O functions are largely delegated to other “smart” modules that can carry out I/O on their own with minimal intervention from the CPU discuss the simple architectures in which all 1/0 transfers take place between 1/0 devices and memory through the CPU. The following sections will discuss architectures in which /O is delegated to specialized control modules and data transfers do not go through the CPU Programmed 1/0 Programmed I/O is the most basic control device possible and requires minimal support to the hardware. The CPU is not only performing the 1/0 transaction in this case, but waiting for the system to be ready for transfer. In the 1170 structure of Fig. 1, the /O device interface provides a data register for exchange of data, and a control and status register to select the mode of operation and to determine whether the device is busy or ready for a transfer. The transfer of data between the 1/0 system & the CPU is performed by the data register on the data bus. Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. This file is meant for personal use by nandinibj.hp@gmail.com only. ‘Sharing or publishing the contents in part or full is liable for legal action, Input-output device Tnput-output interface CPU { Controi/status regi {Data register 1 itty “ Data bus y Address bus | Y /O read I yO write _| Figure 1. A typical programmed I/O configuration. Interrupt-Driven /0 External interrupts are individual processor inputs to notify a system event processor that needs processor intervention. Usually processors sample their inputs at the end of each instruction cycle. Should an interrupt request be found, the processor typically does not start the next instruction execution, Instead, the interrupting device is detected and the service requested by the device is performed.In one case, called the vectored interrupt method, the I/O device identifies itself to the CPU, e.g. by submitting a special identification number called the device number. In another method, called the polled interrupt, the CPU checks all the devices to find out which one is requesting the interrupt Direct Memory Access Systems ‘While vectored interrupts relieve the CPU of much of the control work that programmed I/O and even the polled-interrupt method need, the CPU is actually still heavily involved in the /O data transfers. To read a word from an 1/0 device to memory, this word must first be read from the device by the processor, then written by the processor to the memory. In addition, when reading or writing a big block of data, the processor has the burden of sequencing through the needed addresses. Devices like disks, which need to transfer large volumes of data at high rates, generally use direct memory access (DMA) controllers, which can act like a simple processor for the purpose of 1/0 operations. DMA controllers are capable of resolving device priorities, can read data from VO devices and write them to memory and vice versa without the intervention of the CPU, and can generate address sequences to access blocks of data. Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. ‘This file is meant for personal use by nandinibj.hp@gmail.com only. Sharing or publishing the contents in part or ful is liable for legal action, 2.4Subroutines A software consists of instructions to solve the problem, In a certain program, several times it is needed in different data values to perform a particular sub-task. Therefore, the program is divided into smaller units to solve some of the problems. This is defined as tasks, processes or subroutines. We use the word subroutine in mounting languages to distinguish the functions that are used in other programming languages from those that were used for each subprogram in assembly languages. The subroutine block of instructions can be included in the main program any time this task is required. This might, however, contribute to needless space waste. Rather, only one copy of the subroutine instructions is stored in the memory & can be repeatedly accessed. Components of Subroutines A Janguage assembly routine: 1) Anentry point: The first instruction is located in the routine. 2) Parameters: The list of records or storage places containing routine parameters, 3) Return values: List of documents or memory locations for data saving. 4) Working storage: The registries or memory place for the routine to accomplish its job. Calling Subroutines Behind the subroutine are two ideas: 1) You should be able to call the subroutine from anywhere, 2) After completing the subroutine, it should return to the position the subroutine was named. Specific instructions are available to pass control over subroutines and restore control of the main program.The command transferring control is generally referred to as a call, jump, or subroutine branch. The calling program is called Caller. The calling program is called Callee. The instruction that the caller is returned with power. To call a subroutine a deviation from the default sequential execution of instructions is needed. When a program branches into a sub-routine, the processor begins to execute the instructions to the subroutine (PC). Branching to subroutine in ARM is achieved via the Branch and Connect Instruction (BL). Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. This file is meant for personal use by nandinibj.hp@gmail.com only. Sharing or publishing the contents in part or full is liable for legal action, BL my-subroutine my-subroutiae points to the first line of a subroutine This command stores the current PC counter address in the LR before entering the start address of the program counter. Once the subroutine is finished, the processor must be able, immediately after the branch instruction which called the subroutine, to branch it back (return) to the instructions. The value stored in the link register is returned to a subroutine by the program counter which returns the control to the following command, So we can use the following instructions in order to return from the subroutine: Bx retura back to the instruction after the subroutine call Mov PC, LR serves the same purpose 2.5Additional Instructions Different kinds of machine commands must be adequate in a computer to express all of the HLL directions. Now let's talk about the kinds of instructions that need to be composed in a realistic machine. These are: 1) Data Processing Instruction It includes arithmetic & logic instructions. They are used for the arithmetic & logic of computers. Example of these instructions are: © Adding and subtracting arithmetic instructions ‘¢ Instructions for reasoning, like AND, OR and NOT. 2) Data Storage and retrieval Instruetions Since data processing is typically done in the CPU record on the data. Accordingly, instructions are required to carry data from and to the memory register. . These instructions are referred to as data storage & recovery instructions. Asan example: Store Instructions & Load 3) Data Moment Instructions These are primarily instructions for input/output, For program & data transfer to memory, as well as for user calculations, /O instructions are needed. That is, these instructions are used to Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. This file is meant for personal use by nandinibj.hp@gmail.com only. Sharing or publishing the contents in part or ful is liable for legal action, memorize and communicate the output system with programs and data from dififrent devices (specifically, the Input). Example: Input, Output & Move ete 4) Control Flow Instructions To control the flow of instructions, the flow instructions for the program are controlled. "Test instructions" are used to test machine status using the data word value & ,"Branch instructions" are used to bind to a diverse set of commands based on the choice taken, In addition, the branch instructions are often used for control transfer. 5) Miscellaneous Instructions There are some other instructions which are incompatible with each of the above definitions, For example, interrupting or monitoring call, stop orders, or any or more instructions on the operating system 2.6Encoding of Machine Instructions ‘A command must be stored in a Compact Binary pattern to be executed in a processor. These encoded commands are properly referred to as computer commands. The symbolic names and acronyms are called assembly language commands that are converted into computer commands by the assembler programme. We have seen guidelines that carry out activities such as remove, connect, rotate, pass, change & branch, These commands may use operands of various sizes, including ASCII characters encoded with 32-bit, 8-bit numbers, etc. A binary encoded template known as the OP code for that instruction can be used to identify the sort or the operand type of operand to be performed. Suppose to 8 bits, giving 256 options for specifying different instructions are allocated for such purposes. The remaining necessary information can be defined by 24 bits. 2.7 Conclusion Selecting i tructions enables one to convert an intermediate low Level code into the target machine assembly code. There are definitely several examples in which specific “unique” instructions can significantly boost a program's speed. We have rarely seen cases where the system Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. This file is meant for personal use by nandinibj.hp@gmail.com only. ‘Sharing or publishing the contents in part or full is liable for legal action, as a whole enjoys the same benefits. We assume that the careful pruning of a set is cost efficient in a large range of programming environments. The system architects should ask themselves these questions when designing a new set of instructions. Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. This file is meant for personal use by nandinibj.hp@gmail.com only. Sharing or publishing the contents in part or ful is liable for legal action, 2.8Glossary Address — A specific data source or des tion identification number (or locator). An address defines an operand’s registry or memory position in the instruction. Addressing Mode— How the effective address of source and destination operating in an instruction is calculated by the microcontroller. Assembly Language — A type of programming language of microcontroller with a semi-English sentence. Machine Language — A kind of microcontroller programming language with a six-part English word. Post-Unit Reading Material > Stallings, W: Computer Organization and Architecture: Principle of Structure and Function, fifth edition, MacMillan Publishing Company, 2002. > Patterson D., Hennessy J.: Computer Organization and Design: The Hardware/Software Interface, second edition, Morgan Kaufmann Publisher’s, San Mateo, 197. > Carpinelli J.D.: Computer Systems Organization & Architecture, first edition, Addison Wesley Longman, Boston, 2001 References 1. https://www.uet.edu.pk/pp/ee/~mtahir/EE371/EE371/Experiment_S.pdf 2. http:!/coagarage.blogspot.com/p/coa-instruction-types.html Proprietary content. All rights reserved. Unauthorised use or distribution prohibited. This file is meant for personal use by nandinibj.hp@gmail.com only. ‘Sharing or publishing the contents in part or full is liable for legal action,

You might also like