Arithmetic Operations in Assembly Language: Fundamentals & Implementation

marceldavidbaroi 32 views 10 slides Mar 11, 2025
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

"Learn how arithmetic operations such as addition, subtraction, multiplication, and division are performed in Assembly Language. This guide covers key instructions, register usage, and practical examples to help you understand low-level computations effectively."


Slide Content

Arithmetic Operations in Assembly Language

Assembly Language Assembly Language is a low-level programming language. The instructions within Assembly Language are similar to machine code instructions. Arithmetic instructions in Assembly Language are executed in the Arithmetic Logical Unit (ALU) of the computer’s processor.

Types of arithmetic operations Assembly Language allows us to perform basic unsigned integer arithmetic operations. These operations are: Addition ( add )  Subtraction ( sub ) Multiplication ( mul ) Division ( dvi ) Increment ( inc ) Decrement ( dec )

Addition and subtraction The syntax for writing addition or subtraction instructions is as follows: operation destination, source operation : the intended arithmetic operation, i.e., add or sub. destination :  the accumulator register or memory location where we will store our final result after adding or subtracting the value in  source  register or memory location. source :  the register or memory location that contains the value to be added or subtracted to/from the original content of the  destination  register.

Multiplication The syntax for writing multiplication or division instructions is as follows: Operation source mul  performs an unsigned multiplication of the source operand and the accumulator. If the source operand is a byte (8 bits), we multiply it by the value stored in the register AL. The result is returned in the registers AH and AL. The higher half of the 16-bit result is stored in AH and the lower half in AL. This means that if the result is small enough to be represented in 8 bits, AH would contain 0. If the source operand is a word (16 bits), then we multiply it by the value stored in the register AX and the result is returned in the registers DX and AX. The higher half of the 32-bit result is stored in DX and the lower half in AX.

AL AX 8 bit source 8 bit source AH DX AL AX x x = =

Division div performs an integer division of the accumulator and the source operand. The result consists of an integer quotient and remainder. If the source operand is a byte, the 16-bit number stored in AX is divided by the operand. The 8-bit quotient is stored in AL and the 8-bit remainder in AH. If the source operand is a word, the 32-bit number stored in DX : AX is divided by the operand. The higher half of the number is stored in DX and the lower in AX. The 16-bit quotient is stored in AX and the remainder in DX.

DX AX 16 bit divisor AX DX = QUOTIENT REMAINDER AX 8 bit divisor AL AH = QUOTIENT REMAINDER

Increment and decrement The inc and dec instructions can be used to increment or decrement the contents of their respective operands by one. The inc instruction has no effect on the carry flag. The dec instruction sets the zero flag if the result of the operation is 0.

Thankyou