Monday, 24 February 2025

Assembly Language Programming

 Unit 4

Models of 8086 Assembly Language Program

The 8086 microprocessor supports different memory models based on how much memory a program needs. These models determine how code, data, and stack are organized in memory.


1. Types of Memory Models in 8086

The Intel 8086 processor operates in Real Mode, where it can address up to 1MB of memory. Based on how memory is divided, the following models are available:

Memory Model

Code Size

Data Size

Stack Size

Segments Used

Tiny

≤ 64 KB

≤ 64 KB

≤ 64 KB

Single Segment (CS = DS = SS)

Small

≤ 64 KB

≤ 64 KB

≤ 64 KB

Separate CS, DS, SS

Medium

Unlimited

≤ 64 KB

≤ 64 KB

Separate CS, DS, SS

Compact

≤ 64 KB

Unlimited

≤ 64 KB

Separate CS, DS, SS

Large

Unlimited

Unlimited

≤ 64 KB

Separate CS, DS, SS

Huge

Unlimited

Unlimited

Unlimited

Separate CS, DS, SS


2. Explanation of Each Memory Model

a) Tiny Model

  • Entire program (code, data, stack) fits within a single 64 KB segment.
  • CS = DS = SS (single segment).
  • Mostly used for .COM files.

Example:

assembly

.MODEL TINY

.CODE

ORG 100H  ; Required for COM file execution


START:

    MOV AH, 09H

    MOV DX, OFFSET MSG

    INT 21H  ; Print message


    MOV AX, 4C00H

    INT 21H  ; Exit program


MSG DB 'Hello, World!$'


END START


b) Small Model

  • Code, data, and stack have separate segments.
  • Code and data each fit in 64 KB.
  • Used for simple .EXE programs.

Example:

assembly

.MODEL SMALL

.STACK 100H

.DATA

MSG DB 'Hello, 8086!$'


.CODE

MAIN PROC

    MOV AX, @DATA

    MOV DS, AX  ; Initialize data segment


    MOV AH, 09H

    MOV DX, OFFSET MSG

    INT 21H  ; Print message


    MOV AX, 4C00H

    INT 21H  ; Exit program

MAIN ENDP


END MAIN


c) Medium Model

  • Code can exceed 64 KB (multiple code segments).
  • Data is limited to 64 KB.
  • Used for large programs with multiple functions.

Example:

assembly

.MODEL MEDIUM

.STACK 100H

.DATA

MSG DB 'Welcome to Medium Model$'


.CODE

MAIN PROC

    MOV AX, @DATA

    MOV DS, AX


    MOV AH, 09H

    MOV DX, OFFSET MSG

    INT 21H


    MOV AX, 4C00H

    INT 21H

MAIN ENDP


END MAIN


d) Compact Model

  • Multiple data segments but single code segment.
  • Used when data is large but code remains within 64 KB.

Example:

assembly

.MODEL COMPACT

.STACK 100H

.DATA

BUFFER DB 256 DUP('$')  ; Large data buffer


.CODE

MAIN PROC

    MOV AX, @DATA

    MOV DS, AX


    ; Your program logic here


    MOV AX, 4C00H

    INT 21H

MAIN ENDP


END MAIN


e) Large Model

  • Both code and data can exceed 64 KB.
  • Each function and data block may be in different segments.
  • Used for very large programs.

Example:

assembly

.MODEL LARGE

.STACK 100H

.DATA

MSG DB 'Large Model Example$'

 

.CODE

MAIN PROC FAR

    MOV AX, @DATA

    MOV DS, AX


    MOV AH, 09H

    MOV DX, OFFSET MSG

    INT 21H


    MOV AX, 4C00H

    INT 21H

MAIN ENDP


END MAIN


f) Huge Model

  • Multiple code and multiple data segments.
  • Used for handling large arrays beyond 64 KB.
  • Similar to Large Model, but pointers can access full segment addressing.

assembly

.MODEL HUGE

.STACK 100H

.DATA

BIG_ARRAY DW 50000 DUP(0)  ; Huge array


.CODE

MAIN PROC FAR

    MOV AX, @DATA

    MOV DS, AX


    ; Program logic


    MOV AX, 4C00H

    INT 21H

MAIN ENDP


END MAIN


3. Choosing the Right Model

  • Tiny → Small programs, .COM files.
  • Small → Standard programs, fits within 64 KB code & data.
  • Medium → Large programs, multiple functions with a single data segment.
  • CompactLarge data but small code.
  • LargeLarge programs requiring multiple code & data segments.
  • Huge → Needed for very large arrays/structures (more than 64 KB).

4. Summary

  • The 8086 memory model is selected based on code, data, and stack size.
  • Tiny model is for compact programs, small & medium for most applications.
  • Large and huge models handle big programs and massive data structures.
  • Use .MODEL directive in MASM (Microsoft Macro Assembler) to specify the model.

No comments:

Post a Comment

Desktop Virtualisation

Desktop Virtualization ( DV ) Desktop Virtualization ( DV ) is a technique that creates an illusion of a desktop provided to the user. It d...