SlideShare a Scribd company logo
1 of 27
ASSEMBLY LANGUAGE
Ahmed M. Abed
Teaching assistant – Islamic university of Gaza
aabed91@gmail.com
REGISTERS
GENERAL PURPOSE REGISTERS
SEGMENT REGISTERS
 CS - points at the segment containing the current program.
 DS - generally points at segment where variables are defined.
 ES - extra segment register, it's up to a coder to define its usage.
 SS - points at the segment containing the stack.
 Although it is possible to store any data in the segment registers, this is never a
good idea. the segment registers have a very special purpose - pointing at
accessible blocks of memory.
FIRST PROGRAM IN ASSEMBLY
.CODE
MAIN PROC
MOV AX,@DATA ;Set address of data
TITLE

A04ASM1 (EXE) Move and add operations

MOV

DS,AX

; segment in DS

.STACK

MOV

AX,FLDD

;Move 0215 to AX

.DATA

ADD

AX,FLDE

;Add 0125 to AX

FLDD

DW

215

MOV

FLDF,AX

FLDE

DW

125

MOV

AX,4C00H

FLDF

DW

?

INT

21H

;Store sum in FLDF
;End processing

MAIN ENDP

;End of procedure

END MAIN

;End of program
CONT.

 TITLE line (optional)
 Contains a brief heading of the program and the disk file name.
 .STACK directive
 Tells the assembler to define a runtime stack for the program
 The size of the stack can be optionally specified by this directive
 The runtime stack is required for procedure calls
CONT.

 .DATA directive
 Defines an area in memory for the program data
 The program's variables should be defined under this directive
 Assembler will allocate and initialize the storage of variables
 .CODE directive
 Defines the code section of a program containing instructions
 Assembler will place the instructions in the code area in memory
CONT.

 PROC and ENDP directives
 Used to define procedures

 As a convention, we will define main as the first procedure
 Additional procedures can be defined after main
 END directive
 Marks the end of a program
 Identifies the name (main) of the program’s startup procedure
EXAMPLE
.model small
.data
msg DB 'Hello, World'
msg1 DB '$'
.code
mov ax,@DATA

mov ds,ax
mov ah,9
mov dx,offset msg
int 21h

mov ah,4ch
int 21h
 end
ANALYSIS OF THE EXAMPLE
MODEL

is a directive to tell the assembler
how to segment memory.
There are six models of an assembly
program
• Tiny : both code and data in same
64KB (one segment). Files with .com
extensions.
• Small: all data in one segment &
all code in one segment.
• Medium: all data in one segment,
but code in more than one
segment.
• Compact: Data in more than one
segment, all code in one segment, no
array may exceed 64KB
• Large: Both data and code in more
than one segment.
• Flat: Protected mode. Uses 32-bit
offsets for code and data
CONT.
.DATA

is a directive to put in data segment.

.CODE is a directive to put in code
segment.

is a directive to put in code segment.

@Data

is a default address of data segment to
put it in ax register.

mov ax, @data
mov ds, ax

As note we can't put data in ds register
directly. So we use intermediate register
(ax) as in the mov ds, ax

mov ah, 9

Put the service 9 in ah.

int 21h

(Interrupt 21 hexa), it has many services
like9,8,2, and each one has special
work.

mov ah,4ch
int 21h

The two statements to terminate the
execution of the program.

END

is a directive to indicate the end of file
SOFTWARE INTERRUPTS
 A software interrupt is a call to an operating system procedure. Most of these procedures,
called interrupt handlers , provide input-output capability to application programs.
They are used for such tasks as the following:
Displaying characters and strings

Reading characters and strings from the keyboard
Displaying text in color
Opening and closing files
Reading data from files
Writing data to files
Setting and retrieving the system time and date
INT INSTRUCTION
 instruction calls a system subroutine also known as an interrupt
handler.
 Before the INT instruction executes, one or more parameters
must be inserted in registers.
 A number identifying the particular procedure must be moved to the
AH register.
 Depending on the function, other values may have to be passed to
the interrupt in registers.

 The syntax is

INT number

 Where number is an integer in the range 0 to FF hexadecimal.
COMMON INTERRUPTS
INT 10h Video Services
• Procedures that display routines that control the cursor position, write text
in color, scroll the screen, and display video graphics.

INT 16h Keyboard Services
• Procedures that read the keyboard and check its status.

INT 17h Printer Services.
• Procedures that initialize, print, and return the printer status.

INT 1Ah Time of Day.
• Procedure that gets the number of clock ticks since the machine was
turned on or sets the counter to a new value.

INT 1Ch User Timer Interrupt.
• An empty procedure that is executed 18.2 times per second.
CONT.
INT 21h MS-DOS Services.
• Procedures that provide input-output, file handling, and memory
management. Also known as MS-DOS function calls.

 MS-DOS provides a lot of easy-to-use functions for displaying
text on the console.
 There are about 200 different functions supported by this
interrupt, identified by a function number placed in the AH
register.
 A number of functions require that the 32-bit address of an input
parameter be stored in the DS:DX registers. DS, the data
segment register, is usually set to your program’s data area.
MS-DOS FUNCTION CALLS (INT 21H)
1.

Function 4Ch

 Ends the current process (program), returns an optional 8-bit
return code to the calling process.
 A return code of 0 usually indicates successful completion.
mov ah,4Ch
mov al,0
int 21h
; Same as:
.EXIT 0

; terminate process
; return code
CONT.
 2-Function 02h

INT 21h Function 2
Description

Write a single character to standard output and advance the
cursor one column forward

Receives

AH =2
DL =character value

Returns

Nothing

Sample call

mov ah, 2
mov dl , 'A'
int 21h
CONT.
 3-Function 06h

INT 21h Function 6
Description

Write a character to standard output

Receives

AH = 6
DL = character value

Sample call

mov ah , 6
mov dl , "A"
int 21h

Notes

Unlike other INT 21h functions, this one does not filter
(interpret) ASCII control characters.
CONT.
 4-Function 05h

INT 21h Function 5
Description

Write a single character to the printer

Receives

AH = 5
DL = character value

Returns

Nothing

Sample call

mov ah , 5
mov dl , "Z“
int 21h

Notes

Unlike other INT 21h functions, this one does not filter
(interpret) ASCII control characters.

; select printer output
; character to be printed
; call MS-DOS
CONT.
 5-Function 09h

INT 21h Function9
Description

Write a $-terminated string to standard output

Receives

AH = 9
DS:DX = segment/offset of the string

Returns

Nothing

Sample call

.data
string BYTE "This is a string$"
.code
mov ah , 9
mov dx , OFFSET string
int 21h

Notes

The string must be terminated by a dollar-sign character ($).
CONT.
 6-Function 40h

INT 21h Function 40h
Description

Write an array of bytes to a file or device

Receives

AH = 40h
BX = file or device handle (console 1)
CX = number of bytes to write
DS:DX = address of array

Returns

AX = number of bytes written

Sample call

message DB "Hello, world"
.code
mov ah , 40h
mov bx , 1
mov cx , LENGTHOF message
mov dx , OFFSET message
int 21h
CONT. OF INT 21H FUNCTIONS
 7-Function 01h

INT 21h Function 1
Description

Read a single character from standard input

Receives

AH = 1

Returns

AX = character (ASCII code)

Sample call

character (ASCII code)

Notes

If no character is present in the input buffer, the program
waits. This function echoes the character to standard
output.
DATE/TIME FUNCTIONS
8-Function 2Ah

INT 21h Function 2Ah
Description

Get the system date

Receives

AH = 2Ah

Returns

CX = year
DH, DL = month, day
AL = day of week (Sunday 0, Monday 1, etc.)

Sample call

mov ah,2Ah
int 21h
mov year,cx
mov month,dh
mov day,dl
mov dayOfWeek,al
CONT.
9-Function 2Bh

INT 21h Function 2Bh
Description

Set the system date

Receives

AH =2Bh
CX =year
DH =month
DL =day

Returns

If the change was successful, AL 0; otherwise, AL FFh.

Sample call

mov ah,2Bh
mov cx,year
mov dh,month
mov dl,day
int 21h
CONT.
9-Function 2Ch

INT 21h Function 2Ch
Description

Get the system time

Receives

AH 2Ch

Returns

CH = hours (0 – 23)
CL = minutes (0 – 59)
DH = seconds (0 – 59)
DL = hundredths of seconds (usually not accurate)

Sample call

mov ah,2Ch
int 21h
mov hours,ch
mov minutes,cl
mov seconds,dh
CONT.
9-Function 2Dh

INT 21h Function 2Dh
Description

Set the system time

Receives

AH = 2Dh
CH = hours (0 – 23)
CL = minutes (0 – 59)
DH = seconds (0 – 59)

Returns

If the change was successful, AL 0; otherwise, AL FFh.

Sample call

mov ah,2Dh
mov ch,hours
mov cl,minutes
mov dh,seconds
int 21h
EXAMPLE


TITLE Hello World Program (Hello.asm)



.MODEL small



.STACK 100h



.data



message DB "Hello, world!",0dh,0ah



data_size= $ -offset message



.code



main PROC



mov ax,@data ; initialize DS



mov ds,ax



mov ah,40h ; write to file/device



mov bx,1 ; output handle



mov cx,data_size



mov dx,OFFSET message ; addr of buffer



int 21h



.EXIT



main ENDP



END main

; number of bytes

More Related Content

What's hot

Advanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptAdvanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptMuhammad Sikandar Mustafa
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly languageMir Majid
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Shehrevar Davierwala
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programmingWondeson Emeye
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly LanguageMotaz Saad
 
Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Bhatt Balkrishna
 
Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2Khaja Dileef
 
Examinable Question and answer system programming
Examinable Question and answer system programmingExaminable Question and answer system programming
Examinable Question and answer system programmingMakerere university
 
system software 16 marks
system software 16 markssystem software 16 marks
system software 16 marksvvcetit
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4Motaz Saad
 
Unit 4 assembly language programming
Unit 4   assembly language programmingUnit 4   assembly language programming
Unit 4 assembly language programmingKartik Sharma
 
Organization of the ibm personal computers
Organization of the ibm personal computersOrganization of the ibm personal computers
Organization of the ibm personal computerswarda aziz
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)Selomon birhane
 
Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Urvashi Singh
 

What's hot (20)

Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Advanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptAdvanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter ppt
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly language
 
8086 assembly
8086 assembly8086 assembly
8086 assembly
 
Assembly language programming intro
Assembly language programming introAssembly language programming intro
Assembly language programming intro
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
 
Lecture5(1)
Lecture5(1)Lecture5(1)
Lecture5(1)
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly Language
 
Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming
 
Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2
 
Examinable Question and answer system programming
Examinable Question and answer system programmingExaminable Question and answer system programming
Examinable Question and answer system programming
 
system software 16 marks
system software 16 markssystem software 16 marks
system software 16 marks
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
 
Unit 4 assembly language programming
Unit 4   assembly language programmingUnit 4   assembly language programming
Unit 4 assembly language programming
 
Organization of the ibm personal computers
Organization of the ibm personal computersOrganization of the ibm personal computers
Organization of the ibm personal computers
 
Mp &mc programs
Mp &mc programsMp &mc programs
Mp &mc programs
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
 
Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086
 

Similar to Part III: Assembly Language

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.pdfAnonymous611358
 
Keyboard interrupt
Keyboard interruptKeyboard interrupt
Keyboard interruptTech_MX
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutineAshim Saha
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assemblyAbdul Khan
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language BasicsEducation Front
 
Introduction of 8086 micro processor .
Introduction of 8086 micro processor .Introduction of 8086 micro processor .
Introduction of 8086 micro processor .Siraj Ahmed
 
6_2018_11_23!09_24_56_PM (1).pptx
6_2018_11_23!09_24_56_PM (1).pptx6_2018_11_23!09_24_56_PM (1).pptx
6_2018_11_23!09_24_56_PM (1).pptxHebaEng
 
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler ProgrammingOmar Sanchez
 
Programming basic computer
Programming basic computerProgramming basic computer
Programming basic computerMartial Kouadio
 
Microprocessor (1)
Microprocessor (1)Microprocessor (1)
Microprocessor (1)Muhd Azlan
 
Introduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorIntroduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorDarling Jemima
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language ProgrammingNiropam Das
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set ArchitectureDilum Bandara
 

Similar to Part III: Assembly Language (20)

Wk1to4
Wk1to4Wk1to4
Wk1to4
 
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
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Keyboard interrupt
Keyboard interruptKeyboard interrupt
Keyboard interrupt
 
Alp 05
Alp 05Alp 05
Alp 05
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Introduction of 8086 micro processor .
Introduction of 8086 micro processor .Introduction of 8086 micro processor .
Introduction of 8086 micro processor .
 
6_2018_11_23!09_24_56_PM (1).pptx
6_2018_11_23!09_24_56_PM (1).pptx6_2018_11_23!09_24_56_PM (1).pptx
6_2018_11_23!09_24_56_PM (1).pptx
 
Alp 05
Alp 05Alp 05
Alp 05
 
Alp 05
Alp 05Alp 05
Alp 05
 
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
 
Programming basic computer
Programming basic computerProgramming basic computer
Programming basic computer
 
12 mt06ped008
12 mt06ped008 12 mt06ped008
12 mt06ped008
 
Microprocessor (1)
Microprocessor (1)Microprocessor (1)
Microprocessor (1)
 
Introduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorIntroduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM Processor
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language Programming
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
 

Recently uploaded

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Part III: Assembly Language

  • 1. ASSEMBLY LANGUAGE Ahmed M. Abed Teaching assistant – Islamic university of Gaza aabed91@gmail.com
  • 4. SEGMENT REGISTERS  CS - points at the segment containing the current program.  DS - generally points at segment where variables are defined.  ES - extra segment register, it's up to a coder to define its usage.  SS - points at the segment containing the stack.  Although it is possible to store any data in the segment registers, this is never a good idea. the segment registers have a very special purpose - pointing at accessible blocks of memory.
  • 5. FIRST PROGRAM IN ASSEMBLY .CODE MAIN PROC MOV AX,@DATA ;Set address of data TITLE A04ASM1 (EXE) Move and add operations MOV DS,AX ; segment in DS .STACK MOV AX,FLDD ;Move 0215 to AX .DATA ADD AX,FLDE ;Add 0125 to AX FLDD DW 215 MOV FLDF,AX FLDE DW 125 MOV AX,4C00H FLDF DW ? INT 21H ;Store sum in FLDF ;End processing MAIN ENDP ;End of procedure END MAIN ;End of program
  • 6. CONT.  TITLE line (optional)  Contains a brief heading of the program and the disk file name.  .STACK directive  Tells the assembler to define a runtime stack for the program  The size of the stack can be optionally specified by this directive  The runtime stack is required for procedure calls
  • 7. CONT.  .DATA directive  Defines an area in memory for the program data  The program's variables should be defined under this directive  Assembler will allocate and initialize the storage of variables  .CODE directive  Defines the code section of a program containing instructions  Assembler will place the instructions in the code area in memory
  • 8. CONT.  PROC and ENDP directives  Used to define procedures  As a convention, we will define main as the first procedure  Additional procedures can be defined after main  END directive  Marks the end of a program  Identifies the name (main) of the program’s startup procedure
  • 9. EXAMPLE .model small .data msg DB 'Hello, World' msg1 DB '$' .code mov ax,@DATA mov ds,ax mov ah,9 mov dx,offset msg int 21h mov ah,4ch int 21h  end
  • 10. ANALYSIS OF THE EXAMPLE MODEL is a directive to tell the assembler how to segment memory. There are six models of an assembly program • Tiny : both code and data in same 64KB (one segment). Files with .com extensions. • Small: all data in one segment & all code in one segment. • Medium: all data in one segment, but code in more than one segment. • Compact: Data in more than one segment, all code in one segment, no array may exceed 64KB • Large: Both data and code in more than one segment. • Flat: Protected mode. Uses 32-bit offsets for code and data
  • 11. CONT. .DATA is a directive to put in data segment. .CODE is a directive to put in code segment. is a directive to put in code segment. @Data is a default address of data segment to put it in ax register. mov ax, @data mov ds, ax As note we can't put data in ds register directly. So we use intermediate register (ax) as in the mov ds, ax mov ah, 9 Put the service 9 in ah. int 21h (Interrupt 21 hexa), it has many services like9,8,2, and each one has special work. mov ah,4ch int 21h The two statements to terminate the execution of the program. END is a directive to indicate the end of file
  • 12. SOFTWARE INTERRUPTS  A software interrupt is a call to an operating system procedure. Most of these procedures, called interrupt handlers , provide input-output capability to application programs. They are used for such tasks as the following: Displaying characters and strings Reading characters and strings from the keyboard Displaying text in color Opening and closing files Reading data from files Writing data to files Setting and retrieving the system time and date
  • 13. INT INSTRUCTION  instruction calls a system subroutine also known as an interrupt handler.  Before the INT instruction executes, one or more parameters must be inserted in registers.  A number identifying the particular procedure must be moved to the AH register.  Depending on the function, other values may have to be passed to the interrupt in registers.  The syntax is INT number  Where number is an integer in the range 0 to FF hexadecimal.
  • 14. COMMON INTERRUPTS INT 10h Video Services • Procedures that display routines that control the cursor position, write text in color, scroll the screen, and display video graphics. INT 16h Keyboard Services • Procedures that read the keyboard and check its status. INT 17h Printer Services. • Procedures that initialize, print, and return the printer status. INT 1Ah Time of Day. • Procedure that gets the number of clock ticks since the machine was turned on or sets the counter to a new value. INT 1Ch User Timer Interrupt. • An empty procedure that is executed 18.2 times per second.
  • 15. CONT. INT 21h MS-DOS Services. • Procedures that provide input-output, file handling, and memory management. Also known as MS-DOS function calls.  MS-DOS provides a lot of easy-to-use functions for displaying text on the console.  There are about 200 different functions supported by this interrupt, identified by a function number placed in the AH register.  A number of functions require that the 32-bit address of an input parameter be stored in the DS:DX registers. DS, the data segment register, is usually set to your program’s data area.
  • 16. MS-DOS FUNCTION CALLS (INT 21H) 1. Function 4Ch  Ends the current process (program), returns an optional 8-bit return code to the calling process.  A return code of 0 usually indicates successful completion. mov ah,4Ch mov al,0 int 21h ; Same as: .EXIT 0 ; terminate process ; return code
  • 17. CONT.  2-Function 02h INT 21h Function 2 Description Write a single character to standard output and advance the cursor one column forward Receives AH =2 DL =character value Returns Nothing Sample call mov ah, 2 mov dl , 'A' int 21h
  • 18. CONT.  3-Function 06h INT 21h Function 6 Description Write a character to standard output Receives AH = 6 DL = character value Sample call mov ah , 6 mov dl , "A" int 21h Notes Unlike other INT 21h functions, this one does not filter (interpret) ASCII control characters.
  • 19. CONT.  4-Function 05h INT 21h Function 5 Description Write a single character to the printer Receives AH = 5 DL = character value Returns Nothing Sample call mov ah , 5 mov dl , "Z“ int 21h Notes Unlike other INT 21h functions, this one does not filter (interpret) ASCII control characters. ; select printer output ; character to be printed ; call MS-DOS
  • 20. CONT.  5-Function 09h INT 21h Function9 Description Write a $-terminated string to standard output Receives AH = 9 DS:DX = segment/offset of the string Returns Nothing Sample call .data string BYTE "This is a string$" .code mov ah , 9 mov dx , OFFSET string int 21h Notes The string must be terminated by a dollar-sign character ($).
  • 21. CONT.  6-Function 40h INT 21h Function 40h Description Write an array of bytes to a file or device Receives AH = 40h BX = file or device handle (console 1) CX = number of bytes to write DS:DX = address of array Returns AX = number of bytes written Sample call message DB "Hello, world" .code mov ah , 40h mov bx , 1 mov cx , LENGTHOF message mov dx , OFFSET message int 21h
  • 22. CONT. OF INT 21H FUNCTIONS  7-Function 01h INT 21h Function 1 Description Read a single character from standard input Receives AH = 1 Returns AX = character (ASCII code) Sample call character (ASCII code) Notes If no character is present in the input buffer, the program waits. This function echoes the character to standard output.
  • 23. DATE/TIME FUNCTIONS 8-Function 2Ah INT 21h Function 2Ah Description Get the system date Receives AH = 2Ah Returns CX = year DH, DL = month, day AL = day of week (Sunday 0, Monday 1, etc.) Sample call mov ah,2Ah int 21h mov year,cx mov month,dh mov day,dl mov dayOfWeek,al
  • 24. CONT. 9-Function 2Bh INT 21h Function 2Bh Description Set the system date Receives AH =2Bh CX =year DH =month DL =day Returns If the change was successful, AL 0; otherwise, AL FFh. Sample call mov ah,2Bh mov cx,year mov dh,month mov dl,day int 21h
  • 25. CONT. 9-Function 2Ch INT 21h Function 2Ch Description Get the system time Receives AH 2Ch Returns CH = hours (0 – 23) CL = minutes (0 – 59) DH = seconds (0 – 59) DL = hundredths of seconds (usually not accurate) Sample call mov ah,2Ch int 21h mov hours,ch mov minutes,cl mov seconds,dh
  • 26. CONT. 9-Function 2Dh INT 21h Function 2Dh Description Set the system time Receives AH = 2Dh CH = hours (0 – 23) CL = minutes (0 – 59) DH = seconds (0 – 59) Returns If the change was successful, AL 0; otherwise, AL FFh. Sample call mov ah,2Dh mov ch,hours mov cl,minutes mov dh,seconds int 21h
  • 27. EXAMPLE  TITLE Hello World Program (Hello.asm)  .MODEL small  .STACK 100h  .data  message DB "Hello, world!",0dh,0ah  data_size= $ -offset message  .code  main PROC  mov ax,@data ; initialize DS  mov ds,ax  mov ah,40h ; write to file/device  mov bx,1 ; output handle  mov cx,data_size  mov dx,OFFSET message ; addr of buffer  int 21h  .EXIT  main ENDP  END main ; number of bytes

Editor's Notes

  1. Some segments hold program instructions (code), others hold variables (data), and another segment named the stack segment holds local function variables and function parameters.
  2. In 16-bit programs, the code generated by .EXIT ismov ah,4Ch ; terminate processint 21h