Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Roll No.

N098 Name: VEDASHREE SHETYE


Program : MBA.TECH CE Division: E
Batch: E2 Date of Experiment:17/09/2022
Date of Submission: 03/01/2023 Grade :

EXP. 2

Aim: A) Write a program to add two 8-bit nos.


B) Write a program to add two 16-bit nos
C) Write a program to subtract two 8-bit nos.
D) Write a program to subtract two 16-bit nos.

Apparatus: Tasm software

Theory:

The add instruction requires either the addend or the augend to be in a register, unless the
source operand is immediate since the addressing modes permitted for the source and
destination are register-register, memory to register, register to memory, register to immediate,
and finally memory to immediate. Hence one of the operands is initially moved to AX. Then
using the add instruction, 16-bit addition is performed.

Mnemonic Meaning Format Operation Flags


affected
ADD Addition ADD D,S (S)+(D) (D) ALL
carry (CF)
ADC Add with ADC D,S (S)+(D)+(CF) (D) ALL
carry carry (CF)
INC Increment INC D (D)+1 (D) ALL except
by one CY
AAA ASCII AAA If the sum is >9, AH is AF,CF
adjust for incremented by 1. Used to
addition adjust the result to get correct
unpacked BCD (0-9).
Instruction works only on AL
register.
DAA Decimal DAA Adjust AL for decimal ALL
adjust Packed BCD (0-99)
after
addition
The next arithmetic primitive is SUB. As discussed in ADD it permits the same
modes of addressing. Hence moving the minuend to a register pair is necessary. Then the
result is moved to a location in memory
Mnemonic Meaning Format Operation Flags
affected
SUB Subtract SUB D,S (D)-(S) (D) All
Borrow (CF)
SBB Subtract SBB D,S (D)-(S)-(CF) (D) All
with
borrow
DEC Decrement DEC D (D)-1 (D) All but CF
by one
NEG Negate NEG D 2s compliment All

DAS Decimal DAS Convert the result in AL to All


adjust for packed decimal format
subtraction
AAS ASCII AAS (AL) difference CY,AC
adjust for (AH) dec by 1 if borrow or
subtraction >9

A) Addition of two 8-bit numbers:

Program:
data segment
num1 db 98h
num2 db 99h
result dw ?
data ends

code segment
start: assume ds: data, cs: code
mov ax,data
mov ds,ax
mov ah,00h
mov al,num1
add al,num2
jnc down
inc ah
down:mov result,ax
mov ax,4c00h
int 21h
code ends
end start
B) Addition of two 16-bit numbers:

Program:

data segment
num1 dw 98ABh
num2 dw 99CDh
result dw ?
data ends

code segment
start: assume ds: data, cs: code
mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
add ax,bx
jnc down
inc ah
down:mov result,ax
mov ax,4c00h
int 21h
code ends
end start

C) Subtraction of two 8-bit numbers:

Program:
data segment
n1 db 37H
n2 db 01H
result db ?
data ends

code segment
start: assume ds: data, cs: code
mov ax,data
mov ds,ax
mov al,n1
mov bl,n2
sub al,bl
mov result,al

mov ax,4c00h
int 21h
code ends
end start
D) Subtraction of two 16-bit numbers:

Program:
data segment
n1 dw 3067H
n2 dw 0333H
result dw ?
data ends

code segment
start: assume ds: data, cs: code
mov ax,data
mov ds,ax
mov ax,n1
sub ax,n2
mov result,ax

mov ax,4c00h
int 21h
code ends
end start

Procedure:
Steps to be followed to execute 8086 program in tasm software
 Write Assembly language program in notepad.
 Save this program file in tasm /bin folder with .asm exetention
 Go to window start then select run
 Type command cmd (command window will pop up for dos prompt).
 Change the directory (cd\)
 Select path c:cd tasm/bin
 Write command tasm/zi file name .asm
 Write command tlink/v file name .obj
 Write command td file name .exe
 Program Window will appear
 Select view tab then select cpu
 Press F8 to execute program in single step mode
 Select view tab then select variable to see the result.
Result:
A) 8-bit Addition

B) 16-bit Addition
C) 8-bit Subtraction

D) 16-bit Subtraction

Conclusion: Therefore, after successfully completing this experiment, we


are able to program addition and subtraction for 8-bit and 16-bit numbers.

You might also like