Presentation is loading. Please wait.

Presentation is loading. Please wait.

S YSTEMS P ROGRAMMING CHAPTER 2 PROGRAMMING IN ASSEMBLY LANGUAGE Er. Bharadwaj Choudhury.

Similar presentations


Presentation on theme: "S YSTEMS P ROGRAMMING CHAPTER 2 PROGRAMMING IN ASSEMBLY LANGUAGE Er. Bharadwaj Choudhury."— Presentation transcript:

1 S YSTEMS P ROGRAMMING CHAPTER 2 PROGRAMMING IN ASSEMBLY LANGUAGE Er. Bharadwaj Choudhury

2 H IGH L EVEL L ANGUAGE C ONSTRUCTS Constants: Numerical, string or other quantities whose unchanging actual values are known when the program is written Variables: Name given to a value. The value may change when the program is executed Reserve words: if, then, else, return, float, real Procedures: Functions or subroutines, which may or may not have arguments and may or may not return values

3 A SSEMBLY L EVEL L ANGUAGE C ONSTRUCTS Computer’s memory: A sequence of bytes, words, blocks. Each computer have a fixed amount of working memory CPU’s registers: Each computer have a set of working as well as special registers Instructions: Each assembly language must have a set of instructions based on the microprocessor used in the computer, along with additional instructions available in the assembler Location Counter: Its task is to keep track of the current location of the instruction being processed relative to the beginning of the next group of instructions

4 H OW T O R UN A SSEMBLY P ROGRAMS ?  Step 1 : Enter the assembly language program through a text editor or an inbuilt editor of the assembler. The inbuilt editor is known as work bench program  Step 2 : The assembly program file or the source file is a ASCII file having the extension.ASM  Step 3 : The assembler accepts this source file and converts it into an object file.OBJ in machine language. The linker converts such object file(s) into some executable form, such as.EXE,.BIN, etc through different passes. Sometimes the extension of inclusion file is.INC

5 S OME C OMMERCIAL A SSEMBLERS Borland turbo assembler (TASM) : This is a MS-DOS based assembler. Suppose MYTASM.ASM is a source program in TASM syntax, then the command C:\TASM>TASM MYTASM assemblers the source program and produces MYTASM.OBJ, provided the assembly program is correct. Microsoft assembler (MASM) : The name has traditionally been referred to the Microsoft Macro assembler. The software for MASM contains an executable program file ML.EXE. Here, ML assembles and links one or more assembly language source program files, producing a.OBJ file and an executable.EXE file

6 S OME C OMMERCIAL A SSEMBLERS MicroAsm : It is a windows-based Integrated Development Environment(IDE) for the assembly programmer. This includes a source editor and an Intel 8086 assembler with easy syntax Netwide Assembler(NASM) : It is a 80x86 processor- based assembler. It supports a wide variety of object file formats such as a.out, ELF, COFF, Win32, etc. Simple binary files are also generated by this assembler. This assembler works under different operating environments such as MS-DOS, WINDOWS and LINUX

7 A SSEMBLER T YPES One pass assemblers Two pass assemblers One and half pass assemblers Multi-pass assemblers

8 A SSEMBLY L ANGUAGE F ORMATS Different assembly language instruction formats differ on details like pseudo operations used, length of identifiers, formats of a constant, etc However, most assembly language instructions has 2 mandatory and 2 optional fields. Label : a symbol of the assembly program. Can store maximum of 6-8 characters Opcode : contains mnemonic code for machine or pseudo operations Operand : specifies 0 or more operands, separated by commas Comments : high-level description of the program [Label]OpcodeOperand[Comments]

9 H OW A SSEMBLY P ROGRAMS A RE E XECUTED ? Consider the assembly program shown below [to be executed in Intel 8086 machine]: Stm. No.LabelOpcodeOperand 10RG100h 2NUM1DW20 3NUM2DW13 4SUMDW? 5MOVAX, NUM1 6ADDAX, NUM2 7MOVSUM,AX 8END Red color indicates machine operations, Blue color indicates pseudo operations For your understanding

10 MOT AB & POT AB MnemonicOpcodeLength(byte) MOV AX,memoB83 ADD AX,memo023 MOV memo,AXA23 Pseudo operationTask ORGStart the program and initialize LC with the value of operand, else initialize it to 0 DWDefine the constant and word storage requirement. Update LC value ENDEnd indicates the end of program. Also, enables allocation of addresses for the unallocated literals in the literal table. Control send to the next pass

11 P ASS 1 O F T HE A SSEMBLY P ROCESS Stm. No. 1 : LC ← 100h Stm. No. 2 : NUM1 in symbol table with value 100h LC ← 100h + 2h = 102h Stm. No. 3 : NUM2 in symbol table with value 102h LC ← 102h + 2h = 104h Stm. No. 4 : SUM in symbol table with value 104h LC ← 104h + 2h = 106h  Stm. No. 5: LC ← LC + 3h =109h  Stm. No. 6 : LC ← LC + 3h =10Ch  Stm. No. 7 : LC ← LC + 3h =10Fh  Stm. No. 8: Opcode is END, indicating end of program

12 P ASS 2 O F T HE A SSEMBLY P ROCESS Stm. No. 1 : Allocate the LC ← 100h Stm. No. 2-4 : Already processed in pass 1 and symbols stored in symbol table  Stm. No. 5: Machine code= B8 + Address of NUM1 = B80100  Stm. No. 6 : Machine code= 02 + Address of NUM2 = 020102  Stm. No. 7 : Machine code= A2 + Address of SUM = A20104  Stm. No. 8: Opcode is END, indicating termination of program

13 S UMMARY : T HE T WO P ASSES Pass I is to construct a symbol table and a literal table using the MOTab and POTab Pass I keeps a copy of the user’s program for Pass II An intermediate mnemonic program is output of Pass I The task of Pass II is to generate the object code from the copy of the user’s program in Pass I Pass II provides the linker & loader with the necessary information for linking object code with link libraries and ultimately loading the executable code in memory for execution

14 PRACTICE PROBLEM Generate symbol table (Pass 1) and machine code(Pass 2) for the assembly program below running on a SIC machine [Note: SIC is a 24-bit machine] Stm. No.LabelOpcodeOperand 1SICSTART0202 2LDANUM1 3ADDNUM2 4STASUM 5NUM1WORD20 6NUM2WORD13 7SUMWORD0 8END Red color indicates machine operations, Blue color indicates pseudo operations

15 MOT AB & POT AB FOR PRACTICE PROBLEM MnemonicOpcodeLength(byte) LDA m003 ADD m183 STA m0C3 Pseudo operationTask STARTStart the program and initialize LC with the value of operand, else initialize it to 0 WORDDefine the constant and storage requirement. Update LC value ENDEnd indicates the end of program. Also, enables allocation of addresses for the unallocated literals in the literal table. Control send to the next pass

16 THANK YOU


Download ppt "S YSTEMS P ROGRAMMING CHAPTER 2 PROGRAMMING IN ASSEMBLY LANGUAGE Er. Bharadwaj Choudhury."

Similar presentations


Ads by Google