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

More Related Content

What's hot (20)

PDF
Assembly language (coal)
Hareem Aslam
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Bilal Amjad
 
PDF
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
warda aziz
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Bilal Amjad
 
PPTX
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
PDF
Chapter 6 Flow control Instructions
warda aziz
 
PPTX
Part I:Introduction to assembly language
Ahmed M. Abed
 
PDF
Assembly Langauge Chap 1
warda aziz
 
PDF
Addressing modes of 80386
PDFSHARE
 
PPTX
Instruction Set Architecture
Dilum Bandara
 
PPTX
Binary and hex input/output (in 8086 assembuly langyage)
Bilal Amjad
 
PPTX
Flags registers
saman Iftikhar
 
PPTX
Addressing Modes Of 8086
Ikhlas Rahman
 
PPTX
bubble sorting of an array in 8086 assembly language
Bilal Amjad
 
PPT
Introduction to Assembly Language
Motaz Saad
 
PDF
22cs201 COMPUTER ORGANIZATION AND ARCHITECTURE
Kathirvel Ayyaswamy
 
PDF
Unit 3 – assembly language programming
Kartik Sharma
 
PPT
09 Arithmetic
Jeanie Delos Arcos
 
PPT
Instruction set of 8086
Tirumalesh Nizampatnam
 
PPT
Assembly Language Lecture 4
Motaz Saad
 
Assembly language (coal)
Hareem Aslam
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Bilal Amjad
 
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
warda aziz
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
Chapter 6 Flow control Instructions
warda aziz
 
Part I:Introduction to assembly language
Ahmed M. Abed
 
Assembly Langauge Chap 1
warda aziz
 
Addressing modes of 80386
PDFSHARE
 
Instruction Set Architecture
Dilum Bandara
 
Binary and hex input/output (in 8086 assembuly langyage)
Bilal Amjad
 
Flags registers
saman Iftikhar
 
Addressing Modes Of 8086
Ikhlas Rahman
 
bubble sorting of an array in 8086 assembly language
Bilal Amjad
 
Introduction to Assembly Language
Motaz Saad
 
22cs201 COMPUTER ORGANIZATION AND ARCHITECTURE
Kathirvel Ayyaswamy
 
Unit 3 – assembly language programming
Kartik Sharma
 
09 Arithmetic
Jeanie Delos Arcos
 
Instruction set of 8086
Tirumalesh Nizampatnam
 
Assembly Language Lecture 4
Motaz Saad
 

Viewers also liked (16)

PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Bilal Amjad
 
PPT
Chapter 1
Ashhad Kamal
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Bilal Amjad
 
PPTX
8086 microprocessor-architecture-120207111857-phpapp01
jemimajerome
 
PDF
Coal 2 - concepts in Assembly Programming
Muhammad Taqi Hassan Bukhari
 
PDF
Coal 1 - introduction to assembly programming in Assembly Programming
Muhammad Taqi Hassan Bukhari
 
PPT
Kleene's theorem
Samita Mukesh
 
PPT
Unit2 control unit
Ashim Saha
 
PPTX
Processor Basics
Education Front
 
PPTX
Flags registor of 8086 processor
Fazle Akash
 
PPT
Computer Organization and Assembly Language
fasihuddin90
 
PPT
Assembly Language Lecture 2
Motaz Saad
 
PPT
Stack and subroutine
Ashim Saha
 
PPT
Assembly Language Lecture 1
Motaz Saad
 
PPT
Assembly Language Basics
Education Front
 
PPT
Assembly language programming(unit 4)
Ashim Saha
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Bilal Amjad
 
Chapter 1
Ashhad Kamal
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Bilal Amjad
 
8086 microprocessor-architecture-120207111857-phpapp01
jemimajerome
 
Coal 2 - concepts in Assembly Programming
Muhammad Taqi Hassan Bukhari
 
Coal 1 - introduction to assembly programming in Assembly Programming
Muhammad Taqi Hassan Bukhari
 
Kleene's theorem
Samita Mukesh
 
Unit2 control unit
Ashim Saha
 
Processor Basics
Education Front
 
Flags registor of 8086 processor
Fazle Akash
 
Computer Organization and Assembly Language
fasihuddin90
 
Assembly Language Lecture 2
Motaz Saad
 
Stack and subroutine
Ashim Saha
 
Assembly Language Lecture 1
Motaz Saad
 
Assembly Language Basics
Education Front
 
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)

PPTX
Part III: Assembly Language
Ahmed M. Abed
 
PPTX
Chapter 2 programming concepts - I
SHREEHARI WADAWADAGI
 
PPTX
EC8691-MPMC-PPT.pptx
Manikandan813397
 
PPTX
Microprocessor chapter 9 - assembly language programming
Wondeson Emeye
 
PPTX
03-IntroAssembly.pptx Introduction to assmebly language
DanielSolomon72
 
PPT
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
PDF
Assembly_80x86- Assembly languages programming and 80x861.pdf
ahmedmohammed246810a
 
PPTX
Assembly Language Programming
Niropam Das
 
PPTX
Assembly Language lecture university of narowal
aneesulhussnain512
 
PDF
Exp 03
madzflores
 
PPT
Lec 04 intro assembly
Abdul Khan
 
PPTX
cmp104 lec 8
kapil078
 
PPT
chapt_5+6AssemblyLanguagecompleteclear.ppt
mubashrabashir540
 
PPT
8051h.ppt microcontroller Assembly Language Programming
anushkayadav3011
 
PDF
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Anonymous611358
 
PPT
Wk1to4
raymondmy08
 
PPTX
Programming the basic computer
Kamal Acharya
 
PDF
Assembler Programming
Omar Sanchez
 
PPTX
System Software
PandurangBiradar2
 
PPTX
Introduction to Assembly Language & various basic things
ishitasabrincse
 
Part III: Assembly Language
Ahmed M. Abed
 
Chapter 2 programming concepts - I
SHREEHARI WADAWADAGI
 
EC8691-MPMC-PPT.pptx
Manikandan813397
 
Microprocessor chapter 9 - assembly language programming
Wondeson Emeye
 
03-IntroAssembly.pptx Introduction to assmebly language
DanielSolomon72
 
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
Assembly_80x86- Assembly languages programming and 80x861.pdf
ahmedmohammed246810a
 
Assembly Language Programming
Niropam Das
 
Assembly Language lecture university of narowal
aneesulhussnain512
 
Exp 03
madzflores
 
Lec 04 intro assembly
Abdul Khan
 
cmp104 lec 8
kapil078
 
chapt_5+6AssemblyLanguagecompleteclear.ppt
mubashrabashir540
 
8051h.ppt microcontroller Assembly Language Programming
anushkayadav3011
 
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Anonymous611358
 
Wk1to4
raymondmy08
 
Programming the basic computer
Kamal Acharya
 
Assembler Programming
Omar Sanchez
 
System Software
PandurangBiradar2
 
Introduction to Assembly Language & various basic things
ishitasabrincse
 
Ad

More from Bilal Amjad (11)

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

Recently uploaded (20)

PDF
IoT - Unit 2 (Internet of Things-Concepts) - PPT.pdf
dipakraut82
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PPTX
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
PPTX
Innowell Capability B0425 - Commercial Buildings.pptx
regobertroza
 
PDF
Additional Information in midterm CPE024 (1).pdf
abolisojoy
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
PPTX
Pharmaceuticals and fine chemicals.pptxx
jaypa242004
 
PDF
BioSensors glucose monitoring, cholestrol
nabeehasahar1
 
PPTX
site survey architecture student B.arch.
sri02032006
 
PDF
monopile foundation seminar topic for civil engineering students
Ahina5
 
PDF
PRIZ Academy - Change Flow Thinking Master Change with Confidence.pdf
PRIZ Guru
 
PDF
6th International Conference on Machine Learning Techniques and Data Science ...
ijistjournal
 
PDF
POWER PLANT ENGINEERING (R17A0326).pdf..
haneefachosa123
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
PPTX
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 
PDF
Book.pdf01_Intro.ppt algorithm for preperation stu used
archu26
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
IoT - Unit 2 (Internet of Things-Concepts) - PPT.pdf
dipakraut82
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
Innowell Capability B0425 - Commercial Buildings.pptx
regobertroza
 
Additional Information in midterm CPE024 (1).pdf
abolisojoy
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
Pharmaceuticals and fine chemicals.pptxx
jaypa242004
 
BioSensors glucose monitoring, cholestrol
nabeehasahar1
 
site survey architecture student B.arch.
sri02032006
 
monopile foundation seminar topic for civil engineering students
Ahina5
 
PRIZ Academy - Change Flow Thinking Master Change with Confidence.pdf
PRIZ Guru
 
6th International Conference on Machine Learning Techniques and Data Science ...
ijistjournal
 
POWER PLANT ENGINEERING (R17A0326).pdf..
haneefachosa123
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 
Book.pdf01_Intro.ppt algorithm for preperation stu used
archu26
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 

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