0% found this document useful (0 votes)
17 views

IPC_UNIT I Assembly Language Programming

Uploaded by

riot id
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

IPC_UNIT I Assembly Language Programming

Uploaded by

riot id
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 80

Course Objectives

⮚ Understand & learn assembly language programming.


⮚ Demonstrate programming proficiency using 8086,80386 microprocessors &
AVR microcontrollers to design practically motivated systems.
⮚ 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 tradeoffs will be studied in depth.
⮚ Relate and communicate effectively about the microprocessors, peripherals
& microcontrollers used in the present gadgets.
⮚ Develop an ability to use the techniques, skills, and modern engineering
tools to accommodate different practically-motivated circuits.

7/3/2023 Introduction to Processors and Chips 1


Course Outcomes
⮚ Develop program using assembly language over hardware and software.
⮚ Apply the knowledge of memory organization.
⮚ Develop solutions using embedded programming kit.

7/3/2023 Introduction to Processors and Chips 2


Course: Introduction to Processors & Chips

Course Code: 19BTCS303


L: 03Hrs/Week
CA:40 Marks
FE:60 Marks
Credits: 03
COURSE CONTENT

7/3/2023 Introduction to Processors and Chips 4


Unit-I: Assembly Language Programming

• 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.

7/3/2023 Introduction to Processors and Chips 5


Unit-II: 8086 Microprocessor
• Introduction to a Microprocessor.
• Introduction to 8-bit and 16-bit microprocessors.
• 8086- Architecture Functional diagram.
• Register Organization.
• Programming Model.
• Physical Memory Organization.
• Signal descriptions of 8086- common function signals.
• Non-pipelined & pipelined machine cycle.
• addressing modes, Instruction Format, instruction set of 8086.
• Introduction to 8086 Assembly Language Programming and a few sample
programs of 8086.
7/3/2023 Introduction to Processors and Chips 6
Unit-III: 80386 Microprocessor

• Difference between 8086 & 80386.


• 80386 – Features, architecture, Register Set.
• 80386 Real mode segmentation and Address translation & Addressing
modes.
• Real Mode Instruction set of 80386.
• Pin Description of 80386 & 16/32-bit data transfer mechanism.

7/3/2023 Introduction to Processors and Chips 7


Unit-IV: Introduction to Arduino
• Difference between microprocessor and microcontroller.
• Introduction to Arduino boards.
• Introduction to AVR - ATmega328, 8-Bit Microcontroller – Basics,
Features, Architecture, pin diagram & Instruction Set.
• Arduino UNO board architecture.
• Arduino programming: IDE for Arduino.
• Introduction to Tinkercad.
• Arduino programming basics - Structures, Variables, data types,
arithmetic, constants, flow control, digital & analog I/O, time, math,
random and serial.
7/3/2023 Introduction to Processors and Chips 8
Unit-V Arduino Interfacing
• Analog/Digital components and its application with Arduino.
• Other utilities in Arduino: Timers, Analog comparators and hardware
interrupts.
• Interfacing with peripherals: Communication buses, Interfacing of I/O
devices.
• Basics of wireless networking.
• Introduction to NodeMCU Wi-Fi module.
• Interfacing Case studies: Case studies of a few projects using Arduino
boards

7/3/2023 Introduction to Processors and Chips 9


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.

7/3/2023 Introduction to Processors and Chips 10


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.
7/3/2023 Introduction to Processors and Chips 11
U N IT

Assembly Language Programming

7/3/2023 Introduction to Processors and Chips 12


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/3/2023 Introduction to Processors and Chips 13
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/3/2023 Introduction to Processors and Chips 14
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/3/2023 Introduction to Processors and Chips 15


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/3/2023 Introduction to Processors and Chips 16


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/3/2023 Introduction to Processors and Chips 17


❖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/3/2023 Introduction to Processors and Chips 18


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/3/2023 Introduction to Processors and Chips 19
•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/3/2023 Introduction to Processors and Chips 20
•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/3/2023 Introduction to Processors and Chips 21


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/3/2023 Introduction to Processors and Chips 22
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/3/2023 Introduction to Processors and Chips 23
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.
1. Data Segment
2. Code Segment
3. Stack Segment

7/3/2023 Introduction to Processors and Chips 24


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/3/2023 Introduction to Processors and Chips 25


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/3/2023 Introduction to Processors and Chips 26


Stack Segment

⮚This segment contains data values passed to functions and procedures within the
program.

7/3/2023 Introduction to Processors and Chips 27


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/3/2023 Introduction to Processors and Chips 28


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/3/2023 Introduction to Processors and Chips 29
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/3/2023 Introduction to Processors and Chips 30


Steps involved in programming
• Specify the problem
• Designing the problem solution
• Coding
• Debugging

7/3/2023 Introduction to Processors and Chips 31


Program Development
Algorithm

7/3/2023 Introduction to Processors and Chips 32


7/3/2023 Introduction to Processors and Chips 33
Software Programming Tools
Assembly Language Programming Tools
• Assembler
• Linker
• Loader
• Locator
• Debugger
• Emulator
7/3/2023 Introduction to Processors and Chips 35
36
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/3/2023 Introduction to Processors and Chips 37
38
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/3/2023 Introduction to Processors and Chips 39
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/3/2023 Introduction to Processors and Chips 40


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/3/2023 Introduction to Processors and Chips 41


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/3/2023 Introduction to Processors and Chips 42


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/3/2023 Introduction to Processors and Chips 43
ASSEMBLER
DIRECTIVES

7/3/2023 Introduction to Processors and Chips 44


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/3/2023 Introduction to Processors and Chips 45
.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/3/2023 Introduction to Processors and Chips 46
.STACK
• Format: .STACK[size]
• This directive is used for defining the stack.
• By default the size is 1024 bytes.
• E.g. .STACK[98];reserves 98 bytes for the
stack

7/3/2023 Introduction to Processors and Chips 47


Initializing the STACK
Method 1:
ASSUME CS:CODE,DS:DATA,SS:STACK
……..
……
STACK SEGMENT
S-DATA DB 100 DUP(?)
STACK ENDS

7/3/2023 Introduction to Processors and Chips 48


Method 2:
Syntax: .STACK [SIZE]
Example: .STACK 200

7/3/2023 Introduction to Processors and Chips 49


.DATA
• Format: .DATA
• This directive indicates the beginning of the
data segment.
• In NASM🡪
The syntax for declaring data section is −
section.data
7/3/2023 Introduction to Processors and Chips 50
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/3/2023
• E.g. List DB 08HIntroduction to Processors and Chips 51
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/3/2023 Introduction to Processors and Chips 52
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/3/2023 Introduction to Processors and Chips 53


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/3/2023 • E.g. List DQ 1234567898765432H
Introduction to Processors and Chips 54
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/3/2023 Introduction to Processors and Chips 55


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/3/2023 Introduction to Processors and Chips 56
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/3/2023 Introduction to Processors and Chips 57


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/3/2023 Introduction to Processors and Chips 58


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/3/2023 Introduction to Processors and Chips 59


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/3/2023 Introduction to Processors and Chips 60


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/3/2023 Introduction to Processors and Chips 61


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/3/2023 Introduction to Processors and Chips 62
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/3/2023 Introduction to Processors and Chips 63


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/3/2023 Introduction to Processors and Chips 64
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/3/2023 Introduction to Processors and Chips 65
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/3/2023 Introduction to Processors and Chips 66
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/3/2023 Introduction to Processors and Chips 67


Accessing a Procedure and Data from another
Assembly module
File1.asm File2.asm
EXTRN PUBLIC ROUTINE PROC FAR
ROUTINE:FAR |
|
ROUTINE ENDP

7/3/2023 Introduction to Processors and Chips 68


.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/3/2023 Introduction to Processors and Chips 69


Procedures
NEAR PROCEDURE FAR PROCEDURE
• It is declared in the same • It is declared in the
seg. where the main different seg. where the
program is stored main program is stored
• When a procedure is • When a procedure is called
called only contents of IP contents of IP & CS are
are pushed & contents of pushed on the stack
CS are remain unchanged
• Less stack mem. Reqd • More stack mem. Reqd
• INTRA SEGMENT • INTER SEGMENT CALL
CALL

7/3/2023 Introduction to Processors and Chips 70


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/3/2023 Introduction to Processors and Chips 71
Recursive Procedure
main Procedure Procedure
Program

Call Call Call


Recursive Recursive recursive

Next Instr.
After call in Return Return
7/3/2023
Main prog Introduction to Processors and Chips 72
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/3/2023 Introduction to Processors and Chips 73


PROCEDURE MACRO
• m/c codes are put only • m/c code is generated
once in memory each time the macro is
called
• Less mem. is reqd • More mem. is reqd
• Proc is accessed by • Macro can be accessed
CALL & RET with the name given to
instructions during macro when defined
program execution
• Parameters can be • Parameters can be
passed using passed as part of the
reg,pointers,mem or statement which calls a
stack macro

7/3/2023 Introduction to Processors and Chips 74


Local variables in a MACRO
DISPLAY MACRO A
LOCAL J_LABEL
PUSH DX
CMP AL,’Z’
JBE J_LABEL
SUB AL,20H
J_LABEL: MOV DL,AL
MOV AH,02H
INT 21H
POP DX
ENDM

7/3/2023 Introduction to Processors and Chips 75


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/3/2023 Introduction to Processors and Chips 76


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/3/2023 Introduction to Processors and Chips 77


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/ <nasm directory>
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/3/2023 Introduction to Processors and Chips 78
Options used in ALP
1. The -o Option: Specifying the Output File Name
NASM provides the command-line option, which allows you to specify your
-o

desired output file name. You invoke by following it with the name you wish for
-o

the output file, either with or without an intervening space


2. The -f Option: Specifying the Output File Format
3. The -s Option: Send Errors to stdout
The -s option redirects error messages to stdout rather than stderr, so it can be redirected under MS-DOS

4. The -M Option: Generate Makefile Dependencies


This option can be used to generate makefile dependencies on stdout. This can
be redirected to a file for further processing
https://www.nasm.us/doc/nasmdoc4.html 79
How the length of message is calculated?

80

You might also like