UNIT I ASSEMBLY LANGUAGE PROGRAMMING.pptx
Document Details
Uploaded by ZippyIndium
Tags
Full Transcript
MIT Art Design and Technology University MIT School of Computing, Pune Processor Architecture & Interfacing Class - S.Y. (SEM-I), Unit – I Assembly Language Programming Dr. Madhukar Nimbalkar & Prof. Bhushan Bhokse AY 2024-2025 SEM-I ...
MIT Art Design and Technology University MIT School of Computing, Pune Processor Architecture & Interfacing Class - S.Y. (SEM-I), Unit – I Assembly Language Programming Dr. Madhukar Nimbalkar & Prof. Bhushan Bhokse AY 2024-2025 SEM-I Course Objectives This course will enable the students: 1. Understand & learn assembly language programming. 2. Demonstrate programming proficiency using 8086,80386 microprocessors & ATmega microcontrollers to desigThis course will enable the students:n practically motivated systems. 3. Apply knowledge of the microprocessor, microcontroller & assembly language programming theory course to solve problems. This course will provide a bridge to future courses where alternative embedded system designs and their performance trade- offs will be studied in depth. 4. Relate and communicate effectively about the microprocessors, peripherals & microcontrollers used in the present gadgets. 5. Develop an ability to use the techniques, skills, and modern engineering tools to accommodate different practically-motivated circuits. Course Outcomes After completion of this course, students will be able to: 1. Write assembly level language program for performing arithmetic & string manipulation operation in microprocessor. 2. Describe the architecture & working of various units of Intel 8086 & 80386 microprocessor. 3. Explain memory organization, various addressing modes & instruction set of 8086 & 80386 microprocessor 4. Describe architecture of ATmega A328P microcontroller 5. Demonstrate interfacing of various sensors to ATmega A328P microcontroller Text Books 1. Barry Brey,” Intel Microprocessors – architecture, programming & interfacing’, 8th edition, Pearson Education/ Prentice Hall of India. 2. Brian Evans, “Beginning Arduino Programming”, Springer, 2011. Reference Books 1. Ray, K. Bhurchandi, “Advanced Microprocessors and peripherals: Architecture, Programming & Interfacing”, Tata McGraw Hill,2004 ISBN 0-07-463841-6. 2. Douglas Hall, “Microprocessors & Interfacing”, McGraw Hill, Revised 2nd Edition, 2006 ISBN 0-07-100462-9. 3. D. V. Hall. Microprocessors and Interfacing, TMGH. 2'1 editions 2006. 4. David Hanes, “IoT Fundamentals: Networking Technologies, Protocols, and Use Cases for the Internet of Things”, Cisco Press. 5. Walter A. Tribel, Avtar Singh, "The 8088 and 8086 Microprocessors", 4th edition, Prentice Hall of India. 6. James Turley, "Advanced 80386 Programming Techniques", McGraw Hill Education. Unit I - Syllabus Unit I – Assembly Language Programming 07 hours Introduction to microcomputer :Functional block: CPU, Memory, Input/Out devices, Types of architecture (Von- neuman, Harvard, CISC,RISC),Concept of program memory and data memory Introduction to assembly language programming ALP tools- Assembler, linker, loader, debugger, emulator concepts Assembler directives far and near procedures, macros. LINUX installation, LINUX basics, Introduction to NASM, LINUX internals & system functions. Debugging with GNU debugger. UNIT I Assembly Language Programming 7/13/2024 Introduction to Processors and Chips 7 Classification COMPUTERS MAINFRAMES MINICOMPUT MICROCOMPUT ERS ERS Difference between Microprocessor and Microcomputer Block Diagram of a Microcomputer Hardware Software Firmware Harvard & Von Neumann Architecture Harvard Architecture 7/13/2024 13 The Harvard Architecture Harvard architecture is a computer architecture with physically separate storage and signal pathways for instructions and data. The term originated from the Harvard Mark I relay-based computer, which stored instructions on punched tape (24 bits wide) and data in electro-mechanical counters (23 digits wide). These early machines had limited data storage, entirely contained within the data processing unit, and provided no access to the instruction storage as data, making loading and modifying programs an entirely offline process. 7/13/2024 14 The Harvard Architecture In a computer with a von Neumann architecture (and no cache), the CPU can be either reading an instruction or reading/writing data from/to the memory. Both cannot occur at the same time since the instructions and data use the same bus system. In a computer using the Harvard architecture, the CPU can read both an instruction and perform a data memory access at the same time, even without a cache. A Harvard architecture computer can thus be faster for a given circuit complexity because instruction fetches and data access do not contend for a single memory pathway. 7/13/2024 15 The Harvard Architecture In a Harvard architecture, there is no need to make the two memories share characteristics. In particular, the word width, timing, implementation technology, and memory address structure can differ. In some systems, instructions can be stored in read-only memory while data memory generally requires read-write memory. Instruction memory is often wider than data memory. 7/13/2024 16 Von Neumann Architecture Main Memory Address Interconnecti Data & Instruction on Interconnection Central Processing Unit Arithmet Register ic & Control Logic Unit Unit Data &Control Information Interconnection Input/Output 7/13/2024 System 18 Key Features of a Von Neumann machine Uses stored program concept. The program & data are stored in the same memory unit. Program memory= EPROM, Data memory=RAM Each location of the memory can be addressed independently. Execution of instruction in this machine is carried out in a sequential fashion from one instruction to the next. 7/13/2024 19 Von Neumann Architecture Memory holds data, instructions. Central processing unit (CPU) fetches instructions from memory. Separate CPU and memory distinguishes programmable computer. CPU registers help out: program counter (PC), instruction register (IR), general-purpose registers, etc. Combine program and data in 1 chunk of memory Example : 80x86 architecture 7/13/2024 20 CISC Feature Complex instruction set computer Large number of instructions (~200-300 instructions) Specialized complex instructions Many different addressing modes Variable length instruction format Memory to memory instruction For Example : 68000, 80x86 RISC Feature Reduced instruction set computer Relatively few number of instructions (~50) Basic instructions Relatively few different addressing modes Fixed length instruction format Only load/store instructions can access memory Large number of registers Hardwired rather than micro-program control For Example : MIPS, Alpha, ARM etc. RISC vs CISC CISC -- High Code Density Fewer instructions needed to specify the algorithm RISC -- Simpler to Design & Faster to Silicon Higher Performance -- smaller die size Lower power consumption Easier to develop compilers to take advantage of all features CISC – Advantages & Disadvantages Advantages of CISC Less expensive due to the use of microcode; no need to hardwire a control unit Upwardly compatible because a new computer would contain a superset of the instructions of the earlier computers Fewer instructions could be used to implement a given task, allowing for more efficient use of memory Simplified compiler, because the microprograminstruction sets could be written to match the constructs of high-level languages More instructions can fit into the cache, since the instructionsare not a fixed size Disadvantages of CISC Instruction sets and chip hardware became more complex with eachgeneration of computers, since earlier generations of a processor family were contained as a subset in every new version Different instructions take different amount of time to execute due to their variable- length Many instructions are not used frequently; Approximately 20% of the available instructions are used in a typical program 24 RISC – Advantages & Disadvantages Advantages of RISC Faster Simple hardware Shorter design cycle due to simpler hardware Disadvantages of RISC Programmer must pay close attention to instruction scheduling so that the processor does not spend a large amount of time waiting for an instruction to execute Debugging can be difficult due to the instruction scheduling Require very fast memory systems to feed them instructions Nearly all modern microprocessors, including the Pentium (hybrid RISC/CISC) PowerPC, Alpha and SPARC microprocessors are superscalar 25 Example of CPU Architectures Intel: 80x86 Motorola: 680x0 CISC Sun : Sparc Silicon Graphics : MIPS HP : PA-RISC RISC IBM: Power PC Compaq: Alpha What is Assembly Language? Each personal computer has a microprocessor that manages the computer's arithmetical, logical and control activities. Each family of processors has its own set of instructions for handling various operations such as getting input from keyboard, displaying information on screen and performing various other jobs. These set of instructions are called 'machine language instructions'. A processor understands only machine language instructions, which are strings of 1's and 0’s. However, machine language is too obscure and complex for using in software development. So, the low-level assembly language is designed for a specific family of processors that represents various instructions in symbolic code and a more understandable form. 7/13/2024 Introduction to Processors and Chips 27 Language used for programming Machine Assembly High level Language Language Language Binary codes Mnemonics English like statements Processor dependent Processor dependent Processor independent Require less memory Require less memory Require more memory Less execution time Less execution time More execution time Program development Program development Program development is difficult is simpler than m/c is easy language Not user friendly Less user friendly User friendly E.G:Machine E.G: Assembly E.G:BASIC,PASCAL,C Language language 7/13/2024 Introduction to Processors and Chips 28 E.g: Assembly E.g: Machine Language Language Mem. Address Binary Code Hex Operation MOV EAX,12H 00100H 1110100100 E4 INPUT FROM MOV EBX,13H 00101H 00000101 05 PORT 05 00102H 00000100 04 ADD ADD AX,BX 00103H 00000111 07 07H 00104H 11100110 E6 OUTPUT TO 00105H 00000010 02 PORT 02 7/13/2024 Introduction to Processors and Chips 29 Advantages of Assembly Language Having an understanding of assembly language makes one aware of − ⮚ How programs interface with OS, processor, and BIOS. ⮚ How data is represented in memory and other external devices. ⮚ How the processor accesses and executes instruction. ⮚ How instructions access and process data. ⮚ How a program accesses external devices. 7/13/2024 Introduction to Processors and Chips 30 Advantages of Assembly Language (cntd…..) ⮚ It requires less memory and execution time. ⮚ It allows hardware-specific complex jobs in an easier way. ⮚ It is suitable for time-critical jobs. ⮚ It is most suitable for writing interrupt service routines and other memory resident programs. 7/13/2024 Introduction to Processors and Chips 31 Environment Setup ❖Assembly language is dependent upon the instruction set and the architecture of the processor. For the practical, you will need ⮚ An IBM PC or any equivalent compatible computer. ⮚ A copy of Linux operating system. ⮚ A copy of NASM assembler program. 7/13/2024 Introduction to Processors and Chips 32 ❖There are many good assembler programs, such as − ⮚ Microsoft Assembler (MASM) ⮚ Borland Turbo Assembler (TASM) ⮚ The GNU assembler (GAS) ❖We will use the NASM assembler, as it is − ⮚ Free and can download it from various web sources. ⮚ Well documented and will get lots of information on net. ❖Could be used on both Linux and Windows 7/13/2024 Introduction to Processors and Chips 33 Assembly - Basic Syntax ⮚ An assembly program can be divided into three sections − ⮚ The data section, ⮚ The bss section, and ⮚ The text section. The data Section: ⮚ The data section is used for declaring initialized data or constants. This data does not change at runtime. ⮚ You can declare various constant values, file names, or buffer size, etc., in this section. ⮚ The syntax for declaring data section is − section.data 7/13/2024 Introduction to Processors and Chips 34 The bss Section ⮚The bss section is used for declaring variables. ⮚The syntax for declaring bss section is − section.bss The text section ⮚The text section is used for keeping the actual code. ⮚This section must begin with the declaration global _start , which tells the kernel where the program execution begins. ⮚The syntax for declaring text section is − section.text global _start _start: 7/13/2024 Introduction to Processors and Chips 35 Comments Assembly language comment begins with a semicolon (;). It may contain any printable character including blank. It can appear on a line by itself, like − ; This program displays a message on screen or, on the same line along with an instruction, like − add eax , ebx ; adds ebx to eax 7/13/2024 Introduction to Processors and Chips 36 Assembly Language Statements Assembly language programs consist of three types of statements − ⮚ Executable instructions or instructions, ⮚ Assembler directives or pseudo-ops, and ⮚ Macros. ▪The Executable instructions or simply instructions tell the processor what to do. Each instruction consists of an operation code (opcode). Each executable instruction generates one machine language instruction. ▪The assembler directives or pseudo-ops tell the assembler about the various aspects of the assembly process. These are non- executable and do not generate machine language instructions. ▪Macros are basically a text substitution mechanism. 7/13/2024 Introduction to Processors and Chips 37 Syntax of Assembly Language Statements Assembly language statements are entered one statement per line. Each statement follows the following format − [label] mnemonic [operands] [;comment] The fields in the square brackets are optional. A basic instruction has two parts, the first one is the name of the instruction (or the mnemonic), which is to be executed, and the second are the operands or the parameters of the command. Following are some examples of typical assembly language statements − INC COUNT ; Increment the memory variable COUNT MOV TOTAL, 48 ; Transfer the value 48 in the memory variable TOTAL ADD AH, BH ; Add the content of the BH register into the AH register AND MASK1, 128 ; Perform AND operation on the variable MASK1 and 128 ADD MARKS, 10 ; Add 10 to the variable MARKS MOV AL, 10 ; Transfer the value 10 to the AL register 7/13/2024 Introduction to Processors and Chips 38 Memory Segments ⮚ A segmented memory model divides the system memory into groups of independent segments referenced by pointers located in the segment registers. ⮚ Each segment is used to contain a specific type of data. ⮚ One segment is used to contain instruction codes, another segment stores the data elements, and a third segment keeps the program stack. 7/13/2024 Introduction to Processors and Chips 39 Data segment ⮚ It is represented by.data section and the.bss. ⮚ The.data section is used to declare the memory region, where data elements are stored for the program. ⮚ This section cannot be expanded after the data elements are declared, and it remains static throughout the program. ⮚ The.bss section is also a static memory section that contains buffers for data to be declared later in the program. ⮚ This buffer memory is zero-filled. 7/13/2024 Introduction to Processors and Chips 40 Code segment ⮚It is represented by.text section. ⮚This defines an area in memory that stores the instruction codes. ⮚This is also a fixed area. 7/13/2024 Introduction to Processors and Chips 41 Stack Segment ⮚This segment contains data values passed to functions and procedures within the program. 7/13/2024 Introduction to Processors and Chips 42 Assembly - Variables ⮚NASM provides various define directives for reserving storage space for variables. ⮚The define assembler directive is used for allocation of storage space. ⮚It can be used to reserve as well as initialize one or more bytes. 7/13/2024 Introduction to Processors and Chips 43 Allocating Storage Space for Initialized Data ⮚The syntax for storage allocation statement for initialized data is − [variable-name] define-directive initial-value [,initial-value]... ⮚Where, variable-name is the identifier for each storage space. The assembler associates an offset value for each variable name defined in the data segment. ⮚There are five basic forms of the define directive − Directive Purpose Storage Space DB Define Byte allocates 1 byte DW Define Word allocates 2 bytes DD Define Doubleword allocates 4 bytes DQ Define Quadword allocates 8 bytes DT Define Ten Bytes allocates 10 bytes ⮚Each decimal value is automatically converted to its 16-bit binary equivalent and stored as a hexadecimal number. ⮚Processor uses the little-endian byte ordering. Negative numbers are converted to its 2's complement representation. ⮚ Short and long floating-point numbers are represented using 32 or 64 bits, respectively. 7/13/2024 Introduction to Processors and Chips 44 Allocating Storage Space for Uninitialized Data ⮚The reserve directives are used for reserving space for uninitialized data. ⮚The reserve directives take a single operand that specifies the number of units of space to be reserved. ⮚Each define directive has a related reserve directive. ⮚There are five basic forms of the reserve directive − Directive Purpose RESB Reserve a Byte RESD Reserve a Doubleword RESQ Reserve a Quadword REST Reserve a Ten Bytes 7/13/2024 Introduction to Processors and Chips 45 Steps involved in programming Specify the problem Designing the problem solution Coding Debugging 7/13/2024 Introduction to Processors and Chips 46 Program Development Algorithm 7/13/2024 Introduction to Processors and Chips 47 Assembler Linker Loader Locator Debugger Emulator 7/13/2024 Introduction to Processors and Chips 48 Assembler ∙ Assembler translates source file into binary or object code. ∙ It reads the source file from the disk. ∙ Assembler generates 2 files on disk during two passes. ∙ Object file:Contains binary codes of the instructions & information about the addresses of the instructions. ∙ List file: Contains assembly language statements, binary codes for each instructions & the offset for each instruction. ∙ In the first pass assembler performs following operations: o Reading source program o Creating symbol table o Replacing all mnemonic codes by binary codes o Detecting any syntax errors o Assigning relative addresses to instructions and data. ∙ In the second pass it replaces the symbols in the operand field with the addresses from symbol table. 7/13/2024 Introduction to Processors and Chips 49 Linker ∙ Linker is a program used to join together several object files into one large object file. ∙ Linker produces a link file which contains the binary codes for all the combined modules. ∙ The linker also produces the link map which contains the address information about the link files. ∙ Linker generates re-locatable program which can be placed anywhere in memory. ∙ Linker generates.exe,.map files. 7/13/2024 Introduction to Processors and Chips 50 Loader ∙ The loader is a part of the operating system that brings an executable file residing on disk into memory. ∙ Loader is responsible for loading and relocation. ∙ Loaders are of 2 types ∙ Absolute loader: o This loader loads the file into memory at the location specified by the beginning portion of the file called header. Then the control is passed to the program. o It does not perform relocation and linking. ∙ Relocating loader: o It relocates the program in memory. o For calculating all the relative offsets, a delay is produced. 7/13/2024 Introduction to Processors and Chips 51 Locator A LOCATOR is a program used to assign the specific addresses of where the segments of object code are to be loaded into memory. E.g: A Locator program called EXE2BIN provided by IBM PC Disk operating system converts a.EXE file to a.BIN file which has physical addresses. 7/13/2024 Introduction to Processors and Chips 52 Debugger ∙ A debugger is a program which allows us to load our object code program in system memory, execute it and debug it. ∙ Debugger also allows us to stop execution after each instruction so we can check and alter memory and register contents. ∙ A debugger allows us to set a breakpoint at any point in our program. 7/13/2024 Introduction to Processors and Chips 53 Emulator ∙ An emulator is a combination of hardware and software. ∙ It is usually used to test and debug the hardware and software of an external system. ∙ The hardware part of the emulator consists of multi-wire cable which connects the host system to the system being developed. ∙ This connection is used to download object code program into RAM in the system being tested and run it with the help of software of emulator. ∙ Emulator also allows us to debug the program. ∙ It stores the trace data of the execution for future reference. 7/13/2024 Introduction to Processors and Chips 54 ASSEMBLER DIRECTIVES 7/13/2024 Introduction to Processors and Chips 55 ASSEMBLER DIRECTIVES Definition:-Assembler Directives are the statements which help us to control the manner in which a source program assembles and lists. Specialty:-This statements are effective only during the assembly of a program but they do not generate any code that is machine executable. 7/13/2024 Introduction to Processors and Chips 56.CODE Format:.CODE [name] This assembler directive indicates the beginning of the code segment. The name in this format is optional. In NASM🡪 section.text global _start Declaration of text section _start: 7/13/2024 Introduction to Processors and Chips 57.STACK Format:.STACK[size] This directive is used for defining the stack. By default the size is 1024 bytes. E.g..STACK;reserves 98 bytes for the stack 7/13/2024 Introduction to Processors and Chips 58 Initializing the STACK Method 1: ASSUME CS:CODE,DS:DATA,SS:STACK …….. …… STACK SEGMENT S-DATA DB 100 DUP(?) STACK ENDS 7/13/2024 Introduction to Processors and Chips 59 Method 2: Syntax:.STACK [SIZE] Example:.STACK 200 7/13/2024 Introduction to Processors and Chips 60.DATA Format:.DATA This directive indicates the beginning of the data segment. In NASM🡪 The syntax for declaring data section is − section.data 7/13/2024 Introduction to Processors and Chips 61 Define Byte [DB] Format: [name] DB initial value Numeric value or (?) This directive defines the byte type variable. The initial value can be a signed or unsigned number. Range: i)-128 to +127(for signed) ii)0 to 255(for unsigned) 7/13/2024 E.g. List DB 08HIntroduction to Processors and Chips 62 Define Word or Word [DW] Format: [name] DW initial value This directive defines items that are one word(2 bytes) in length. Range: i)0 to 65,535;unsigned numbers ii)-32,768 to +32767;signed numbers E.g. List DW 2534H 7/13/2024 Introduction to Processors and Chips 63 Define Double Word [DD] Format: [name] DD initial value It defines data items that are a double word(4 bytes) in length. It creates storage for 32-bit double words. E.g. List DD ? 7/13/2024 Introduction to Processors and Chips 64 Define Quad Word [DQ] Format: [name] DQ initial value, [initial value] This directive is used to tell the assembler to declare the variable of 4 words in length or to reserve 4 words of storage in memory. It may define one or more constants, each with a maximum of 8 bytes or 16 Hex digits. 7/13/2024 E.g. List DQ 1234567898765432H Introduction to Processors and Chips 65 Define Ten Bytes [DT] Format: [name] DT initial value ,[initial value] It is used to define the data items that are 10 bytes long. Unlike the other data directives which stores the hexadecimal numbers, DT will directly store the data in decimal form. E.g. List DT 1234567890 7/13/2024 Introduction to Processors and Chips 66 DUP Operator Format: [name] Data-Type Number DUP (value) Whenever we want to allocate space for a table or an array the DUP directive can be used. DUP operator will be used after a storage allocation directive like (DB,DW,DQ,DT,DD). With DUP, we can repeat one or more values while assigning the storage values. E.g. List DB 20 DUP(0) A list of 20 bytes, where each byte is 0. A DUP operator can be nested. 7/13/2024 Introduction to Processors and Chips 67 EQU-Equate Format: [name] EQU initial value It is used to give a name to some value or symbol in the program. Each time when the assembler finds that name in the program, it replaces that name with value assigned to that ‘r’ variable. E.g. FACTORIAL EQU 05H This statement is written during the beginning of the program and whenever now FACTORIAL appears in any instruction or another directive, the assembler substitute the value for it. 7/13/2024 Introduction to Processors and Chips 68 The %assign Directive The %assign directive can be used to define numeric constants like the EQU directive. This directive allows redefinition. For example, you may define the constant TOTAL as: %assign TOTAL 10 Later in the code you can redefine it as: %assign TOTAL 20 This directive is case-sensitive. 7/13/2024 Introduction to Processors and Chips 69 The %define Directive The %define directive allows defining both numeric and string constants. This directive is similar to the #define in C. For example, you may define the constant PTR as: %define PTR [EBP+4] The above code replaces PTR by [EBP+4]. This directive also allows redefinition and it is case sensitive. 7/13/2024 Introduction to Processors and Chips 70 EXTRN It indicates that the names or labels that follow the EXTRN directive are in some other assembly module. e.g. : EXTRN DISP: FAR To call a procedure that is in a program module assembled at a different time from that which contains the CALL instruction. The assembler has to be told the procedure is external. The assembler will then put information in object code file so that linker can connect the two modules. 7/13/2024 Introduction to Processors and Chips 71 PUBLIC It informs the assembler & linker that the identified variables in a program are to be referenced by another modules linked with the current one. Format: PUBLIC variable,[variable] The variable can be a no.(up to 2 bytes) or a lable or a symbol. E.g: PUBLIC MULTIPLIER,DIVISOR. ; This makes the 2 variables Multiplier & Divisor available to other assembly modules. 7/13/2024 Introduction to Processors and Chips 72 GLOBAL-Declare symbols as PUBLIC or EXTERN This directive can be used instead of PUBLIC directive or instead EXTERN directive. The global directive is used to make the variable available to all other modules. e.g. GLOBAL FACTOR ;It makes the variable factor public so that it can be accessed from all other modules that are linked. 7/13/2024 Introduction to Processors and Chips 73 Length L It is an operator. It informs assembler to find the number of elements in a named data item like a string or an array. The length of string is always stored in Hex by the 8086. Its format is : e.g. MOV CX,LENGTH STRING ; Loads the Length of string in CX. 7/13/2024 Introduction to Processors and Chips 74 OFFSET It is an operator. It informs the assembler to determine the offset or displacement of a named data item. It may also determined the offset of a procedure from the start of the segment which contains it. Its format is : e.g. MOV AX,OFFSET NUM ; It will load the offset of num in the AX register. 7/13/2024 Introduction to Processors and Chips 75 ORG-Originate The ORG directive allows us to set the location counter to any desired value at any point in the program. The location counter is automatically set to 0000H when the assembler reads a segment. Its format is. ORG expression e.g. ORG 500 H ; Set the location counter to 500H A $ is used to represent the current value of LC The $ represent the next available byte location where assembler can put a data or code byte. The $ often used in ORG statements to inform the assembler to make change in location counter relative to its current value. e.g. ORG $+50 ; Increments the location counter by 50 from its current. 7/13/2024 Introduction to Processors and Chips 76 PROC-Procedure Used to indicate the start of the procedure. The procedure is called from another function by using the CALL instruction. The CALL instruction should have the name of the called procedure as argument as shown below: CALL proc_name 2 types: FAR & NEAR Its format is: [Procedure-name] PROC NEAR 7/13/2024 Introduction to Processors and Chips 77 ENDP-End Procedure. It is used to indicate the end of the Procedure. E.g: FACT PROC NEAR ;Statements inside the procedure. FACT ENDP 7/13/2024 Introduction to Processors and Chips 78 Accessing a Procedure and Data from another Assembly module File1.asm File2.asm EXTRN PUBLIC ROUTINE PROC FAR ROUTINE:FAR | | ROUTINE ENDP 7/13/2024 Introduction to Processors and Chips 79.WHILE CL!=3 MOV AH,01H INT 21H LEA BX,PASS MOV AH,[BX+DI].IF AL==AH ADD DL,01.ELSE.BREAK.END IF INC DL INC CL.ENDW 7/13/2024 Introduction to Processors and Chips 80 Procedures NEAR PROCEDURE FAR PROCEDURE It is declared in the same seg. It is declared in the where the main program is different seg. where the stored main program is stored When a procedure is called When a procedure is called only contents of IP are contents of IP & CS are pushed & contents of CS are pushed on the stack remain unchanged Less stack mem. Reqd More stack mem. Reqd INTRA SEGMENT CALL INTER SEGMENT CALL 7/13/2024 Introduction to Processors and Chips 81 Reentrant Procedure main Procedure1 Procedure2 Program Call Call Call Procedure1 Procedure2 Procedure1 Return Next Instr. After call in Main prog Ret. To main Prog 7/13/2024 Introduction to Processors and Chips 82 Recursive Procedure main Procedure Procedure Program Call Call Call Recursive Recursive recursive Next Instr. After call in Return Return 7/13/2024 Main prog Introduction to Processors and Chips 83 MACROS To simplify and reduce the amount of repetitive coding To reduce the errors caused by repetitive coding To make the ALP more readable. Macro executes faster because there is no need of CALL and Return. In NASM, macros are defined with %macro and %endmacro directives. The basic format is: %Macro Name Macro ;define macro ; body of macro Endmacro ;End macro 7/13/2024 Introduction to Processors and Chips 84 PROCEDURE MACRO m/c codes are put only once m/c code is generated each in memory time the macro is called Less mem. is reqd More mem. is reqd Proc is accessed by CALL & Macro can be accessed with RET instructions during the name given to macro program execution when defined Parameters can be passed Parameters can be passed as using reg,pointers,mem or part of the statement which stack calls a macro 7/13/2024 Introduction to Processors and Chips 85 NASM (Netwide Assembler) It is an assembler and disassembler for the Intel x86 architecture. It can be used to write 16-bit, 32-bit (IA-32) and 64-bit (x86-64) programs. It is considered one of the most popular assemblers for Linux. It was originally written by Simon Tatham with assistance from Julian Hall. As of 2016, it is maintained by a small team led by H. Peter Anvin. 7/13/2024 Introduction to Processors and Chips 86 Installing NASM in Ubuntu ⮚ Step I: Open Terminal in Ubuntu (Alt + Ctrl + T) ⮚ Step II: Run the update command sudo apt-get update apt-get update downloads the package lists from repositories and “updates” them to get information on the newest version of packages and their dependencies. It will do this for all repositories and PPA. ⮚ Step III: Run NASM Installation command sudo apt-get install NASM After the terminal process complete, NASM is successfully installed in your system. 7/13/2024 Introduction to Processors and Chips 87 Alternate way for installation of NASM ⮚ First check your nasm assembler version from your terminal by command nasm -v ⮚ If you do not have latest version of nasm, please use below commands. 🡪Remove your older nasm use command sudo apt-get remove nasm 🡪 Download the attached nasm zipped file.(better you download the file in to virtual machine) 🡪Extract the zipped file into the same folder. 🡪Assuming you have extracted the file in Download directory) follow the below commands cd ~/Downloads/ sudo./configure cd rdoff/ sudo make all cd.. sudo make all sudo make install ⮚ your installation part should be done now. Type nasm in terminal 7/13/2024 Introduction to Processors and Chips 88