Addition of Two Numbers
section .data
num1 dd 10 ; First number (32-bit)
num2 dd 20 ; Second number (32-bit)
result dd 0 ; Store the result (32-bit)
section .text
global _start
_start:
mov eax, [num1] ; Load num1 into EAX
add eax, [num2] ; Add num2 to EAX
mov [result], eax ; Store result in memory
; Exit program
mov eax, 1 ; sys_exit syscall
xor ebx, ebx ; Exit code 0
int 0x80 ; Call kernel
Explanation
-
Data Section (
.data)num1andnum2store the two numbers to be added.resultis reserved for storing the sum.
-
Code Section (
.text) - Load
num1into theEAXregister. - Add
num2toEAXusing theADDinstruction. - Store the result back into memory (
result). - Exit the program using a system call.
Subtraction of Two Numbers in Assembly Language (x86 - NASM)
In assembly language, subtraction is performed using the SUB instruction. Below is a simple x86 assembly program that subtracts two numbers and stores the result.
Code: Subtraction of Two Numbers (x86 Assembly - NASM)
Explanation
-
Data Section (
.data)num1stores the first number (30).num2stores the second number (10).resultis reserved for storing the result ofnum1 - num2.
-
Code Section (
.text) - Load
num1intoEAXregister. - Subtract
num2fromEAXusingSUBinstruction. - Store the result in memory (
result). - Exit the program using a system call.
.model small
ALP to check a given number is odd or even.
🔧 Program Description:
This program checks the least significant bit (LSB) of the number.
-
If LSB is
0, the number is even. -
If LSB is
1, the number is odd.
Sample Output:
If number DB 7, it prints:
If number DB 4, it prints:
Here’s a neat 8086 Assembly Language Program (ALP) that does two things:
-
✅ Finds the length of a string
-
✅ Concatenates two strings
💾 Assumptions:
-
Strings are stored in
.DATAsegment. -
Each string is terminated with
$, as expected by DOS for display. -
We will manually concatenate without using any built-in function.
🧪 Sample Output:
💡 Logic Overview
-
Loop through the array
-
Compare each element with
minandmax -
Replace
minif smaller, replacemaxif larger
🧪 Sample Output
A block transfer is copying a block of data (like an array or string) from one memory location to another.
We use:
-
SI(Source Index) for source -
DI(Destination Index) for destination -
CXto store count (number of bytes to transfer) -
MOVSBto move each byte
🧠Explanation:
| Instruction | Description |
|---|---|
MOV AX, @DATA | Load address of data segment |
MOV DS, AX | Initialize DS |
MOV ES, AX | Same segment used for both source and destination |
LEA SI, source | SI points to start of source block |
LEA DI, dest | DI points to destination block |
MOV CX, 5 | We want to move 5 bytes |
CLD | Clear Direction Flag (moves forward in memory) |
REP MOVSB | Repeats MOVSB CX times, copying byte from [SI] to [DI] |
🔧 What it does:
-
Operates on two predefined numbers
-
Calls separate procedures for each operation
-
Displays results using DOS interrupt
✅ Sample Output:
💡 Program Description
-
Operates on two 8-bit numbers (
num1andnum2) -
Performs:
-
Addition:
num1 + num2 -
Subtraction:
num1 - num2
-
-
Displays the results using DOS interrupts
🧪 Sample Output
✅ Features:
-
Works on an array of 8-bit numbers
-
Can easily toggle between ascending or descending
-
Uses Bubble Sort (simple and easy for 8086)
🧪 Sample Output: