SlideShare a Scribd company logo
Microprocessor Based Systems
Spring 2013
Department of Electrical Engineering
University of Gujrat
• Assembly language program occupies code, data and
stack segment in memory
• Same organization reflected in assembly language
programs as well
• Code data and stack are structured as program segments
• Program segments are translated to memory segments
by assembler
2
Size of code and data, a program can have is determined by
specifying a memory model using .MODEL directive
MODEL memory_model
Model Description
SMALL code in one segment
data in one segment
MEDIUM code in more than one segment
data in one segment
COMPACT code in one segment
data in more than one segment
LARGE code in more than one segment
data in more than one segment
no array larger than 64k bytes
HUGE code in more than one segment
data in more than one segment
arrays may be larger than 64k bytes 3
• A program’s data segment contains all the
variable definitions.
• Constant definitions are often made here as well,
but they may be placed elsewhere in the program
since no memory allocation is involved.
.data directive to declare a data segment
.DATA
WORD1 DW 2
WORD2 DW 5
MSG DB ‘THIS IS A MESSAGE’
MASK EQU 10010111B
4
• The purpose of the stack segment declaration
is to set aside a block of memory (the stack
area) to store the stack.
• The stack area should be big enough to
contain the stack at its maximum size.
.STACK 100H
• If size is omitted, by default 1kB is set aside
5
• The code segment contains a program’s
instructions.
.CODE name
• Inside a code segment, instructions are organized
as procedures.
name PROC
; body of the procedure
name ENDP
• The last line in the program should be the END
directive, followed by name of the main
procedure.
6
MAIN PROC
; instructions go here
MAIN ENDP
; other procedures go here
7
.MODEL SMALL
.STACK 100H
.DATA
; data definitions go here
.CODE
MAIN PROC
; instructions go here
MAIN ENDP
; other procedures go here
END MAIN
8
• CPU communicates with the peripherals
through IO ports
– IN and OUT instructions to access the ports
directly
• Used when fast IO is essential
• Seldom used as
– Port address varies among compluter models
– Easier to program IO with service routine
9
IO Service
routines
BIOS routines
Interact directly with
ports
Stored in ROM
DOS routine
Carry out more
complex tasks
e.g. printing a
character string
10
• I/O service routines
 The Basic Input/Output System (BIOS) routines
 The DOS routines
• The INT (interrupt) instruction is used to
invoke a DOS or BIOS routine.
• INT 16h
– invokes a BIOS routine that performs keyboard
input.
11
• INT 21h may be used to invoke a large number
of DOS functions.
• A particular function is requested by placing a
function number in the AH register and
invoking INT 21h.
12
Input:
AH = 1
Output:
AL = ASCII code if character key is pressed
= 0 if non-character key is pressed
13
MOV AH, 1 ; input key function
INT 21h ; ASCII code in AL
14
Input:
AH = 2
DL = ASCII code of the display character or
= control character
Output:
AL = ASCII code of the display character or
= control character
15
• MOV AH, 2 ; display character function
MOV DL, ‘?’ ; character is ‘?’
INT 21h ; display character
16
ASCII Code HEX Symbol Function
7 BEL beep
8 BS backspace
9 HT tab
A LF line feed (new line)
D CR carriage return (start of current
line)
17
• ECH.ASM will read a character from the
keyboard and display it at the beginning of the
next line.
• The data segment was omitted because no
variables were used.
• When a program terminates, it should return
control to DOS.
• This can be accomplished by executing INT
21h, function 4Ch.
18
TITLE ECHO PROGRAM
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
; display prompt
MOV AH, 2 ; display character function
MOV DL, '?' ; character is '?'
INT 21H ; display it
; input a character
MOV AH, 1 ; read character function
INT 21H ; character in AL
MOV BL, AL ; save it in BL
; go to a new line
MOV AH, 2 ; display character function
MOV DL, 0DH ; carriage return
INT 21H ; execute carriage return
MOV DL, 0AH ; line feed
INT 21H ; execute line feed
; display character
MOV DL, BL ; retrieve character
INT 21H ; and display it
; return to DOS
MOV AH, 4CH ; DOS exit function
INT 21H ; exit to DOS
MAIN ENDP 19
20
• An editor is used to create the preceding
program.
• The .ASM is the conventional extension used
to identify an assembly language source file.
21
• The Microsoft Macro Assembler (MASM) is
used to translate the source file (.ASM file)
into a machine language object file (.OBJ file).
• MASM checks the source file for syntax errors.
• If it finds any, it will display the line number of
each error and a short description.
• C:>MASM File_Name;
22
• The Link program takes one or more object
files, fills in any missing addresses, and
combines the object files into a single
executable file (.EXE file)
• This file can be loaded into memory and run.
• C:>LINK File_Name;
23
• To run it, just type the run file name.
• C:>File_Name
24
Input:
DX = offset address of string.
= The string must end with a ‘$’ character.
25
• LEA is used to load effective address of a
character string.
• LEA destination, source
• MSG DB ‘HELLO!$’
LEA DX, MSG ; get message
MOV AH, 9 ; display string function
INT 21h ; display string
26
• When a program is loaded into memory, DOS
prefaces it 256 byte PSP which contains
information about the program
• DOS places segment no of PSP in DS and ES
before executing the program
• To correct this, a program containing a data
segment must start with these instructions;
MOV AX, @DATA
MOV DS, AX
27
Print String
Program
.MODEL SMALL
.STACK 100H
.DATA
MSG DB 'HELLO!$'
.CODE
MAIN PROC
; initialize DS
MOV AX, @DATA
MOV DS, AX ; intialize DS
; display message
LEA DX, MSG ; get message
MOV AH, 9 ; display string function
INT 21H ; display message
; return to DOS
MOV AH, 4CH
INT 21H ; DOS exit
MAIN ENDP
END MAIN 28
• CASE.ASM begins by prompting the user to
enter a lowercase letter, and on the next line
displays another message with the letter in
uppercase.
• The lowercase letters begin at 61h and the
uppercase letters start at 41h, so subtraction
of 20h from the contents of AL does the
conversion.
29
.MODEL SMALL
.STACK 100H
.DATA
CREQU0DH
LF EQU0AH
MSG1 DB 'ENTER A LOWER CASE LETTER: $'
MSG2 DB CR, LF, 'IN UPPER CASE IT IS: '
CHAR DB ?, '$'
.CODE
MAIN PROC
; intialize DS
MOV AX, @DATA ; get data segment
MOV DS, AX ; intialize DS
; print user prompt
LEA DX, MSG1 ; get first message
MOV AH, 9 ; display string function
INT 21H ; display first message
30
; input a character and convert to upper case
MOV AH, 1 ; read character function
INT 21H ; read a small letter into AL
SUB AL, 20H ; convert it to upper case
MOV CHAR, AL ; and store it
; display on the next line
LEA DX, MSG2 ; get second message
MOV AH, 9 ; display string function
INT 21H ; display message and upper case
letter in front
; DOS exit
MOV AH, 4CH
INT 21H ; DOS exit
MAIN ENDP
END MAIN
31
Ad

More Related Content

What's hot (20)

Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Bilal Amjad
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with types
Ravinder Rautela
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructions
warda aziz
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Bilal Amjad
 
Representation of numbers and characters
Representation of numbers and charactersRepresentation of numbers and characters
Representation of numbers and characters
warda aziz
 
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
Bilal Amjad
 
Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)
Bilal Amjad
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
Mustafa Salah
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
mengistu ketema
 
Assembly language
Assembly language Assembly language
Assembly language
Usama ahmad
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
Robert Almazan
 
Chapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registersChapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registers
warda aziz
 
Unit 3 – assembly language programming
Unit 3 – assembly language programmingUnit 3 – assembly language programming
Unit 3 – assembly language programming
Kartik Sharma
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
karthiga selvaraju
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
jemimajerome
 
Bcd arithmetic instructions
Bcd arithmetic instructionsBcd arithmetic instructions
Bcd arithmetic instructions
Dr. Girish GS
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
kashif Shafqat
 
Arrays and addressing modes
Arrays and addressing modesArrays and addressing modes
Arrays and addressing modes
Bilal Amjad
 
Assembly Langauge Chap 1
Assembly Langauge Chap 1Assembly Langauge Chap 1
Assembly Langauge Chap 1
warda aziz
 
Text Mode Programming in Assembly
Text Mode Programming in AssemblyText Mode Programming in Assembly
Text Mode Programming in Assembly
Javeria Yaqoob
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Bilal Amjad
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with types
Ravinder Rautela
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructions
warda aziz
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Bilal Amjad
 
Representation of numbers and characters
Representation of numbers and charactersRepresentation of numbers and characters
Representation of numbers and characters
warda aziz
 
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
Bilal Amjad
 
Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)
Bilal Amjad
 
Assembly language
Assembly language Assembly language
Assembly language
Usama ahmad
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
Robert Almazan
 
Chapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registersChapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registers
warda aziz
 
Unit 3 – assembly language programming
Unit 3 – assembly language programmingUnit 3 – assembly language programming
Unit 3 – assembly language programming
Kartik Sharma
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
jemimajerome
 
Bcd arithmetic instructions
Bcd arithmetic instructionsBcd arithmetic instructions
Bcd arithmetic instructions
Dr. Girish GS
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
kashif Shafqat
 
Arrays and addressing modes
Arrays and addressing modesArrays and addressing modes
Arrays and addressing modes
Bilal Amjad
 
Assembly Langauge Chap 1
Assembly Langauge Chap 1Assembly Langauge Chap 1
Assembly Langauge Chap 1
warda aziz
 
Text Mode Programming in Assembly
Text Mode Programming in AssemblyText Mode Programming in Assembly
Text Mode Programming in Assembly
Javeria Yaqoob
 

Viewers also liked (16)

Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Bilal Amjad
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
Ashhad Kamal
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Bilal Amjad
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01
jemimajerome
 
Coal 2 - concepts in Assembly Programming
Coal 2 - concepts in Assembly ProgrammingCoal 2 - concepts in Assembly Programming
Coal 2 - concepts in Assembly Programming
Muhammad Taqi Hassan Bukhari
 
Coal 1 - introduction to assembly programming in Assembly Programming
Coal 1 - introduction to assembly programming in Assembly ProgrammingCoal 1 - introduction to assembly programming in Assembly Programming
Coal 1 - introduction to assembly programming in Assembly Programming
Muhammad Taqi Hassan Bukhari
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
Samita Mukesh
 
Unit2 control unit
Unit2 control unitUnit2 control unit
Unit2 control unit
Ashim Saha
 
Processor Basics
Processor BasicsProcessor Basics
Processor Basics
Education Front
 
Flags registor of 8086 processor
Flags registor of 8086 processorFlags registor of 8086 processor
Flags registor of 8086 processor
Fazle Akash
 
Computer Organization and Assembly Language
Computer Organization and Assembly LanguageComputer Organization and Assembly Language
Computer Organization and Assembly Language
fasihuddin90
 
Assembly Language Lecture 2
Assembly Language Lecture 2Assembly Language Lecture 2
Assembly Language Lecture 2
Motaz Saad
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
Ashim Saha
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1
Motaz Saad
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
Education Front
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
Ashim Saha
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Bilal Amjad
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01
jemimajerome
 
Coal 1 - introduction to assembly programming in Assembly Programming
Coal 1 - introduction to assembly programming in Assembly ProgrammingCoal 1 - introduction to assembly programming in Assembly Programming
Coal 1 - introduction to assembly programming in Assembly Programming
Muhammad Taqi Hassan Bukhari
 
Unit2 control unit
Unit2 control unitUnit2 control unit
Unit2 control unit
Ashim Saha
 
Flags registor of 8086 processor
Flags registor of 8086 processorFlags registor of 8086 processor
Flags registor of 8086 processor
Fazle Akash
 
Computer Organization and Assembly Language
Computer Organization and Assembly LanguageComputer Organization and Assembly Language
Computer Organization and Assembly Language
fasihuddin90
 
Assembly Language Lecture 2
Assembly Language Lecture 2Assembly Language Lecture 2
Assembly Language Lecture 2
Motaz Saad
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
Ashim Saha
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1
Motaz Saad
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
Education Front
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
Ashim Saha
 
Ad

Similar to Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction to IBM ec Assembly. Language) (20)

Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
Ahmed M. Abed
 
Chapter 2 programming concepts - I
Chapter 2  programming concepts - IChapter 2  programming concepts - I
Chapter 2 programming concepts - I
SHREEHARI WADAWADAGI
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptxEC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
Manikandan813397
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
Wondeson Emeye
 
03-IntroAssembly.pptx Introduction to assmebly language
03-IntroAssembly.pptx Introduction to assmebly language03-IntroAssembly.pptx Introduction to assmebly language
03-IntroAssembly.pptx Introduction to assmebly language
DanielSolomon72
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
Assembly_80x86- Assembly languages programming and 80x861.pdf
Assembly_80x86- Assembly languages programming and 80x861.pdfAssembly_80x86- Assembly languages programming and 80x861.pdf
Assembly_80x86- Assembly languages programming and 80x861.pdf
ahmedmohammed246810a
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language Programming
Niropam Das
 
Assembly Language lecture university of narowal
Assembly Language lecture university of narowalAssembly Language lecture university of narowal
Assembly Language lecture university of narowal
aneesulhussnain512
 
Exp 03
Exp 03Exp 03
Exp 03
madzflores
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
Abdul Khan
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
kapil078
 
8051h.ppt microcontroller Assembly Language Programming
8051h.ppt microcontroller Assembly Language Programming8051h.ppt microcontroller Assembly Language Programming
8051h.ppt microcontroller Assembly Language Programming
anushkayadav3011
 
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdfIntel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Anonymous611358
 
Wk1to4
Wk1to4Wk1to4
Wk1to4
raymondmy08
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
Kamal Acharya
 
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
Omar Sanchez
 
System Software
System SoftwareSystem Software
System Software
PandurangBiradar2
 
Introduction to Assembly Language & various basic things
Introduction to Assembly Language & various basic thingsIntroduction to Assembly Language & various basic things
Introduction to Assembly Language & various basic things
ishitasabrincse
 
Chapter 3 programming concepts-ii
Chapter 3  programming concepts-iiChapter 3  programming concepts-ii
Chapter 3 programming concepts-ii
SHREEHARI WADAWADAGI
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
Ahmed M. Abed
 
Chapter 2 programming concepts - I
Chapter 2  programming concepts - IChapter 2  programming concepts - I
Chapter 2 programming concepts - I
SHREEHARI WADAWADAGI
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
Wondeson Emeye
 
03-IntroAssembly.pptx Introduction to assmebly language
03-IntroAssembly.pptx Introduction to assmebly language03-IntroAssembly.pptx Introduction to assmebly language
03-IntroAssembly.pptx Introduction to assmebly language
DanielSolomon72
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
Assembly_80x86- Assembly languages programming and 80x861.pdf
Assembly_80x86- Assembly languages programming and 80x861.pdfAssembly_80x86- Assembly languages programming and 80x861.pdf
Assembly_80x86- Assembly languages programming and 80x861.pdf
ahmedmohammed246810a
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language Programming
Niropam Das
 
Assembly Language lecture university of narowal
Assembly Language lecture university of narowalAssembly Language lecture university of narowal
Assembly Language lecture university of narowal
aneesulhussnain512
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
Abdul Khan
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
kapil078
 
8051h.ppt microcontroller Assembly Language Programming
8051h.ppt microcontroller Assembly Language Programming8051h.ppt microcontroller Assembly Language Programming
8051h.ppt microcontroller Assembly Language Programming
anushkayadav3011
 
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdfIntel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Anonymous611358
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
Kamal Acharya
 
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
Omar Sanchez
 
Introduction to Assembly Language & various basic things
Introduction to Assembly Language & various basic thingsIntroduction to Assembly Language & various basic things
Introduction to Assembly Language & various basic things
ishitasabrincse
 
Ad

More from Bilal Amjad (11)

IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino
Bilal Amjad
 
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink) Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Bilal Amjad
 
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Bilal Amjad
 
Big Data in Smart Grid
Big Data in Smart GridBig Data in Smart Grid
Big Data in Smart Grid
Bilal Amjad
 
Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)
Bilal Amjad
 
bubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languagebubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly language
Bilal Amjad
 
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
Bilal Amjad
 
Limit of complex number
Limit of complex numberLimit of complex number
Limit of complex number
Bilal Amjad
 
simple combinational lock
simple combinational locksimple combinational lock
simple combinational lock
Bilal Amjad
 
4-bit camparator
4-bit camparator4-bit camparator
4-bit camparator
Bilal Amjad
 
Orthogonal trajectories
Orthogonal trajectoriesOrthogonal trajectories
Orthogonal trajectories
Bilal Amjad
 
IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino
Bilal Amjad
 
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink) Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Bilal Amjad
 
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Bilal Amjad
 
Big Data in Smart Grid
Big Data in Smart GridBig Data in Smart Grid
Big Data in Smart Grid
Bilal Amjad
 
Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)
Bilal Amjad
 
bubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languagebubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly language
Bilal Amjad
 
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
Bilal Amjad
 
Limit of complex number
Limit of complex numberLimit of complex number
Limit of complex number
Bilal Amjad
 
simple combinational lock
simple combinational locksimple combinational lock
simple combinational lock
Bilal Amjad
 
4-bit camparator
4-bit camparator4-bit camparator
4-bit camparator
Bilal Amjad
 
Orthogonal trajectories
Orthogonal trajectoriesOrthogonal trajectories
Orthogonal trajectories
Bilal Amjad
 

Recently uploaded (20)

Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
Resistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff modelResistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff model
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 

Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction to IBM ec Assembly. Language)

  • 1. Microprocessor Based Systems Spring 2013 Department of Electrical Engineering University of Gujrat
  • 2. • Assembly language program occupies code, data and stack segment in memory • Same organization reflected in assembly language programs as well • Code data and stack are structured as program segments • Program segments are translated to memory segments by assembler 2
  • 3. Size of code and data, a program can have is determined by specifying a memory model using .MODEL directive MODEL memory_model Model Description SMALL code in one segment data in one segment MEDIUM code in more than one segment data in one segment COMPACT code in one segment data in more than one segment LARGE code in more than one segment data in more than one segment no array larger than 64k bytes HUGE code in more than one segment data in more than one segment arrays may be larger than 64k bytes 3
  • 4. • A program’s data segment contains all the variable definitions. • Constant definitions are often made here as well, but they may be placed elsewhere in the program since no memory allocation is involved. .data directive to declare a data segment .DATA WORD1 DW 2 WORD2 DW 5 MSG DB ‘THIS IS A MESSAGE’ MASK EQU 10010111B 4
  • 5. • The purpose of the stack segment declaration is to set aside a block of memory (the stack area) to store the stack. • The stack area should be big enough to contain the stack at its maximum size. .STACK 100H • If size is omitted, by default 1kB is set aside 5
  • 6. • The code segment contains a program’s instructions. .CODE name • Inside a code segment, instructions are organized as procedures. name PROC ; body of the procedure name ENDP • The last line in the program should be the END directive, followed by name of the main procedure. 6
  • 7. MAIN PROC ; instructions go here MAIN ENDP ; other procedures go here 7
  • 8. .MODEL SMALL .STACK 100H .DATA ; data definitions go here .CODE MAIN PROC ; instructions go here MAIN ENDP ; other procedures go here END MAIN 8
  • 9. • CPU communicates with the peripherals through IO ports – IN and OUT instructions to access the ports directly • Used when fast IO is essential • Seldom used as – Port address varies among compluter models – Easier to program IO with service routine 9
  • 10. IO Service routines BIOS routines Interact directly with ports Stored in ROM DOS routine Carry out more complex tasks e.g. printing a character string 10
  • 11. • I/O service routines  The Basic Input/Output System (BIOS) routines  The DOS routines • The INT (interrupt) instruction is used to invoke a DOS or BIOS routine. • INT 16h – invokes a BIOS routine that performs keyboard input. 11
  • 12. • INT 21h may be used to invoke a large number of DOS functions. • A particular function is requested by placing a function number in the AH register and invoking INT 21h. 12
  • 13. Input: AH = 1 Output: AL = ASCII code if character key is pressed = 0 if non-character key is pressed 13
  • 14. MOV AH, 1 ; input key function INT 21h ; ASCII code in AL 14
  • 15. Input: AH = 2 DL = ASCII code of the display character or = control character Output: AL = ASCII code of the display character or = control character 15
  • 16. • MOV AH, 2 ; display character function MOV DL, ‘?’ ; character is ‘?’ INT 21h ; display character 16
  • 17. ASCII Code HEX Symbol Function 7 BEL beep 8 BS backspace 9 HT tab A LF line feed (new line) D CR carriage return (start of current line) 17
  • 18. • ECH.ASM will read a character from the keyboard and display it at the beginning of the next line. • The data segment was omitted because no variables were used. • When a program terminates, it should return control to DOS. • This can be accomplished by executing INT 21h, function 4Ch. 18
  • 19. TITLE ECHO PROGRAM .MODEL SMALL .STACK 100H .CODE MAIN PROC ; display prompt MOV AH, 2 ; display character function MOV DL, '?' ; character is '?' INT 21H ; display it ; input a character MOV AH, 1 ; read character function INT 21H ; character in AL MOV BL, AL ; save it in BL ; go to a new line MOV AH, 2 ; display character function MOV DL, 0DH ; carriage return INT 21H ; execute carriage return MOV DL, 0AH ; line feed INT 21H ; execute line feed ; display character MOV DL, BL ; retrieve character INT 21H ; and display it ; return to DOS MOV AH, 4CH ; DOS exit function INT 21H ; exit to DOS MAIN ENDP 19
  • 20. 20
  • 21. • An editor is used to create the preceding program. • The .ASM is the conventional extension used to identify an assembly language source file. 21
  • 22. • The Microsoft Macro Assembler (MASM) is used to translate the source file (.ASM file) into a machine language object file (.OBJ file). • MASM checks the source file for syntax errors. • If it finds any, it will display the line number of each error and a short description. • C:>MASM File_Name; 22
  • 23. • The Link program takes one or more object files, fills in any missing addresses, and combines the object files into a single executable file (.EXE file) • This file can be loaded into memory and run. • C:>LINK File_Name; 23
  • 24. • To run it, just type the run file name. • C:>File_Name 24
  • 25. Input: DX = offset address of string. = The string must end with a ‘$’ character. 25
  • 26. • LEA is used to load effective address of a character string. • LEA destination, source • MSG DB ‘HELLO!$’ LEA DX, MSG ; get message MOV AH, 9 ; display string function INT 21h ; display string 26
  • 27. • When a program is loaded into memory, DOS prefaces it 256 byte PSP which contains information about the program • DOS places segment no of PSP in DS and ES before executing the program • To correct this, a program containing a data segment must start with these instructions; MOV AX, @DATA MOV DS, AX 27
  • 28. Print String Program .MODEL SMALL .STACK 100H .DATA MSG DB 'HELLO!$' .CODE MAIN PROC ; initialize DS MOV AX, @DATA MOV DS, AX ; intialize DS ; display message LEA DX, MSG ; get message MOV AH, 9 ; display string function INT 21H ; display message ; return to DOS MOV AH, 4CH INT 21H ; DOS exit MAIN ENDP END MAIN 28
  • 29. • CASE.ASM begins by prompting the user to enter a lowercase letter, and on the next line displays another message with the letter in uppercase. • The lowercase letters begin at 61h and the uppercase letters start at 41h, so subtraction of 20h from the contents of AL does the conversion. 29
  • 30. .MODEL SMALL .STACK 100H .DATA CREQU0DH LF EQU0AH MSG1 DB 'ENTER A LOWER CASE LETTER: $' MSG2 DB CR, LF, 'IN UPPER CASE IT IS: ' CHAR DB ?, '$' .CODE MAIN PROC ; intialize DS MOV AX, @DATA ; get data segment MOV DS, AX ; intialize DS ; print user prompt LEA DX, MSG1 ; get first message MOV AH, 9 ; display string function INT 21H ; display first message 30
  • 31. ; input a character and convert to upper case MOV AH, 1 ; read character function INT 21H ; read a small letter into AL SUB AL, 20H ; convert it to upper case MOV CHAR, AL ; and store it ; display on the next line LEA DX, MSG2 ; get second message MOV AH, 9 ; display string function INT 21H ; display message and upper case letter in front ; DOS exit MOV AH, 4CH INT 21H ; DOS exit MAIN ENDP END MAIN 31