Close Menu
  • Home
  • Web Technologies
    • HTML/CSS
    • JavaScript
    • JQuery
    • Django
    • WordPress
  • Programming
    • Python
    • PHP
  • Linux
    • Ubuntu
Facebook X (Twitter) Instagram
  • About Us
  • Contact Us
  • Write for Us
  • AIO SEO TOLLS
Facebook X (Twitter) Instagram Pinterest VKontakte
mr.wixXsid
  • Home
  • Web Technologies
    • HTML/CSS
    • JavaScript
    • JQuery
    • Django
    • WordPress
  • Programming
    • Python
    • PHP
  • Linux
    • Ubuntu
mr.wixXsid
Home » Summation of Two Numbers in Assembly: Input and Output Explained
Assembly

Summation of Two Numbers in Assembly: Input and Output Explained

mrwixxsidBy mrwixxsidApril 10, 2025Updated:April 10, 2025No Comments6 Mins Read
Facebook Twitter Pinterest Tumblr Reddit WhatsApp Email
Share
Facebook Twitter LinkedIn Pinterest Email

Learn how Summation of Two Numbers in Assembly works, how assembly program takes two numbers as input and displays their single or double-digit sum, illustrating fundamental assembly input/output operations.

This program is designed to get two single-digit numbers from the user, add them together, and then show the single-digit sum on the screen.

  1. Memory Setup: The .DATA section reserves space in memory for the messages that will prompt the user for input (MSG1, MSG2), the message indicating the result (SUM), and single-byte storage locations for the first number (N1), the second number (N2), and the result of the addition (R).
  2. Data Segment Initialization: The .CODE section starts with MAIN PROC, the beginning of the main part of the program. The lines MOV AX, @DATA and MOV DS, AX set up the Data Segment register (DS) so the program can correctly access the messages and variables defined in the .DATA section.
  3. First Input:
    • LEA DX, MSG1: The program finds the memory address of the “ENTER FIRST NUMBER:$” message and prepares to display it.
    • MOV AH, 09H and INT 21H: These instructions call the DOS function to display the string pointed to by DX.
    • MOV AH, 1 and INT 21H: These instructions call the DOS function to read a single character typed by the user. The ASCII code of the character is stored in the AL register.
    • SUB AL, 48: This line converts the ASCII code of the digit (e.g., ‘5’ has ASCII 53) into its actual numerical value (e.g., 5).
    • MOV N1, AL: The numerical value of the first digit is stored in the N1 memory location.
  4. Second Input: This section repeats the process of the first input, but prompts the user with “ENTER SECOND NUMBER:$” (MSG2) and stores the numerical value of the second digit in the N2 memory location.
  5. Calculation:
    • MOV AL, N1: The numerical value of the first number is loaded into the AL register.
    • ADD AL, N2: The numerical value of the second number is added to the value in AL. The sum (which should be a single digit or a two-digit number less than 19 given single-digit inputs) is now in AL.
    • MOV R, AL: The sum is stored in the R memory location.
    • MOV AH, 0: The upper byte of the AX register (AH) is cleared, often done as a clean-up or preparation step.
  6. Preparing for Displaying the Sum:
    • AAA: The “ASCII Adjust for Addition” instruction is used. For single-digit addition, if the result in AL is greater than 9, AAA will adjust AL to contain the correct BCD digit (0-9) and put the carry (0 or 1) into AH.
    • ADD AH, 48: The value in AH (the potential carry) is converted to its ASCII character representation (‘0’ or ‘1’).
    • ADD AL, 48: The value in AL (the units digit of the sum) is converted to its ASCII character representation (‘0’-‘9’).
    • MOV BX, AX: The entire AX register, now containing the ASCII codes of the (potentially) two digits of the sum, is copied into the BX register. BH will hold the ASCII of the carry (if any), and BL will hold the ASCII of the units digit.
  7. Displaying the Result:
    • LEA DX, SUM: The program prepares to display the “SUMMATION IS :$” message.
    • MOV AH, 9 and INT 21h: The “SUMMATION IS :$” message is displayed.
    • MOV AH, 2, MOV DL, BH, and INT 21H: The ASCII character in BH (the potential carry) is displayed.
    • MOV AH, 2, MOV DL, BL, and INT 21h: The ASCII character in BL (the units digit of the sum) is displayed.
  8. Program Termination:
    • MOV AH, 4CH and INT 21H: These instructions terminate the program and return control to the operating system.
.MODEL SMALL
.STACK 100H
.DATA
    MSG1 DB 10,13,"ENTER 1ST NUMBER:$"
    MSG2 DB 0AH,0DH,"ENTER 2ND NUMBER:$"
    SUM DB 10,13,"SUMMATION IS:$"
    N1 DB ?
    N2 DB ?
    R DB ?
.CODE
MAIN PROC
    MOV AX,@DATA
    MOV DS,AX

    LEA DX,MSG1  ;  Point to your message
    MOV AH,09H   ;  Say "Show text!".
    INT 21H      ;  Tell DOS to do it.

    MOV AH,1     ;  Say "Wait for keyboard input!".
    INT 21H      ;  DOS waits, you type, the ASCII code goes to AL.

    SUB AL,48    ;  Convert ASCII to number
    MOV N1,AL    ;  Store that number in the "box" named N1

    LEA DX,MSG2
    MOV AH,09H
    INT 21H

    MOV AH,1
    INT 21H

    SUB AL,48    ;  Convert ASCII to number
    MOV N2,AL

    MOV AL,N1    ;   Put the first number into our temporary calculation box (AL).
    ADD AL,N2

    MOV R,AL
    MOV AH,0     ;   FOR REGISTER CLEARANCE

    AAA          ;    A special "fixer" for addition results (mostly for a specific way of storing numbers we haven't directly used).
    ADD AH,48    ;    Convert any carry to its displayable character.
    ADD AL,48    ;    Convert the sum's digit to its displayable character.
    MOV BX,AX    ;    (Maybe) keep a copy of the displayable result.
    LEA DX,SUM   ;   We tell DOS where in memory our message (SUM) is located.
    MOV AH,9     ;   We tell DOS what we want to do (display a string).
    INT 21H      ;   We tell DOS to actually do it, using the information we provided in DX and AH.


; MOV AH, 2

    ; MOV: "Move" or "copy".

    ; AH: The top half of the AX storage box.

    ; 2: A number. This is the DOS function code for displaying a single character on the screen.

    ; Think: "Put the number 2 into the AH box. This tells DOS we want to show one character."

; MOV DL, BH

;     MOV: "Move" or "copy".

;     DL: A small storage box (the lower half of the DX register). DOS often uses DL to hold the character we want to display.

;     BH: Another small storage box (the top half of the BX register). We're taking whatever character code (likely an ASCII value) is currently in BH.

;     Think: "Take the character code that's in the BH box and put a copy of it into the DL box. This is the character we want to show."

; INT 21H

;     INT 21H: "Ring the DOS bell!" We're asking DOS to perform the function we specified in AH (display a character), using the information in DL (the character to display).

;     Think: "Hey DOS, I want to display a character (because AH is 2), and here's the character to display (it's in DL). Please show it on the screen!"

    MOV AH,2
    MOV DL,BH
    INT 21H

    MOV AH,2
    MOV DL,BL
    INT 21H

    MOV AH,4CH
    INT 21H
MAIN ENDP
END MAIN
Assembly Assembly Output Summation of Two Numbers
Share. Facebook Twitter Pinterest Tumblr Reddit Telegram WhatsApp Email
mrwixxsid
  • Website
  • Facebook
  • X (Twitter)
  • Instagram

I am a Full-Stack Web Developer & Security Analyst from Bangladesh. I have built web/online applications on various Open Source Stacks and love information security testing.

Add A Comment
Leave A Reply Cancel Reply

Live Cricket
Live Cricket Updates
Latest Articles

Even Odd number’s in Assembly

April 10, 2025

Summation of Two Numbers in Assembly: Input and Output Explained

April 10, 2025

Resolving “sudo: command not found” in Linux: A Complete Guide

January 3, 2025

How to Change the Root Password in Ubuntu (and Why You Should Do It Now!)

October 4, 2024

Using the Python Pickle Module: A Beginner’s Guide

August 25, 2024
About

Mr.wixXsid is a website that publishes Web technologies, Programming, Linux, and Open-source ERP articles for an aspirant like you and us. We are in-depth research & present valuable content & resources to help the Web professional of all levels.

Latest

Even Odd number’s in Assembly

April 10, 2025

Summation of Two Numbers in Assembly: Input and Output Explained

April 10, 2025
Other sites
  • BLOG
  • SEO TOOL’S
  • All in One Video Downloader
  • SELFISH WORLD
Copyright © 2025 mr.wixXsid. All rights reserved.
  • Privacy Policy
  • Terms of Use
  • Advertise

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.
x
x