Chapter 7_ Integer Arithmetic
Chapter 7_ Integer Arithmetic
Arithmetic
This chapter covers integer arithmetic in assembly language.
Topics include shift and rotate instructions, multiplication, division,
extended precision, and decimal arithmetic.
by Tabeen Bokhat
2023-ce-13
Shift and Rotate
Instructions
Logical shifts Arithmetic shifts
(SHL/SHR) (SAL/SAR)
Multiply or divide by 2 Preserve sign bit for
using bit shifting. signed numbers during
shifts.
Rotates (ROL/ROR,
RCL/RCR)
Circular bit shifts, including through carry flag for multi-word
operations.
Shift and Rotate
Applications
Bit Field Fast
Extraction
Isolate specific bits for data Multiplication/Divisi
manipulation. on
Use shifts to multiply or
divide by powers of two
efficiently.
Simple Data
Encryption
Rotate bytes in messages for basic cipher operations.
Multiplication
Instructions IMUL
MUL Large Operand
Multiplication
Unsigned multiplication using AL, Signed multiplication with varied
AX, DX:AX registers. operand formats. Use loops and shifts to multiply 32-
bit numbers into 64-bit results.
Division
Instructions
Sign Extension (CBW,
IDIV CWD, CDQ)
DIV
Signed division with similar register Prepare registers for signed division
Unsigned division producing usage. operations.
quotient and remainder.
Extended Addition and
Subtraction
ADC
Add with carry supports chained additions.
SBB
Subtract with borrow enables cascading subtractions.
Multi-word
Support
Handle numbers larger than 16 bits by chaining
operations.
ASCII and Unpacked Decimal
Arithmetic Unpacked BCD
Each byte holds one BCD digit (00h–
09h)
ASCII Digits Adjust
Represent numbers as characters • Instructions
AAA, AAS, AAM, AAD correct
'0'–'9' (30h–39h) arithmetic results
1 3
Packed Decimal
Arithmetic
Packed BCD Decimal Financial
Two BCD digits stored per Adjustment
DAA and DAS fix results after Applications
Avoid floating point errors for
byte for compact decimal addition and subtraction. precise currency calculations.
data.
Example: BCD
Addition
Load BCD
Numbers
Place two packed BCD values into registers.
Add Registers
Perform addition using normal ADD instruction.
• Shift, rotate, multiplication, division Mastering integer arithmetic aids efficient assembly
• Extended precision arithmetic programming.
• ASCII and packed decimal operations
THANK YOU!
PRESENTED TO:
SIR ASIM REHMAT
PRESENTED BY:
TABEEN BOKHAT
2023-CE-13