SlideShare a Scribd company logo
http://www.tutorialspoint.com/assembly_prog ramming /assembly_numbers.htm Copyright © tutorialspoint.com
ASSEMBLY - NUMBERS
Numericaldata is generally represented inbinary system. Arithmetic instructions operate onbinary data. When
numbers are displayed onscreenor entered fromkeyboard, they are inASCII form.
So far, we have converted this input data inASCII formto binary for arithmetic calculations and converted the
result back to binary. The following code shows this:
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov eax,'3'
sub eax, '0'
mov ebx, '4'
sub ebx, '0'
add eax, ebx
add eax, '0'
mov [sum], eax
mov ecx,msg
mov edx, len
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov ecx,sum
mov edx, 1
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db "The sum is:", 0xA,0xD
len equ $ - msg
segment .bss
sum resb 1
Whenthe above code is compiled and executed, it produces the following result:
The sum is:
7
Suchconversions, however, have anoverhead, and assembly language programming allows processing
numbers ina more efficient way, inthe binary form. Decimalnumbers canbe represented intwo forms:
ASCII form
BCD or Binary Coded Decimalform
ASCII Representation
InASCII representation, decimalnumbers are stored as string of ASCII characters. For example, the decimal
value 1234 is stored as:
31 32 33 34H
Where, 31H is ASCII value for 1, 32H is ASCII value for 2, and so on. There are the following four instructions for
processing numbers inASCII representation:
AAA - ASCII Adjust After Addition
AAS - ASCII Adjust After Subtraction
AAM - ASCII Adjust After Multiplication
AAD - ASCII Adjust Before Division
These instructions do not take any operands and assume the required operand to be inthe AL register.
The following example uses the AAS instructionto demonstrate the concept:
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
sub ah, ah
mov al, '9'
sub al, '3'
aas
or al, 30h
mov [res], ax
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov edx,1 ;message length
mov ecx,res ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'The Result is:',0xa
len equ $ - msg
section .bss
res resb 1
Whenthe above code is compiled and executed, it produces the following result:
The Result is:
6
BCD Representation
There are two types of BCD representation:
Unpacked BCD representation
Packed BCD representation
Inunpacked BCD representation, eachbyte stores the binary equivalent of a decimaldigit. For example, the
number 1234 is stored as:
01 02 03 04H
There are two instructions for processing these numbers:
AAM - ASCII Adjust After Multiplication
AAD - ASCII Adjust Before Division
The four ASCII adjust instructions, AAA, AAS, AAM and AAD canalso be used withunpacked BCD
representation. Inpacked BCD representation, eachdigit is stored using four bits. Two decimaldigits are
packed into a byte. For example, the number 1234 is stored as:
12 34H
There are two instructions for processing these numbers:
DAA - DecimalAdjust After Addition
DAS - decimalAdjust After Subtraction
There is no support for multiplicationand divisioninpacked BCD representation.
Example:
The following programadds up two 5-digit decimalnumbers and displays the sum. It uses the above concepts:
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov esi, 4 ;pointing to the rightmost digit
mov ecx, 5 ;num of digits
clc
add_loop:
mov al, [num1 + esi]
adc al, [num2 + esi]
aaa
pushf
or al, 30h
popf
mov [sum + esi], al
dec esi
loop add_loop
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov edx,5 ;message length
mov ecx,sum ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'The Sum is:',0xa
len equ $ - msg
num1 db '12345'
num2 db '23456'
sum db ' '
Whenthe above code is compiled and executed, it produces the following result:
The Sum is:
35801

More Related Content

What's hot

Managing console input and output
Managing console input and outputManaging console input and output
Managing console input and output
gourav kottawar
 
Code optimization
Code optimizationCode optimization
Code optimization
veena venugopal
 
Mips
MipsMips
Manipulators
ManipulatorsManipulators
Manipulators
Kamal Acharya
 
Console i/o for c++
Console i/o for c++Console i/o for c++
Console i/o for c++
Darshan Radadiya
 
Program execution, straight line sequence and branching
Program execution, straight line sequence and branchingProgram execution, straight line sequence and branching
Program execution, straight line sequence and branching
JyotiprakashMishra18
 
Instruction Set Architecture
Instruction  Set ArchitectureInstruction  Set Architecture
Instruction Set Architecture
Haris456
 
Ch9a
Ch9aCh9a
Ch9b
Ch9bCh9b
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
Gaditek
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
Ashok Raj
 
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
 
Code Generation
Code GenerationCode Generation
Code Generation
PrabuPappuR
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
Motaz Saad
 
X86 assembly & GDB
X86 assembly & GDBX86 assembly & GDB
X86 assembly & GDB
Jian-Yu Li
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with files
ramya marichamy
 
C programming
C programmingC programming
C programming
Nazmus Shakib Shadin
 
MIPS Architecture
MIPS ArchitectureMIPS Architecture
MIPS Architecture
Dr. Balaji Ganesh Rajagopal
 
Code Conversion in 8085 Microprocessor
Code Conversion in 8085 MicroprocessorCode Conversion in 8085 Microprocessor
Code Conversion in 8085 Microprocessor
MOHIT AGARWAL
 
Embedded c programming
Embedded c programmingEmbedded c programming
Embedded c programming
PriyaDYP
 

What's hot (20)

Managing console input and output
Managing console input and outputManaging console input and output
Managing console input and output
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Mips
MipsMips
Mips
 
Manipulators
ManipulatorsManipulators
Manipulators
 
Console i/o for c++
Console i/o for c++Console i/o for c++
Console i/o for c++
 
Program execution, straight line sequence and branching
Program execution, straight line sequence and branchingProgram execution, straight line sequence and branching
Program execution, straight line sequence and branching
 
Instruction Set Architecture
Instruction  Set ArchitectureInstruction  Set Architecture
Instruction Set Architecture
 
Ch9a
Ch9aCh9a
Ch9a
 
Ch9b
Ch9bCh9b
Ch9b
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
 
Code Generation
Code GenerationCode Generation
Code Generation
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
 
X86 assembly & GDB
X86 assembly & GDBX86 assembly & GDB
X86 assembly & GDB
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with files
 
C programming
C programmingC programming
C programming
 
MIPS Architecture
MIPS ArchitectureMIPS Architecture
MIPS Architecture
 
Code Conversion in 8085 Microprocessor
Code Conversion in 8085 MicroprocessorCode Conversion in 8085 Microprocessor
Code Conversion in 8085 Microprocessor
 
Embedded c programming
Embedded c programmingEmbedded c programming
Embedded c programming
 

Viewers also liked

Final semestral alice ciencia
Final semestral alice cienciaFinal semestral alice ciencia
Final semestral alice ciencia
SUSY84
 
Xarxa d'escoles cooperants. Tenim nous amics a Nicaragua
Xarxa d'escoles cooperants. Tenim nous amics a NicaraguaXarxa d'escoles cooperants. Tenim nous amics a Nicaragua
Xarxa d'escoles cooperants. Tenim nous amics a Nicaragua
Roser Mascaró
 
Xamarin day9 - Advance Xamarin Forms
Xamarin day9 - Advance Xamarin FormsXamarin day9 - Advance Xamarin Forms
Xamarin day9 - Advance Xamarin Forms
Subodh Pushpak
 
Xamarin day2 - Android with Xamarin
Xamarin day2 - Android with XamarinXamarin day2 - Android with Xamarin
Xamarin day2 - Android with Xamarin
Subodh Pushpak
 
Democratic and autocracy
Democratic and autocracyDemocratic and autocracy
Democratic and autocracy
htiohito
 
Nihao canción de secuencia didáctica
Nihao canción de secuencia didácticaNihao canción de secuencia didáctica
Nihao canción de secuencia didáctica
laycar
 
Casos de Éxito Ciatej
Casos de Éxito CiatejCasos de Éxito Ciatej
Casos de Éxito Ciatej
Ciatej
 
Culbe
CulbeCulbe
Culbe
jacobminh
 
La Criminología como base fundamental de la Política Criminológica en México:...
La Criminología como base fundamental de la Política Criminológica en México:...La Criminología como base fundamental de la Política Criminológica en México:...
La Criminología como base fundamental de la Política Criminológica en México:...
Archivos de Criminología, Seguridad Privada y Criminalística
 
Guía de actividades en AVA
Guía de actividades en AVAGuía de actividades en AVA
Guía de actividades en AVA
Sergio Bermúdez Rojas
 
liuhecai
liuhecailiuhecai
liuhecai
nwz1008
 
Taller sistemas de gestión de la innovación
Taller sistemas de gestión de la innovaciónTaller sistemas de gestión de la innovación
Taller sistemas de gestión de la innovación
REAS País Valencià, Xarxa d' economia Alternativa i Solidària
 
Otc
Otc Otc
Otc
Ciatej
 
Oooook
OooookOooook
CBN fears haunt TRS over Hyderabad!
CBN fears haunt TRS over Hyderabad!CBN fears haunt TRS over Hyderabad!
CBN fears haunt TRS over Hyderabad!
telugustop.com
 
Tecnologie e Startup: ICT è solo una commodity? - Matteo Valoriani - Codemoti...
Tecnologie e Startup: ICT è solo una commodity? - Matteo Valoriani - Codemoti...Tecnologie e Startup: ICT è solo una commodity? - Matteo Valoriani - Codemoti...
Tecnologie e Startup: ICT è solo una commodity? - Matteo Valoriani - Codemoti...
Codemotion
 
Analisis laporan keuangan
Analisis laporan keuanganAnalisis laporan keuangan
Analisis laporan keuanganadelaa09
 
водорості
водоростіводорості
водорості
katia0401
 

Viewers also liked (20)

Final semestral alice ciencia
Final semestral alice cienciaFinal semestral alice ciencia
Final semestral alice ciencia
 
Xarxa d'escoles cooperants. Tenim nous amics a Nicaragua
Xarxa d'escoles cooperants. Tenim nous amics a NicaraguaXarxa d'escoles cooperants. Tenim nous amics a Nicaragua
Xarxa d'escoles cooperants. Tenim nous amics a Nicaragua
 
Xamarin day9 - Advance Xamarin Forms
Xamarin day9 - Advance Xamarin FormsXamarin day9 - Advance Xamarin Forms
Xamarin day9 - Advance Xamarin Forms
 
Xamarin day2 - Android with Xamarin
Xamarin day2 - Android with XamarinXamarin day2 - Android with Xamarin
Xamarin day2 - Android with Xamarin
 
Democratic and autocracy
Democratic and autocracyDemocratic and autocracy
Democratic and autocracy
 
Bandotan
BandotanBandotan
Bandotan
 
Nihao canción de secuencia didáctica
Nihao canción de secuencia didácticaNihao canción de secuencia didáctica
Nihao canción de secuencia didáctica
 
Casos de Éxito Ciatej
Casos de Éxito CiatejCasos de Éxito Ciatej
Casos de Éxito Ciatej
 
Culbe
CulbeCulbe
Culbe
 
La Criminología como base fundamental de la Política Criminológica en México:...
La Criminología como base fundamental de la Política Criminológica en México:...La Criminología como base fundamental de la Política Criminológica en México:...
La Criminología como base fundamental de la Política Criminológica en México:...
 
Guía de actividades en AVA
Guía de actividades en AVAGuía de actividades en AVA
Guía de actividades en AVA
 
liuhecai
liuhecailiuhecai
liuhecai
 
Taller sistemas de gestión de la innovación
Taller sistemas de gestión de la innovaciónTaller sistemas de gestión de la innovación
Taller sistemas de gestión de la innovación
 
Otc
Otc Otc
Otc
 
My prezi
My preziMy prezi
My prezi
 
Oooook
OooookOooook
Oooook
 
CBN fears haunt TRS over Hyderabad!
CBN fears haunt TRS over Hyderabad!CBN fears haunt TRS over Hyderabad!
CBN fears haunt TRS over Hyderabad!
 
Tecnologie e Startup: ICT è solo una commodity? - Matteo Valoriani - Codemoti...
Tecnologie e Startup: ICT è solo una commodity? - Matteo Valoriani - Codemoti...Tecnologie e Startup: ICT è solo una commodity? - Matteo Valoriani - Codemoti...
Tecnologie e Startup: ICT è solo una commodity? - Matteo Valoriani - Codemoti...
 
Analisis laporan keuangan
Analisis laporan keuanganAnalisis laporan keuangan
Analisis laporan keuangan
 
водорості
водоростіводорості
водорості
 

Similar to N_Asm Assembly numbers (sol)

N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)
Selomon birhane
 
X86 assembly nasm syntax
X86 assembly nasm syntaxX86 assembly nasm syntax
X86 assembly nasm syntax
Francesco DiFusco
 
Alp 05
Alp 05Alp 05
Alp 05
gswapnil86
 
Alp 05
Alp 05Alp 05
Wk1to4
Wk1to4Wk1to4
Wk1to4
raymondmy08
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answers
debarghyamukherjee60
 
Generacion de codigo ensamblado
Generacion de codigo ensambladoGeneracion de codigo ensamblado
Generacion de codigo ensamblado
tre_na_gil
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
Tirumalesh Nizampatnam
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
Mohammed A. Imran
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
n|u - The Open Security Community
 
Chap03[1]
Chap03[1]Chap03[1]
N_Asm Assembly basic syntax (sol)
N_Asm Assembly basic syntax (sol)N_Asm Assembly basic syntax (sol)
N_Asm Assembly basic syntax (sol)
Selomon birhane
 
Alp 05
Alp 05Alp 05
Alp 05
Jaimon Jacob
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
bolovv
 
7986-lect 7.pdf
7986-lect 7.pdf7986-lect 7.pdf
7986-lect 7.pdf
RiazAhmad521284
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
PRADEEP
 
Introduction to Assembly Language Programming
Introduction to Assembly Language ProgrammingIntroduction to Assembly Language Programming
Introduction to Assembly Language Programming
Rahul P
 
other-architectures.ppt
other-architectures.pptother-architectures.ppt
other-architectures.ppt
Jaya Chavan
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
Ahmed M. Abed
 
Need help in assembly. Thank you Implement the following expression .pdf
Need help in assembly. Thank you Implement the following expression .pdfNeed help in assembly. Thank you Implement the following expression .pdf
Need help in assembly. Thank you Implement the following expression .pdf
rajkumarm401
 

Similar to N_Asm Assembly numbers (sol) (20)

N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)
 
X86 assembly nasm syntax
X86 assembly nasm syntaxX86 assembly nasm syntax
X86 assembly nasm syntax
 
Alp 05
Alp 05Alp 05
Alp 05
 
Alp 05
Alp 05Alp 05
Alp 05
 
Wk1to4
Wk1to4Wk1to4
Wk1to4
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answers
 
Generacion de codigo ensamblado
Generacion de codigo ensambladoGeneracion de codigo ensamblado
Generacion de codigo ensamblado
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Chap03[1]
Chap03[1]Chap03[1]
Chap03[1]
 
N_Asm Assembly basic syntax (sol)
N_Asm Assembly basic syntax (sol)N_Asm Assembly basic syntax (sol)
N_Asm Assembly basic syntax (sol)
 
Alp 05
Alp 05Alp 05
Alp 05
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
 
7986-lect 7.pdf
7986-lect 7.pdf7986-lect 7.pdf
7986-lect 7.pdf
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
Introduction to Assembly Language Programming
Introduction to Assembly Language ProgrammingIntroduction to Assembly Language Programming
Introduction to Assembly Language Programming
 
other-architectures.ppt
other-architectures.pptother-architectures.ppt
other-architectures.ppt
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
 
Need help in assembly. Thank you Implement the following expression .pdf
Need help in assembly. Thank you Implement the following expression .pdfNeed help in assembly. Thank you Implement the following expression .pdf
Need help in assembly. Thank you Implement the following expression .pdf
 

More from Selomon birhane

N_Asm Assembly addressing modes (sol)
N_Asm Assembly addressing modes (sol)N_Asm Assembly addressing modes (sol)
N_Asm Assembly addressing modes (sol)
Selomon birhane
 
N_Asm Assembly arrays (sol)
N_Asm Assembly arrays (sol)N_Asm Assembly arrays (sol)
N_Asm Assembly arrays (sol)
Selomon birhane
 
N_Asm Assembly recursion (sol)
N_Asm Assembly recursion (sol)N_Asm Assembly recursion (sol)
N_Asm Assembly recursion (sol)
Selomon birhane
 
N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)
Selomon birhane
 
N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)
Selomon birhane
 
N_Asm Assembly variables (sol)
N_Asm Assembly variables (sol)N_Asm Assembly variables (sol)
N_Asm Assembly variables (sol)
Selomon birhane
 
N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)
Selomon birhane
 
Control system(smarajit ghosh) By sol
Control system(smarajit ghosh) By solControl system(smarajit ghosh) By sol
Control system(smarajit ghosh) By sol
Selomon birhane
 
Two ports
Two ports Two ports
Two ports
Selomon birhane
 

More from Selomon birhane (9)

N_Asm Assembly addressing modes (sol)
N_Asm Assembly addressing modes (sol)N_Asm Assembly addressing modes (sol)
N_Asm Assembly addressing modes (sol)
 
N_Asm Assembly arrays (sol)
N_Asm Assembly arrays (sol)N_Asm Assembly arrays (sol)
N_Asm Assembly arrays (sol)
 
N_Asm Assembly recursion (sol)
N_Asm Assembly recursion (sol)N_Asm Assembly recursion (sol)
N_Asm Assembly recursion (sol)
 
N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)
 
N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)
 
N_Asm Assembly variables (sol)
N_Asm Assembly variables (sol)N_Asm Assembly variables (sol)
N_Asm Assembly variables (sol)
 
N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)
 
Control system(smarajit ghosh) By sol
Control system(smarajit ghosh) By solControl system(smarajit ghosh) By sol
Control system(smarajit ghosh) By sol
 
Two ports
Two ports Two ports
Two ports
 

Recently uploaded

How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 

Recently uploaded (20)

How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 

N_Asm Assembly numbers (sol)

  • 1. http://www.tutorialspoint.com/assembly_prog ramming /assembly_numbers.htm Copyright © tutorialspoint.com ASSEMBLY - NUMBERS Numericaldata is generally represented inbinary system. Arithmetic instructions operate onbinary data. When numbers are displayed onscreenor entered fromkeyboard, they are inASCII form. So far, we have converted this input data inASCII formto binary for arithmetic calculations and converted the result back to binary. The following code shows this: section .text global _start ;must be declared for using gcc _start: ;tell linker entry point mov eax,'3' sub eax, '0' mov ebx, '4' sub ebx, '0' add eax, ebx add eax, '0' mov [sum], eax mov ecx,msg mov edx, len mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov ecx,sum mov edx, 1 mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov eax,1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db "The sum is:", 0xA,0xD len equ $ - msg segment .bss sum resb 1 Whenthe above code is compiled and executed, it produces the following result: The sum is: 7 Suchconversions, however, have anoverhead, and assembly language programming allows processing numbers ina more efficient way, inthe binary form. Decimalnumbers canbe represented intwo forms: ASCII form BCD or Binary Coded Decimalform ASCII Representation InASCII representation, decimalnumbers are stored as string of ASCII characters. For example, the decimal value 1234 is stored as: 31 32 33 34H Where, 31H is ASCII value for 1, 32H is ASCII value for 2, and so on. There are the following four instructions for processing numbers inASCII representation: AAA - ASCII Adjust After Addition AAS - ASCII Adjust After Subtraction AAM - ASCII Adjust After Multiplication
  • 2. AAD - ASCII Adjust Before Division These instructions do not take any operands and assume the required operand to be inthe AL register. The following example uses the AAS instructionto demonstrate the concept: section .text global _start ;must be declared for using gcc _start: ;tell linker entry point sub ah, ah mov al, '9' sub al, '3' aas or al, 30h mov [res], ax mov edx,len ;message length mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov edx,1 ;message length mov ecx,res ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov eax,1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'The Result is:',0xa len equ $ - msg section .bss res resb 1 Whenthe above code is compiled and executed, it produces the following result: The Result is: 6 BCD Representation There are two types of BCD representation: Unpacked BCD representation Packed BCD representation Inunpacked BCD representation, eachbyte stores the binary equivalent of a decimaldigit. For example, the number 1234 is stored as: 01 02 03 04H There are two instructions for processing these numbers: AAM - ASCII Adjust After Multiplication AAD - ASCII Adjust Before Division The four ASCII adjust instructions, AAA, AAS, AAM and AAD canalso be used withunpacked BCD representation. Inpacked BCD representation, eachdigit is stored using four bits. Two decimaldigits are packed into a byte. For example, the number 1234 is stored as: 12 34H
  • 3. There are two instructions for processing these numbers: DAA - DecimalAdjust After Addition DAS - decimalAdjust After Subtraction There is no support for multiplicationand divisioninpacked BCD representation. Example: The following programadds up two 5-digit decimalnumbers and displays the sum. It uses the above concepts: section .text global _start ;must be declared for using gcc _start: ;tell linker entry point mov esi, 4 ;pointing to the rightmost digit mov ecx, 5 ;num of digits clc add_loop: mov al, [num1 + esi] adc al, [num2 + esi] aaa pushf or al, 30h popf mov [sum + esi], al dec esi loop add_loop mov edx,len ;message length mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov edx,5 ;message length mov ecx,sum ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov eax,1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'The Sum is:',0xa len equ $ - msg num1 db '12345' num2 db '23456' sum db ' ' Whenthe above code is compiled and executed, it produces the following result: The Sum is: 35801