Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 47

Computer System Low- Level Techniques

CT073-3-2

Mathematical Commands
Topic & Structure of The Lesson

• Assembly Language Mathematical


Commands.

CT073-2-3 and CSLLT Mathematical Command slide <2> of 47


Learning Outcomes

At the end of this topic, You should be able to

- Understand and use how mathematical


commands work in assembly language programs.

- Use assembly language mathematical


commands.

CT073-2-3 and CSLLT Mathematical Command slide <3> of 47


Key Terms You Must Be Able To
Use
• If you have mastered this topic, you should be able to use the following
terms correctly in your assignments and exams:

Mathematical commands
-ADD
- SUB
- MUL
- DIV
- INC
-DEC

CT073-2-3 and CSLLT Mathematical Command slide <4> of 47


Mathematics

• Being a computer, the most basic type of operation


is the mathematical operation.
• Assembly Language provides us with commands
that can be used to perform the four basic
mathematical operations,
• Addition
• Subtraction
• Multiplication
• Division

CT073-2-3 and CSLLT Mathematical Command slide <5> of 47


Byte Addition

Addition in assembly language can be performed by


using the ADD instruction or command.
For example,

ADD AL,CL

The first register is known as the


implied register (as the results are
automatically stored in it)

CT073-2-3 and CSLLT Mathematical Command slide <6> of 47


Byte Addition - Example

For example:-
mov al,5
mov cl,12
add al,cl
Answer:-
al = 17
cl = 12

CT073-2-3 and CSLLT Mathematical Command slide <7> of 47


Byte Addition - Example

For example:-
mov al,5
add al,12
Answer:-
al = 17

CT073-2-3 and CSLLT Mathematical Command slide <8> of 47


Byte Addition - Example

For example:-
mov al,250
mov cl,20
add al,cl
Answer:-
al = 14
cl = 20

CT073-2-3 and CSLLT Mathematical Command slide <9> of 47


Word Addition

Addition in assembly language can be performed by


using the ADD instruction or command.
For example,

ADD AX,CX

The first register is known as the


implied register (as the results are
automatically stored in it)

CT073-2-3 and CSLLT Mathematical Command slide <10> of 47


Word Addition - Example

For example:-
mov ax,625
mov cx,489
add ax,cx
Answer:-
ax = 1114
cx = 489

CT073-2-3 and CSLLT Mathematical Command slide <11> of 47


Word Addition - Example

For example:-
mov ax,625
add ax,489
Answer:-
ax = 1114

CT073-2-3 and CSLLT Mathematical Command slide <12> of 47


Word Addition - Example

For example:-
mov ax,63821 (F94D)
mov cx,48260 (BC84)
add ax,cx
Answer:-
ax = 46545 (B5D1)
cx = 48260 (BC84)

CT073-2-3 and CSLLT Mathematical Command slide <13> of 47


Byte Subtraction
Subtraction in assembly language can be performed by
using the SUB instruction or command.
For example,

SUB AL,CL

The first register is known


as the implied register (as
the results are automatically
stored in it)

CT073-2-3 and CSLLT Mathematical Command slide <14> of 47


Byte Subtraction - Example

For example:-
mov al,10
mov cl,5
sub al,cl
Answer:-
al = 5
cl = 5

CT073-2-3 and CSLLT Mathematical Command slide <15> of 47


Byte Subtraction - Example

For example:-
mov al,10
sub al,5
Answer:-
al = 5

CT073-2-3 and CSLLT Mathematical Command slide <16> of 47


Byte Subtraction - Example

For example:-
mov al,10
mov cl,15
sub al,cl
Answer:-
al = 251
cl = 15

CT073-2-3 and CSLLT Mathematical Command slide <17> of 47


Word Subtraction
Subtraction in assembly language can be performed by
using the SUB instruction or command.
For example,

SUB AX,CX

The first register is known


as the implied register (as
the results are automatically
stored in it)

CT073-2-3 and CSLLT Mathematical Command slide <18> of 47


Word Subtraction - Example

For example:-
mov ax,10
mov cx,5
sub ax,cx
Answer:-
ax = 5
cx = 5

CT073-2-3 and CSLLT Mathematical Command slide <19> of 47


Word Subtraction - Example

For example:-
mov ax,10
sub ax,5
Answer:-
ax = 5

CT073-2-3 and CSLLT Mathematical Command slide <20> of 47


Word Subtraction - Example

For example:-
mov ax,10 (A)
mov cx,20 (14)
sub cx
Answer:-
ax = 65526 (FFF6)
cx = 20

CT073-2-3 and CSLLT Mathematical Command slide <21> of 47


Multiplication
In assembly language there are generally two kinds of
multiplication:-
• byte multiplication
• word multiplication

Byte Multiplication
A multiplication which involves byte registers and
producing a result which is word (8bits) in size.
Word Multiplication
A multiplication which involves word registers and
producing a result which is double word (16bits) in
size.
CT073-2-3 and CSLLT Mathematical Command slide <22> of 47
Byte Multiplication

MUL BL

This is interpreted as:-


AX = AL * BL
whereby AL is the implied register, and AH
contains the overflow.

CT073-2-3 and CSLLT Mathematical Command slide <23> of 47


Byte Multiplication

MUL CL

This is interpreted as:-


AX = AL * CL
whereby AL is the implied register, and AH
contains the overflow.

CT073-2-3 and CSLLT Mathematical Command slide <24> of 47


Byte Multiplication - Example

For example:-
mov al,5
mov bl,30
mul bl
Answer:-
al = 150
ah = 0
ax = 150
CT073-2-3 and CSLLT Mathematical Command slide <25> of 47
Byte Multiplication - Example

For example:-
mov al,30 (1E)
mov bl,10 (A)
mul bl
Answer:-
al = 44 (2C)
ah = 1
ax = 300 (12C)
CT073-2-3 and CSLLT Mathematical Command slide <26> of 47
Word Multiplication

MUL BX

This is interpreted as:-


DX:AX = AX * BX
whereby AX is the implied register, and DX
contains the overflow.

CT073-2-3 and CSLLT Mathematical Command slide <27> of 47


Word Multiplication

MUL CX

This is interpreted as:-


DX:AX = AX * CX
whereby AX is the implied register, and DX
contains the overflow.

CT073-2-3 and CSLLT Mathematical Command slide <28> of 47


Word Multiplication - Example

For example:-
mov ax,300
mov bx,129
mul bx
Answer:-
ax = 38700
dx = 0
dx:ax = 38700
CT073-2-3 and CSLLT Mathematical Command slide <29> of 47
Word Multiplication - Example

For example:-
mov ax,329
mov bx,1030
mul bx
Answer:-
ax = 11190
dx = 5
dx:ax = 338870
CT073-2-3 and CSLLT Mathematical Command slide <30> of 47
Division
In assembly language there are generally two kinds of
division:-
• byte division
• word division
Byte Division
A division which involves dividing a word register
(16bits) with a byte register (8bits) and producing a
result which is byte in size.
Word Division
A division which involves dividing a double word
(32bits) register with a word (16bits) register and
producing a result which is word in size.
CT073-2-3 and CSLLT Mathematical Command slide <31> of 47
Byte Division

DIV BL

This is interpreted as:-


AX = AX / BL
whereby AX is the implied register, AL contains
the quotient and AH contains the remainder.

CT073-2-3 and CSLLT Mathematical Command slide <32> of 47


Byte Division

DIV CL

This is interpreted as:-


AX = AX / CL
whereby AX is the implied register, AL contains
the quotient and AH contains the remainder.

CT073-2-3 and CSLLT Mathematical Command slide <33> of 47


Byte Division - Example

For example:-
mov ax,100
mov bl,25
div bl
Answer:-
al = 4
ah = 0

CT073-2-3 and CSLLT Mathematical Command slide <34> of 47


Byte Division - Example

For example:-
mov ax,6239
mov bl,45
div bl
Answer:-
al = 138
ah = 29

CT073-2-3 and CSLLT Mathematical Command slide <35> of 47


Byte Division - Example

For example:-
mov ax,2560
mov bl,10
div bl
Answer:-
al = ?
ah = ?

CT073-2-3 and CSLLT Mathematical Command slide <36> of 47


Word Division

DIV BX

This is interpreted as:-


DX:AX = DX:AX / BX
whereby DX:AX is the implied register, AX
contains the quotient and DX contains the
remainder.

CT073-2-3 and CSLLT Mathematical Command slide <37> of 47


Word Division

DIV CX

This is interpreted as:-


DX:AX = DX:AX / CX
whereby DX:AX is the implied register, AX
contains the quotient and DX contains the
remainder.

CT073-2-3 and CSLLT Mathematical Command slide <38> of 47


Word Division - Example

For example:-
mov dx,0
mov ax, 61287
mov bx,14
div bx
Answer:-
ax = 4377
dx = 9
CT073-2-3 and CSLLT Mathematical Command slide <39> of 47
Word Division - Example

For example:-
This is a 32bit
mov dx,5
number, 389625
mov ax, 61945
mov bx,23
div bx
Answer:-
ax = 16940
dx = 5
CT073-2-3 and CSLLT Mathematical Command slide <40> of 47
Increment Commands

INC CX
This is interpreted as:-
CX = CX + 1

INC AL
This is interpreted as:-
AL = AL + 1

CT073-2-3 and CSLLT Mathematical Command slide <41> of 47


INC
Example:-

MOV AH,198
INC AH

Before (AH contents)


19810 = 110001102
After (AH contents)
19910 = 110001112
CT073-2-3 and CSLLT Mathematical Command slide <42> of 47
Decrement Commands

DEC CX

This is interpreted as:-


CX = CX - 1

DEC AL

This is interpreted as:-


AL = AL - 1
CT073-2-3 and CSLLT Mathematical Command slide <43> of 47
DEC
Example:-

MOV AH,198
DEC AH

Before (AH contents)


19810 = 110001102
After (AH contents)
19710 = 110001012
CT073-2-3 and CSLLT Mathematical Command slide <44> of 47
Some Questions……….
You are required to write a complete program that
makes use of the common registers (AH, AL, BH, BL,
……) to perform the following mathematical
calculations:-
1. (5 + 2) * 5 4. (12 * 60) / 8 - 120
2. (7 - 2) + (8 * 3) + 5 5. (78 + 4) * 5 + 12
3. (75 * 5) / 4

Ensure that your answer is stored in the AX register


after performing the calculations. You are not required
to have any inputs or outputs in your program.
CT073-2-3 and CSLLT Mathematical Command slide <45> of 47
Question and Answer Session

Q&A

CT073-2-3 and CSLLT Mathematical Command slide <46> of 47


What we will cover next

• Bit Manipulation Commands

CT073-2-3 and CSLLT Mathematical Command slide <47> of 47

You might also like