SlideShare une entreprise Scribd logo
1  sur  49
Assembly Language
Programming
Fundamentals
Presented By: Shehrevar Davierwala
Do Visit: http://sites.google.com/site/techwizardin
http://www.authorstream.com/shehrevard
Introduction To Programming Languages
• Machine Languages -“natural language” of a
computer
• Low Level Languages-In low level language,
instructions are coded using mnemonics
• High Level Languages
Data Representation & Numbering Systems
• Binary Numbering Systems
• Octal Numbering Systems
• Decimal Numbering Systems
• Hexadecimal Numbering Systems
Types Of Encoding
• American Standard Code For Information
Interchange ( ASCII )
• Binary Coded Decimal ( BCD )
• Extended Binary Coded Decimal Interchange
Code ( EBCDIC )
Mode of data representation
• Integer Representation
• Floating Point Representation
Format of Assembly Language Instructions
[Label] Operation [Operands] [; Comment]
• Example: Examples of instructions with varying numbers of fields.
• [Label] Operation [Operands] [; Comment]
L1: cmp bx, cx ; Compare bx with cx all fields present
add ax, 25 operation and 2
operands
inc bx operation and 1 operand
ret operation field only
; Comment: whatever you wish !! comment field only
program syntax
Type 1( MASM) TYPE 2(MASM) Kit
.model small
.data
Mes db ‘Hello $’
Op1 db 20h
Op2 db 30h
.code
Start:
Mov ax,@data
Mov ds,ax
Mov ax,op1
Mov bx,op2
Add ax,bx
Int 3
End start
Assume CS:code segment,DS:Data segment
DATA SEGMENT
Mes db ‘Hello $’
Op1 db 20h
Op2 db 30h
DATA ENDS
CODE SEGMENT
Start:
Mov ax,data
Mov ds,ax
Mov ax,op1
Mov bx,op2
Add ax,bx
Int 3
CODE ENDS
End start
Mov ax,20
Mov bx,30
Add ax,bx
Int 3
• Assembler Directives
• Procedures
• Macros
Assembler Directives
• Assembler Directives are directions to the
assembler.
• Assembler directives are the commands to the
assembler that direct the assembly process.
• They indicate how an operand is treated by
the assembler and how assembler handles the
program.
• They also direct the assembler how program
and data should be arranged in the memory.
List of Assembler Directives
ASSUME DB DW DD DQ
DT END ENDP ENDS EQU
EVEN EXTRN GLOBAL GROUP INCLUDE
LABEL LENGTH NAME OFFSET ORG
PROC PTR SEGMENT SHORT TYPE
Procedures
• A procedure is a collection of instructions to which we can direct the flow
of our program, and once the execution of these instructions is over
control is given back to the next line to process of the code which called
on the procedure.
• At the time of invoking a procedure the address of the next instruction of
the program is kept on the stack so that, once the flow of the program has
been transferred and the procedure is done, one can return to the next
line
of the original program, the one which called the procedure.
• Intrasegment procedure(IP in stack)
• Intersegment procedure(CS:IP in stack)
• Syntax:
Procedure name PROC near
instruction 1
instruction 2
RET
Procedure name ENDP
Example:
ADD2 PROC near
ADD AX,BX
RET
ADD2 ENDP
ADD2 PROC FAR
ADD AX,BX
RET
ADD2 ENDP
MACROS
• A macro is a group of repetitive instructions in
a program which are codified only once and
can be used as many times as necessary.
• Macro with in a macro is a nested MACRO
• A macro can be defined anywhere in program
using the directives MACRO and ENDM
• Syntax of macro:
Read MACRO
mov ah,01h
int 21h
ENDM
Display MACRO
mov dl,al
Mov ah,02h
int 21h
ENDM
Passing parameters to a macro
• Display MACRO MSG
mov dx, offset msg
mov ah,09h
int 21h
ENDM
The parameter MSG can be replaced by msg1 or msg2 while calling…
Calling macro:
DISPLAY MSG1
DISPLAY MSG2
MSG1 db “I am Fine $”
MSG2 db “Hello, How are you..? $”
Here parameter is
MSG
Procedures Vs Macros
Procedures Macros
Accessed by CALL and RET mechanism
during program execution
Accessed by name given to macro when
defined during assembly
Machine code for instructions only put in
memory once
Machine code generated for instructions
each time called
Parameters are passed in registers,
memory locations or stack
Parameters passed as part of statement
which calls macro
Procedures uses stack Macro does not utilize stack
A procedure can be defined anywhere in
program using the directives PROC and
ENDP
A macro can be defined anywhere in
program using the directives MACRO and
ENDM
Procedures takes huge memory for
CALL(3 bytes each time CALL is used)
instruction
Length of code is very huge if macro’s are
called for more number of times
Key common aspects for any
programming language
• Variables: declaration
• Assignment: assigning values to variable
• Input/output: displaying messages or
displaying variable values
• Control Flow: If Then, Loops
• Sub Programs: Definition , usage
Declaring Variables
• In c , java data types are used
• In Assembly language, Assembler Directives
are used(db , dw , dd , dq , dT)
• Example:
– reply db ‘y’ ( reply is a character variable)
– prompt db ‘Enter your favourite colour: ’, 0( prompt is a string terminated by
null)
– colour db 80 dup(?) (colour is an array of size 80)
– i db 20
– k db ?
– num dw 4000
– large dd 50000
• Indirect addressing
– Strings stored in memory
Message db ‘Hello’,0
8086 stack
• The stack is a block of memory that may be used for temporarily storing
the contents of registers inside CPU.
• Stack is accessed by using SP and SS.
• Stack is a Top Down Data Structure whose elements are accessed by using
a pointer (SP,SS).
• The stack is required when CALL instruction is used.
• Push
• Pop
• Top of stack
• Stack pointer
• LIFO
stack
• Example: Using the stack, swap the values of the ax and bx registers, so that ax
now contains what bx contained and bx contains what ax contained. (This is not
the most efficient way to exchange the contents of two variables). To carry out this
operation, we need at least one temporary variable:
push ax ; Store ax on stack
push bx ; Store bx on stack
pop ax ; Copy last value on stack to ax
pop bx ; Copy first value to bx
Push ax
Mov ax,bx
popbx
Assignment
• For assigning values, MOV
• Mov ax,42
• Mov bx,45
So here MOV instruction carries out assignment
Syntax of MOV: MOV destination, source
Destination – a register or memory location
Source- - a constant or another register or memory
location.
• Example1: Store the ASCII code for the letter
A in register bx.
Ans: ????
Comments: we can give comments with help of
semicolon(;).the text written after semicolon
is treated as semicolon.
Add ax,bx; addition of ax,bx contents
Note: In assembly language, only one
Arithmetic operation can be performed at a
single time.
Exercises
• 1) Write instructions to:
– Load character ? into register bx
– Load space character into register cx
– Load 26 (decimal) into register cx
– Copy contents of ax to bx and dx
• 2) What errors are present in the following :
• mov ax 3d
• mov 23, ax
• mov cx, ch
• move ax, 1h
• add 2, cx
• add 3, 6
• inc ax, 2
• 3) Write instructions to evaluate the arithmetic expression 5 +(6-2) leaving the result in ax using (a)
1 register, (b) 2 registers,(c) 3 registers
• 4) Write instructions to evaluate the expressions:
• a = b + c –d
• z = x + y + w – v +u
Input / output
• i/o devices—keyboard , screen
• IN & OUT( complicated instructions)
• So a mechanism is needed to call operating
system to carryout I/O .
• Also what kind of I/O operation to be
performed should be specified.( read or write
etc)
• Here we do it with help of SOFTWARE
INTERRUPTS
SOFTWARE INTERRUPT
• Software interrupt is generated by program
• The INT instruction generates a software
interrupt
• INT instruction uses a single operand to indicate
which MS-DOS sub program should be invoked.
• FOR I/O operations, We have INT 21H
• Here number stored in AH register is used to
specify which kind of I/O operation is to be done.
• 1h
• Write a code fragment to display the
character ’a’ on the screen?
• Write a code fragment to read a character
from the keyboard?
• Reading and displaying a character?
• Example: The following code fragment illustrates the use of indirect addressing. It is a loop to count the
number of characters in a string terminated by the Null character (ASCII 0). It uses the cx register to
store the number of characters in the string.
message db ‘Hello’, 0
mov cx, 0 ; cx stores number ofcharacters
mov bx, offset message ; store address of message in bx
begin:
cmp byte ptr [bx], 0 ; is this end of string?
je fin ; if yes goto Finished
inc cx ; cx = cx + 1
inc bx ; bx points to next character
jmp begin
fin:
Control Flow
• Example : This example illustrates the use of the jmp instruction to
implement an endless loop – not something you would noramlly wish to
do!
again:
call getc ; read a character
call putc ; display character
jmp again ; jump to again
Unconditional jump
• Example : The following code fragment
illustrates a forward jump, as control is
transferred to a later place in the program:
call getc ; read a character
call putc ; display the character
jmp finish ; jump to label finish
<do other things>; Never gets done !!!
finish:
mov ax, 4c00h
int 21h
Conditional jump
• conditional jump instructions can handle the various conditions (==, !=, <,
>, <=, >=) that arise when comparing values. Je/jz
ax = 2;
if ( ax != bx )
{
ax = ax + 1 ;
}
bx = bx + 1 ;
mov ax, 2 ; ax = 2
sub ax, bx ; ax = 2 - bx
jz nextl ; jump if (ax-bx) == 0
inc ax ; ax = ax + 1
nextl:
inc bx
Conditional jump instructions
If then
if ( i == 10 )
{
i = i + 5 ;
j = j + 5 ;
}
/* Rest of program */
If else
c = getchar() ;
if ( c == ‘A’ )
printf(“You guessed correctly !! “);
else
printf(“Sorry incorrect guess “) ;
• Upper case to lower case:
if ( c >= ‘A‘ && c <= ‘Z‘ ) or if ( c < ‘A‘ || c > ‘Z‘ )
main() /* char.c: convert letter to lowercase */
{
char c;
printf(“nEnter an uppercase letter: “);
c = getchar();
if ( c >= ‘A‘ && c <= ‘Z‘ )
{
c = c + ( ‘a’ - ‘A’ ) ; /* convert to
lowercase */
printf(“nThe lowercase equivalent is: %c “,c);
}
else
printf(“nNot an uppercase letter %c “, c );
}
In the code fragments below where will execution
continue from when <jump-on-condition> is replaced by (a)
je lab1 ; (b) jg lab1; (c) jle lab1; (d) jz lab1
(i) mov ax, 10h
cmp ax, 9h
<jump-on-condition>
; rest of program
...........
...........
lab1:
(ii) mov cx, 0h
cmp cx, 0d
<jump-on-condition>
; rest of program
...........
. ..........
lab1:
LOOPS-deterministic loopcount = 1 ;
while ( count <= 60 )
{
putchar(‘*’) ;
count = count + 1 ;
}
Write a code fragment to display the characters from ‘a’ to ‘z’ on the screen using the
knowledge that the ASCII codes form a collating sequence. This means that the code
for ‘b’ is one greater than the code for ‘a’ and the code for ‘c’ is one greater than that
for ‘b’ and so on.
c = ‘a‘ ; /* c = 97 (ASCII for ‘a‘)
while ( c <= ‘z‘ )
{
putchar( c );
c = c + 1 ;
}
Non deterministic loop
main()
{
char c, reply;
reply = ‘y‘;
while ( reply == ‘y‘ )
{
printf(“nEnter an uppercase letter: “);
c = getchar();
c = c + ( ‘a’ - ‘A’ ) ; /* convert to lowercase
*/
printf(“nThe lowercase equivalent is: %c “, c);
printf(“nEnter y to continue: “);
reply = getchar();
}
}
• Bit manipulations
• Nuber conversions(packed,unpacked)
• Shift operations
• Clear bit 5 of a given byte
• Converting a lowercase letter to its uppercase equivalent
• Specify the instructions and masks would you use to
a) set bits 2, 3 and 4 of the ax register
b) clear bits 4 and 7 of the bx register
• How would al be affected by the following instructions:
(a) and al, 00fh
(b) and al, 0f0h
(c) or al, 00fh
(d) or al, 0f0h
• Toggle bits 0, 1 and 6 of the value in al (here 67h)
• compliment
or cx, cx ; compares cx with 0
je label
and ax, ax ; compares ax with 0
jg label2
THANK YOU
??????

Contenu connexe

Tendances

Assembly language 8086
Assembly language 8086Assembly language 8086
Assembly language 8086John Cutajar
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architectureprasadpawaskar
 
PIC Microcontrollers.ppt
PIC Microcontrollers.pptPIC Microcontrollers.ppt
PIC Microcontrollers.pptDr.YNM
 
Interfacing with peripherals: analog to digital converters and digital to ana...
Interfacing with peripherals: analog to digital converters and digital to ana...Interfacing with peripherals: analog to digital converters and digital to ana...
Interfacing with peripherals: analog to digital converters and digital to ana...NimeshSingh27
 
Register transfer language
Register transfer languageRegister transfer language
Register transfer languageSanjeev Patel
 
RISC and CISC Processors
RISC and CISC ProcessorsRISC and CISC Processors
RISC and CISC ProcessorsAdeel Rasheed
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptxHebaEng
 
8086 MICROPROCESSOR
8086 MICROPROCESSOR8086 MICROPROCESSOR
8086 MICROPROCESSORAkhila Rahul
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorAshita Agrawal
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output OrganizationKamal Acharya
 
Accessing I/O Devices
Accessing I/O DevicesAccessing I/O Devices
Accessing I/O DevicesSlideshare
 
8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controllerabhikalmegh
 
Logical and shift micro operations
Logical and shift micro operationsLogical and shift micro operations
Logical and shift micro operationsSanjeev Patel
 
Byte and string manipulation 8086
Byte and string manipulation 8086Byte and string manipulation 8086
Byte and string manipulation 8086mpsrekha83
 

Tendances (20)

Assembly language 8086
Assembly language 8086Assembly language 8086
Assembly language 8086
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
 
Assembly Language
Assembly LanguageAssembly Language
Assembly Language
 
PIC Microcontrollers.ppt
PIC Microcontrollers.pptPIC Microcontrollers.ppt
PIC Microcontrollers.ppt
 
ADDRESSING MODES
ADDRESSING MODESADDRESSING MODES
ADDRESSING MODES
 
Interfacing with peripherals: analog to digital converters and digital to ana...
Interfacing with peripherals: analog to digital converters and digital to ana...Interfacing with peripherals: analog to digital converters and digital to ana...
Interfacing with peripherals: analog to digital converters and digital to ana...
 
Register transfer language
Register transfer languageRegister transfer language
Register transfer language
 
RISC and CISC Processors
RISC and CISC ProcessorsRISC and CISC Processors
RISC and CISC Processors
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptx
 
8086 MICROPROCESSOR
8086 MICROPROCESSOR8086 MICROPROCESSOR
8086 MICROPROCESSOR
 
Microprocessor 8086
Microprocessor 8086Microprocessor 8086
Microprocessor 8086
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 Microprocessor
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output Organization
 
ARM Processors
ARM ProcessorsARM Processors
ARM Processors
 
Serial Communication in 8051
Serial Communication in 8051Serial Communication in 8051
Serial Communication in 8051
 
Accessing I/O Devices
Accessing I/O DevicesAccessing I/O Devices
Accessing I/O Devices
 
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
 
8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller
 
Logical and shift micro operations
Logical and shift micro operationsLogical and shift micro operations
Logical and shift micro operations
 
Byte and string manipulation 8086
Byte and string manipulation 8086Byte and string manipulation 8086
Byte and string manipulation 8086
 

Similaire à Assembly language programming_fundamentals 8086

Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language ProgrammingNiropam Das
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programmingWondeson Emeye
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionAhmed Raza
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Bilal Amjad
 
Chap6 procedures &amp; macros
Chap6 procedures &amp; macrosChap6 procedures &amp; macros
Chap6 procedures &amp; macrosHarshitParkar6677
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly LanguageAhmed M. Abed
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8kapil078
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Bilal Amjad
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assemblyAbdul Khan
 

Similaire à Assembly language programming_fundamentals 8086 (20)

EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptxEC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language Programming
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
 
C for Engineers
C for EngineersC for Engineers
C for Engineers
 
Alp 05
Alp 05Alp 05
Alp 05
 
Alp 05
Alp 05Alp 05
Alp 05
 
Alp 05
Alp 05Alp 05
Alp 05
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Chap6 procedures &amp; macros
Chap6 procedures &amp; macrosChap6 procedures &amp; macros
Chap6 procedures &amp; macros
 
7986-lect 7.pdf
7986-lect 7.pdf7986-lect 7.pdf
7986-lect 7.pdf
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
 
5059734.ppt
5059734.ppt5059734.ppt
5059734.ppt
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Assembler
AssemblerAssembler
Assembler
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 

Plus de Shehrevar Davierwala

Plus de Shehrevar Davierwala (20)

Introduction_Swift
Introduction_SwiftIntroduction_Swift
Introduction_Swift
 
PsudoCode.pptx
PsudoCode.pptxPsudoCode.pptx
PsudoCode.pptx
 
Number System.pptx
Number System.pptxNumber System.pptx
Number System.pptx
 
Java Script (Module 1).pptx
Java Script (Module 1).pptxJava Script (Module 1).pptx
Java Script (Module 1).pptx
 
Website in Clicks Day 2
Website in Clicks Day 2Website in Clicks Day 2
Website in Clicks Day 2
 
Develop Website in Clicks
Develop Website in ClicksDevelop Website in Clicks
Develop Website in Clicks
 
Build Virtual Assistant Using AI
Build Virtual Assistant Using AI Build Virtual Assistant Using AI
Build Virtual Assistant Using AI
 
Build brand reputation using facebook
Build brand reputation using facebookBuild brand reputation using facebook
Build brand reputation using facebook
 
Digital Marketing Session 2
Digital Marketing Session 2Digital Marketing Session 2
Digital Marketing Session 2
 
Learn Digital Marketing : 0 to Hero Day 1
Learn Digital Marketing :  0 to Hero Day 1 Learn Digital Marketing :  0 to Hero Day 1
Learn Digital Marketing : 0 to Hero Day 1
 
Standard template
Standard templateStandard template
Standard template
 
Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective  Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective
 
Developing stunning website in clicks - 2
Developing stunning website in clicks - 2Developing stunning website in clicks - 2
Developing stunning website in clicks - 2
 
Developing stunning website in clicks
Developing stunning website in clicksDeveloping stunning website in clicks
Developing stunning website in clicks
 
Google forms for data analysis
Google forms for data analysisGoogle forms for data analysis
Google forms for data analysis
 
Webdesign session1
Webdesign session1Webdesign session1
Webdesign session1
 
Tech talk webtech
Tech talk webtechTech talk webtech
Tech talk webtech
 
Tech talk php_cms
Tech talk php_cmsTech talk php_cms
Tech talk php_cms
 
Ph pbasics
Ph pbasicsPh pbasics
Ph pbasics
 
Php mysql
Php mysqlPhp mysql
Php mysql
 

Dernier

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Dernier (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Assembly language programming_fundamentals 8086

  • 1. Assembly Language Programming Fundamentals Presented By: Shehrevar Davierwala Do Visit: http://sites.google.com/site/techwizardin http://www.authorstream.com/shehrevard
  • 2. Introduction To Programming Languages • Machine Languages -“natural language” of a computer • Low Level Languages-In low level language, instructions are coded using mnemonics • High Level Languages
  • 3. Data Representation & Numbering Systems • Binary Numbering Systems • Octal Numbering Systems • Decimal Numbering Systems • Hexadecimal Numbering Systems
  • 4. Types Of Encoding • American Standard Code For Information Interchange ( ASCII ) • Binary Coded Decimal ( BCD ) • Extended Binary Coded Decimal Interchange Code ( EBCDIC )
  • 5. Mode of data representation • Integer Representation • Floating Point Representation
  • 6. Format of Assembly Language Instructions [Label] Operation [Operands] [; Comment] • Example: Examples of instructions with varying numbers of fields. • [Label] Operation [Operands] [; Comment] L1: cmp bx, cx ; Compare bx with cx all fields present add ax, 25 operation and 2 operands inc bx operation and 1 operand ret operation field only ; Comment: whatever you wish !! comment field only
  • 7. program syntax Type 1( MASM) TYPE 2(MASM) Kit .model small .data Mes db ‘Hello $’ Op1 db 20h Op2 db 30h .code Start: Mov ax,@data Mov ds,ax Mov ax,op1 Mov bx,op2 Add ax,bx Int 3 End start Assume CS:code segment,DS:Data segment DATA SEGMENT Mes db ‘Hello $’ Op1 db 20h Op2 db 30h DATA ENDS CODE SEGMENT Start: Mov ax,data Mov ds,ax Mov ax,op1 Mov bx,op2 Add ax,bx Int 3 CODE ENDS End start Mov ax,20 Mov bx,30 Add ax,bx Int 3
  • 8.
  • 9. • Assembler Directives • Procedures • Macros
  • 10. Assembler Directives • Assembler Directives are directions to the assembler. • Assembler directives are the commands to the assembler that direct the assembly process. • They indicate how an operand is treated by the assembler and how assembler handles the program. • They also direct the assembler how program and data should be arranged in the memory.
  • 11. List of Assembler Directives ASSUME DB DW DD DQ DT END ENDP ENDS EQU EVEN EXTRN GLOBAL GROUP INCLUDE LABEL LENGTH NAME OFFSET ORG PROC PTR SEGMENT SHORT TYPE
  • 12. Procedures • A procedure is a collection of instructions to which we can direct the flow of our program, and once the execution of these instructions is over control is given back to the next line to process of the code which called on the procedure. • At the time of invoking a procedure the address of the next instruction of the program is kept on the stack so that, once the flow of the program has been transferred and the procedure is done, one can return to the next line of the original program, the one which called the procedure. • Intrasegment procedure(IP in stack) • Intersegment procedure(CS:IP in stack)
  • 13. • Syntax: Procedure name PROC near instruction 1 instruction 2 RET Procedure name ENDP Example: ADD2 PROC near ADD AX,BX RET ADD2 ENDP ADD2 PROC FAR ADD AX,BX RET ADD2 ENDP
  • 14. MACROS • A macro is a group of repetitive instructions in a program which are codified only once and can be used as many times as necessary. • Macro with in a macro is a nested MACRO • A macro can be defined anywhere in program using the directives MACRO and ENDM
  • 15. • Syntax of macro: Read MACRO mov ah,01h int 21h ENDM Display MACRO mov dl,al Mov ah,02h int 21h ENDM
  • 16. Passing parameters to a macro • Display MACRO MSG mov dx, offset msg mov ah,09h int 21h ENDM The parameter MSG can be replaced by msg1 or msg2 while calling… Calling macro: DISPLAY MSG1 DISPLAY MSG2 MSG1 db “I am Fine $” MSG2 db “Hello, How are you..? $” Here parameter is MSG
  • 17. Procedures Vs Macros Procedures Macros Accessed by CALL and RET mechanism during program execution Accessed by name given to macro when defined during assembly Machine code for instructions only put in memory once Machine code generated for instructions each time called Parameters are passed in registers, memory locations or stack Parameters passed as part of statement which calls macro Procedures uses stack Macro does not utilize stack A procedure can be defined anywhere in program using the directives PROC and ENDP A macro can be defined anywhere in program using the directives MACRO and ENDM Procedures takes huge memory for CALL(3 bytes each time CALL is used) instruction Length of code is very huge if macro’s are called for more number of times
  • 18. Key common aspects for any programming language • Variables: declaration • Assignment: assigning values to variable • Input/output: displaying messages or displaying variable values • Control Flow: If Then, Loops • Sub Programs: Definition , usage
  • 19. Declaring Variables • In c , java data types are used • In Assembly language, Assembler Directives are used(db , dw , dd , dq , dT) • Example: – reply db ‘y’ ( reply is a character variable) – prompt db ‘Enter your favourite colour: ’, 0( prompt is a string terminated by null) – colour db 80 dup(?) (colour is an array of size 80) – i db 20 – k db ? – num dw 4000 – large dd 50000
  • 20. • Indirect addressing – Strings stored in memory Message db ‘Hello’,0
  • 21. 8086 stack • The stack is a block of memory that may be used for temporarily storing the contents of registers inside CPU. • Stack is accessed by using SP and SS. • Stack is a Top Down Data Structure whose elements are accessed by using a pointer (SP,SS). • The stack is required when CALL instruction is used. • Push • Pop • Top of stack • Stack pointer • LIFO
  • 22. stack
  • 23. • Example: Using the stack, swap the values of the ax and bx registers, so that ax now contains what bx contained and bx contains what ax contained. (This is not the most efficient way to exchange the contents of two variables). To carry out this operation, we need at least one temporary variable: push ax ; Store ax on stack push bx ; Store bx on stack pop ax ; Copy last value on stack to ax pop bx ; Copy first value to bx Push ax Mov ax,bx popbx
  • 24. Assignment • For assigning values, MOV • Mov ax,42 • Mov bx,45 So here MOV instruction carries out assignment Syntax of MOV: MOV destination, source Destination – a register or memory location Source- - a constant or another register or memory location.
  • 25. • Example1: Store the ASCII code for the letter A in register bx. Ans: ???? Comments: we can give comments with help of semicolon(;).the text written after semicolon is treated as semicolon. Add ax,bx; addition of ax,bx contents Note: In assembly language, only one Arithmetic operation can be performed at a single time.
  • 26. Exercises • 1) Write instructions to: – Load character ? into register bx – Load space character into register cx – Load 26 (decimal) into register cx – Copy contents of ax to bx and dx • 2) What errors are present in the following : • mov ax 3d • mov 23, ax • mov cx, ch • move ax, 1h • add 2, cx • add 3, 6 • inc ax, 2 • 3) Write instructions to evaluate the arithmetic expression 5 +(6-2) leaving the result in ax using (a) 1 register, (b) 2 registers,(c) 3 registers • 4) Write instructions to evaluate the expressions: • a = b + c –d • z = x + y + w – v +u
  • 27. Input / output • i/o devices—keyboard , screen • IN & OUT( complicated instructions) • So a mechanism is needed to call operating system to carryout I/O . • Also what kind of I/O operation to be performed should be specified.( read or write etc) • Here we do it with help of SOFTWARE INTERRUPTS
  • 28. SOFTWARE INTERRUPT • Software interrupt is generated by program • The INT instruction generates a software interrupt • INT instruction uses a single operand to indicate which MS-DOS sub program should be invoked. • FOR I/O operations, We have INT 21H • Here number stored in AH register is used to specify which kind of I/O operation is to be done.
  • 30. • Write a code fragment to display the character ’a’ on the screen? • Write a code fragment to read a character from the keyboard? • Reading and displaying a character?
  • 31. • Example: The following code fragment illustrates the use of indirect addressing. It is a loop to count the number of characters in a string terminated by the Null character (ASCII 0). It uses the cx register to store the number of characters in the string. message db ‘Hello’, 0 mov cx, 0 ; cx stores number ofcharacters mov bx, offset message ; store address of message in bx begin: cmp byte ptr [bx], 0 ; is this end of string? je fin ; if yes goto Finished inc cx ; cx = cx + 1 inc bx ; bx points to next character jmp begin fin:
  • 32. Control Flow • Example : This example illustrates the use of the jmp instruction to implement an endless loop – not something you would noramlly wish to do! again: call getc ; read a character call putc ; display character jmp again ; jump to again
  • 33. Unconditional jump • Example : The following code fragment illustrates a forward jump, as control is transferred to a later place in the program: call getc ; read a character call putc ; display the character jmp finish ; jump to label finish <do other things>; Never gets done !!! finish: mov ax, 4c00h int 21h
  • 34. Conditional jump • conditional jump instructions can handle the various conditions (==, !=, <, >, <=, >=) that arise when comparing values. Je/jz ax = 2; if ( ax != bx ) { ax = ax + 1 ; } bx = bx + 1 ; mov ax, 2 ; ax = 2 sub ax, bx ; ax = 2 - bx jz nextl ; jump if (ax-bx) == 0 inc ax ; ax = ax + 1 nextl: inc bx
  • 36. If then if ( i == 10 ) { i = i + 5 ; j = j + 5 ; } /* Rest of program */
  • 37. If else c = getchar() ; if ( c == ‘A’ ) printf(“You guessed correctly !! “); else printf(“Sorry incorrect guess “) ;
  • 38. • Upper case to lower case: if ( c >= ‘A‘ && c <= ‘Z‘ ) or if ( c < ‘A‘ || c > ‘Z‘ ) main() /* char.c: convert letter to lowercase */ { char c; printf(“nEnter an uppercase letter: “); c = getchar(); if ( c >= ‘A‘ && c <= ‘Z‘ ) { c = c + ( ‘a’ - ‘A’ ) ; /* convert to lowercase */ printf(“nThe lowercase equivalent is: %c “,c); } else printf(“nNot an uppercase letter %c “, c ); }
  • 39.
  • 40. In the code fragments below where will execution continue from when <jump-on-condition> is replaced by (a) je lab1 ; (b) jg lab1; (c) jle lab1; (d) jz lab1 (i) mov ax, 10h cmp ax, 9h <jump-on-condition> ; rest of program ........... ........... lab1: (ii) mov cx, 0h cmp cx, 0d <jump-on-condition> ; rest of program ........... . .......... lab1:
  • 41. LOOPS-deterministic loopcount = 1 ; while ( count <= 60 ) { putchar(‘*’) ; count = count + 1 ; }
  • 42. Write a code fragment to display the characters from ‘a’ to ‘z’ on the screen using the knowledge that the ASCII codes form a collating sequence. This means that the code for ‘b’ is one greater than the code for ‘a’ and the code for ‘c’ is one greater than that for ‘b’ and so on. c = ‘a‘ ; /* c = 97 (ASCII for ‘a‘) while ( c <= ‘z‘ ) { putchar( c ); c = c + 1 ; }
  • 43.
  • 44. Non deterministic loop main() { char c, reply; reply = ‘y‘; while ( reply == ‘y‘ ) { printf(“nEnter an uppercase letter: “); c = getchar(); c = c + ( ‘a’ - ‘A’ ) ; /* convert to lowercase */ printf(“nThe lowercase equivalent is: %c “, c); printf(“nEnter y to continue: “); reply = getchar(); } }
  • 45.
  • 46. • Bit manipulations • Nuber conversions(packed,unpacked) • Shift operations
  • 47. • Clear bit 5 of a given byte • Converting a lowercase letter to its uppercase equivalent • Specify the instructions and masks would you use to a) set bits 2, 3 and 4 of the ax register b) clear bits 4 and 7 of the bx register • How would al be affected by the following instructions: (a) and al, 00fh (b) and al, 0f0h (c) or al, 00fh (d) or al, 0f0h • Toggle bits 0, 1 and 6 of the value in al (here 67h) • compliment
  • 48. or cx, cx ; compares cx with 0 je label and ax, ax ; compares ax with 0 jg label2