---
title: "8086 ALP: sum of 100 even numbers"
subject: "Microprocessor"
chapter: 3
key: "semester_4/microprocessor:alp-8086-sum-even-numbers"
source: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8086-sum-even-numbers
site: BCT Engineering
---

# 8086 ALP: sum of 100 even numbers

Microprocessor · Chapter 3: Programming with 8086 Microprocessor

- Asked in: 2074 Bhadra, 8 marks
- Video: [Program to find sum of even numbers from 1 to 100 in assembly language | DosBox | 8086 | Sameh UlHaq](https://www.youtube.com/watch?v=_km-xkj9WkM) — Sameh Ulhaq
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8086-sum-even-numbers
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-3

## Question

Write an assembly language program for 8086 to calculate the addition of 100 natural even numbers and display the result in screen, in decimal format.

## Short answer

Sum the first 100 even numbers (2+4+...+200) in a loop using DX as the current even, CX as counter, AX accumulating sum. The result 10100 is converted to decimal by repeated division by 10, pushing remainders, then popping and displaying as ASCII digits. Output: 10100.

## Answer

The first 100 even natural numbers are 2, 4, 6, ..., 200. Their sum = 100 × 101 = 10100, which fits in a 16-bit register. The program adds them in a loop (DX holds the current even number), then converts AX to decimal by repeated division by 10 (remainders are pushed on the stack and popped in reverse order) and displays the digits.

```asm
.MODEL SMALL
.STACK 100H

DISPSTR MACRO MSG            ; display a '$'-terminated string
        LEA  DX,MSG
        MOV  AH,09H
        INT  21H
        ENDM

CLRSCR  MACRO                ; clear screen and home the cursor
        MOV  AX,0600H        ; scroll whole window (AL=0 -> blank it)
        MOV  BH,07H          ; normal attribute
        MOV  CX,0000H        ; upper-left corner (row 0, col 0)
        MOV  DX,184FH        ; lower-right corner (row 24, col 79)
        INT  10H
        MOV  AH,02H          ; set cursor position
        MOV  BH,00H          ; page 0
        MOV  DX,0000H        ; row 0, col 0
        INT  10H
        ENDM

.DATA
    MSG   DB 'Sum of first 100 even numbers = $'

.CODE
MAIN PROC
    MOV  AX,@DATA
    MOV  DS,AX

    XOR  AX,AX             ; AX = sum = 0
    MOV  DX,2              ; first even number
    MOV  CX,100            ; 100 numbers
ADDLP:
    ADD  AX,DX             ; sum = sum + even number
    ADD  DX,2              ; next even number
    LOOP ADDLP             ; repeat 100 times, AX = 10100

    PUSH AX                ; save the sum
    DISPSTR MSG
    POP  AX
    MOV  BX,10             ; divisor
    XOR  CX,CX             ; digit counter
DIVLP:
    XOR  DX,DX             ; DX:AX / 10
    DIV  BX                ; AX = quotient, DX = remainder
    PUSH DX                ; save digit
    INC  CX
    OR   AX,AX             ; quotient zero?
    JNZ  DIVLP
SHOWLP:
    POP  DX                ; most significant digit first
    ADD  DL,30H            ; convert to ASCII
    MOV  AH,02H
    INT  21H               ; display digit
    LOOP SHOWLP
    MOV  AH,4CH            ; return to DOS
    INT  21H
MAIN ENDP

END MAIN
```

**Output:** `Sum of first 100 even numbers = 10100`

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the sum of the first 100 even natural numbers and why does it fit in AX?
   A. 5050, fits in 8 bits
   B. 10100, fits in 16 bits
   C. 10100, needs DX:AX because it exceeds 16 bits
   D. 20100, fits in 16 bits
   Answer: B. Sum = 100 x 101 = 10100, which is below 65535, so one 16-bit register is enough. (Key point: Sum value)

2. How does the addition loop generate the even numbers?
   A. DX starts at 2 and ADD DX,2 after each addition, repeated 100 times with LOOP
   B. DX starts at 0 and is incremented by 1 each time
   C. CX is added directly to AX
   D. DX starts at 1 and ADD DX,2 each time
   Answer: A. DX holds the current even number, starting at 2 and increasing by 2; CX=100 controls the count. (Key point: Loop logic)

3. How is AX converted to decimal digits for display?
   A. Repeated multiplication by 10 and taking the high byte
   B. Repeated division by 10, pushing remainders on the stack
   C. Adding 30H once to the whole of AX
   D. Repeated subtraction of 100 until zero
   Answer: B. DIV by 10 gives the remainder as the last digit; remainders are pushed and later popped. (Key point: Decimal conversion)

4. Why are the remainders pushed on the stack before display?
   A. To save memory
   B. Because INT 21h only reads from the stack
   C. Division gives the least significant digit first, and popping reverses it to most significant first
   D. To convert them to ASCII automatically
   Answer: C. The stack is LIFO, so the digit produced last (most significant) is popped first. (Key point: Digit order)

## Related in Microprocessor

- [8086 ALP: largest and smallest, display](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-largest-smallest-display) — Microprocessor, chapter 3
- [8086 ALP: count vowels and display string](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-count-vowels-display) — Microprocessor, chapter 3
- [8086 assembly language operators](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3A8086-operators) — Microprocessor, chapter 3, asked 3×
- [8086 ALP: alternate case display](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-alternate-case) — Microprocessor, chapter 3
- [8086 ALP: display only alphabetic characters](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-alphabetic-only) — Microprocessor, chapter 3
- [8086 ALP: words on lines and word count](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-words-lines-count) — Microprocessor, chapter 3

## Related in other subjects

- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
- [Protected specifier; student/test/result program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprotected-three-class-program) — Object Oriented Programming, chapter 6
- [Odd and even numbers to separate files](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-odd-even-until-no) — Computer Programming, chapter 10, asked 2×
- [Function definition; sum of two numbers](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afunction-definition-sum-two) — Computer Programming, chapter 6
