8086 Assembly Subtraction: 8-bit and 16-bit

To understand the subtraction process in x86 Assembly language, you must go through some important topics we shared earlier:

To perform subtraction in x86 assembly we have to use SUB opcode and different registers for 8-bit and 16-bit numbers.

x86 Assembly Subtraction of 16-bit Numbers

Q: Write a program, take two 16-bit numbers of your choice, perform subtraction them and display the result.

PROGRAM

.Model small
.stack 100h

.data
b dw 08h
c dw 02h

.code
MAIN PROC
mov ax,@data
mov ds,ax

mov bx,b
mov cx,c

sub bx,cx
add bx,30h

mov ah,02
mov dx,bx
int 21h

main endp
end main

EXPLANATION

In the above program, we initialized two variables b and c with hexadecimal values. we use data type DW because we are performing 16-bit subtraction. Then we use SUB opcode to perform subtraction and we added 30h to the result to show the result in integer form rather that hexadecimal form.


x86 Assembly Subtraction of 8-bit Numbers

Q: Write a program, take two 8-bit numbers of your choice, perform subtraction them and display the result.

PROGRAM

.Model small
.stack 100h

.data
b db 08h
c db 02h

.code
MAIN PROC
mov ax,@data
mov ds,ax

mov bl,b
mov cl,c

sub bl,cl
add bl,30h

mov ah,02
mov dl,bl
int 21h

main endp
end main

EXPLANATION

The above program is for 8-bit subtraction so we use 8-bit register AL, BL, CL, DL. All the other process is same as for 32-bit subtraction.

Hope so this tutorial will help you understand the basics of 8086 Subtraction. Comment to show me that you are alive!


Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *