Description
4.1 Models of 8086 Assembly Language Program 💾
The 8086 uses a segmented memory architecture, dividing memory into logical segments (Code, Data, Stack, Extra). Memory Models define the maximum allowed size for the Code and Data segments and are crucial for the linker and assembler to manage memory references. The .MODEL directive is used to specify the model.
| Model | Code Size | Data Size | Pointer Size | Key Feature |
| TINY | $\leq 64 \text{KB}$ | $\leq 64 \text{KB}$ | Near | Both code and data share a single segment (produces a .COM file). |
| SMALL | $\leq 64 \text{KB}$ | $\leq 64 \text{KB}$ | Near | Code and data are in separate segments but are small. |
| COMPACT | $\leq 64 \text{KB}$ | $> 64 \text{KB}$ | Near Code, Far Data | Larger data, but single code segment. |
| MEDIUM | $> 64 \text{KB}$ | $\leq 64 \text{KB}$ | Far Code, Near Data | Larger code, but single data segment. |
| LARGE | $> 64 \text{KB}$ | $> 64 \text{KB}$ | Far | Multiple code and data segments, no single data array $> 64 \text{KB}$. |
| HUGE | $> 64 \text{KB}$ | $> 64 \text{KB}$ | Far | Similar to Large, but allows single data array $> 64 \text{KB}$. |
4.2 Programming Using Assembler 🔢
This section covers essential algorithms and data manipulation techniques in 8086 assembly:
Arithmetic Operations
-
Hexadecimal Operations: Standard instructions like
ADD,SUB,MUL,DIV,INC, andDECare inherently performed on binary data, which directly represents hexadecimal values. -
BCD Operations (Binary Coded Decimal): Special instructions are used to adjust the accumulator (
ALorAX) after arithmetic operations to ensure the result is a valid BCD number.-
DAA(Decimal Adjust After Addition): Corrects the result inALafter anADDorADCinstruction. -
DAS(Decimal Adjust After Subtraction): Corrects the result inALafter aSUBorSBBinstruction.
-
-
Sum of Series: Typically involves setting up a loop using the
LOOPinstruction and using a register likeCXas a counter andAXorDX:AXas an accumulator.
Array & Sorting
-
Smallest and Largest Numbers (Array): Involves using a loop to iterate through the array, using instructions like
MOVandCMP(Compare) to compare the current element with the currently stored minimum/maximum value. Jump instructions (JL– Jump Less,JG– Jump Greater) are used to update the min/max register. -
Sorting Numbers: Implemented using nested loops (like Bubble Sort or Insertion Sort). This requires using
CMPandXCHG(Exchange) instructions to compare adjacent elements and swap them based on the desired order (ascending/descending).
Number Properties (Check)
-
Odd or Even: Determined by checking the Least Significant Bit (LSB).
-
Use the
TESTinstruction with a bitmask of0001h(e.g.,TEST AL, 01H). If the Zero Flag (ZF) is set (result is zero), the number is even (LSB is 0). If $\text{ZF}=0$, the number is odd (LSB is 1). -
Alternatively, using
ROR(Rotate Right) can shift the LSB into the Carry Flag (CF). If $\text{CF}=1$, it’s odd.
-
-
Positive or Negative: Determined by checking the Most Significant Bit (MSB), which is the Sign Bit in two’s complement representation.
-
For 8-bit numbers, this is Bit 7. For 16-bit, it’s Bit 15.
-
Check the Sign Flag (SF) after any arithmetic/logical operation. If $\text{SF}=1$, the number is negative. If $\text{SF}=0$ (and $\text{ZF}=0$), the number is positive.
-
Data Transfer & String Operations
-
Block Transfer: Moving a block of data from one memory location (Source Segment:Offset $\rightarrow$ DS:SI) to another (Extra Segment:Offset $\rightarrow$ ES:DI). This is efficiently done using the
REP MOVSB(Repeat Move String Byte) orREP MOVSW(Repeat Move String Word) instructions.CXholds the count. -
String Operations: The 8086 has dedicated string instructions that automatically increment/decrement the index registers (
SI/DI) based on the Direction Flag (DF):-
Length: Iterating (using
SCASB– Scan String Byte) until a delimiter (e.g.,$or00H) is found, and then calculating the distance from the start address. -
Reverse/Copy: Using
MOVSBorSTOSB(Store String Byte) in a loop, often by initializingDIto the end of the destination and setting the DF flag (STDfor decrement) to copy backward. -
Compare: Using
REPZ CMPSB(Repeat while Zero/Equal Compare String Byte). This compares the strings at $\text{DS}:\text{SI}$ and $\text{ES}:\text{DI}$ and sets flags based on the result. -
Concatenation: Copying the first string, then copying the second string to the memory location immediately following the end of the first string.
-
-
Count ‘1’s and ‘0’s (16-bit number): This is achieved using Bit Manipulation instructions:
-
Use a loop that iterates 16 times (or the bit size).
-
Inside the loop, use the
RCL(Rotate through Carry Left) orRCR(Rotate through Carry Right) instruction to move the MSB or LSB into the Carry Flag ($\text{CF}$). -
Check the $\text{CF}$: if $\text{CF}=1$, increment the ‘1’ counter; otherwise, increment the ‘0’ counter.
-





Reviews
There are no reviews yet.