Category Archives: 8086

8086 MASM Assembly Program for Addition of Two 8-bit Numbers

This blog post will guide you through a MASM (Microsoft Macro Assembler) program that performs the addition of two 8-bit numbers. While this is a fundamental operation, it demonstrates crucial assembly programming concepts such as data handling, register usage, and memory storage. Let’s dive in!

Assembly Code

    .model small
    .data
    a db 09h
    b db 02h
    c dw ?
    
    .code
    main proc
        mov ax, @data
        mov ds, ax
        
        mov al, a
        mov bl, b
        add al, bl
        
        mov ah, 0
        mov c, ax
        
        int 3  ; Breakpoint interrupt
        
        mov ax, 4C00h  ; Exit program
        int 21h
    main endp
    
    end main
Continue reading 8086 MASM Assembly Program for Addition of Two 8-bit Numbers

Understanding INT 3h vs INT 21h in 8086 Assembly

In 8086 assembly programming, interrupts play a crucial role in handling various operations, from debugging to system calls. Two commonly used interrupts are INT 3h (Breakpoint Interrupt) and INT 21h (DOS Interrupt). While both involve interrupt handling, their functionalities and use cases are completely different.

In this blog post, we will explore the differences between INT 3h and INT 21h, their respective use cases, and practical examples to understand their behavior.

TL;DR

  • INT 3h is used for debugging; it stops execution and hands control to the debugger.
  • INT 21h is used for system services like displaying messages, reading input, and terminating the program.
  • Key Difference: INT 3h is a 1-byte instruction (CC), while INT 21h requires function numbers in AH to specify system calls.
Continue reading Understanding INT 3h vs INT 21h in 8086 Assembly

8086 Assembly Program to Add Two 16-bit Numbers with Carry Handling

In this blog post, we’ll explore an 8086 assembly language program that adds two 16-bit numbers while also checking for a carry flag.

; Data Segment

data segment
    a dw 0FFFFh      ; Example value that will cause a carry
    b dw 0001h       ; Example value
    c dw ?           ; To store result
    carry_flag db 0  ; To store carry (0 or 1)
data ends

; Code Segment

code segment
assume cs:code, ds:data
start:
    mov ax, data
    mov ds, ax      ; Initialize data segment

    mov ax, a       ; Load first number
    mov bx, b       ; Load second number
    add ax, bx      ; Perform addition

    mov c, ax       ; Store result in 'c'

    jc carry_occurred  ; Jump if carry flag is set
    mov carry_flag, 0  ; No carry, store 0
    jmp end_program    

carry_occurred:
    mov carry_flag, 1  ; Store carry flag as 1

end_program:
    int 3             ; Halt program

code ends
end start
Continue reading 8086 Assembly Program to Add Two 16-bit Numbers with Carry Handling

Understanding DW and DB in 8086 Assembly

In the realm of 8086 assembly language, understanding the nuances of data declaration is crucial. Two fundamental directives, DW (Define Word) and DB (Define Byte), play pivotal roles in allocating memory and storing data.


DW (Define Word)

  • Memory Allocation: Reserves 2 bytes (16 bits) of memory for the specified data.
  • Data Storage: Stores a 16-bit integer value.
  • Usage: Ideal for larger numerical values, addresses, or any data that requires 16 bits of representation.

Example:

data segment
    number DW 0x1234  ; Allocates 2 bytes and stores 1234h (4660 decimal)
data ends
Continue reading Understanding DW and DB in 8086 Assembly

8086 Assembly Program to Find Smallest Number from Given Numbers

​In this blog post, we’ll explore how to find the smallest number from a given set of values using an 8086 assembly language program. The following code snippet demonstrates this process:

data segment
STRING1 DB 08h,14h,05h,0Fh,09h
res db ?
data ends

code segment
assume cs:code, ds:data
start: mov ax, data
mov ds, ax
mov cx, 04h

mov bl, 79h
LEA SI, STRING1
up:
mov al, [SI]
cmp al, bl
jge nxt
mov bl, al
nxt:
inc si
dec cx
jnz up

mov res,bl
int 3
code ends
end start
Continue reading 8086 Assembly Program to Find Smallest Number from Given Numbers

8086 Assembly Program to Sort Numbers in Descending Order

In this blog post, we will explore an 8086 assembly language program designed to sort a list of numbers in descending order. Sorting is a fundamental operation in computer science, and understanding how to implement it at the assembly level provides valuable insights into low-level programming and processor operations.

The following assembly program sorts an array of numbers in descending order using the bubble sort algorithm:

DATA SEGMENT
STRING1 DB 99H,12H,56H,45H,36H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV CH,04H
UP2: MOV CL,04H
LEA SI,STRING1

UP1:MOV AL,[SI]
MOV BL,[SI+1]
CMP AL,BL
JNC DOWN
MOV DL,[SI+1]
XCHG [SI],DL
MOV [SI+1],DL

DOWN: INC SI
DEC CL
JNZ UP1
DEC CH
JNZ UP2
INT 3
CODE ENDS
END START
Continue reading 8086 Assembly Program to Sort Numbers in Descending Order