Code Monkey home page Code Monkey logo

simple-arithmetic-calculator-in-assembly's Introduction

Simple Arithmetic Calculator in Assembly

This repository contains an assembly language project that performs basic arithmetic operations: addition, subtraction, multiplication, and division. The calculator reads two single-digit numbers from the user, processes the operations, and stores the results.

Features

  • Reading Input: Reads two single-digit numbers from the user.
  • Arithmetic Operations: Performs addition, subtraction, multiplication, and division.
  • Result Storage: Stores the results of the operations in memory for further use.

Code Snippets

Reading Input

The calculator reads the first and second number from the user and converts them from ASCII to hexadecimal.

; Read the first number
LEER:
    MOV AH, 01H ; Service 01H for reading a character
    INT 21H     ; Store the ASCII code of the character in AL
    CMP AL, 30H ; Check if the digit is less than '0'
    JL LEER
    CMP AL, 39H ; Check if the digit is greater than '9'
    JG LEER
    SUB AL, 30H ; Convert ASCII to hexadecimal
    MOV NUM1, AL

; Read the second number
LEER2:
    MOV AH, 01H ; Service 01H for reading a character
    INT 21H     ; Store the ASCII code of the character in AL
    CMP AL, 30H ; Check if the digit is less than '0'
    JL LEER2
    CMP AL, 39H ; Check if the digit is greater than '9'
    JG LEER2
    SUB AL, 30H ; Convert ASCII to hexadecimal
    MOV NUM2, AL

Arithmetic Operations

The calculator performs addition, subtraction, multiplication, and division, and stores the results.

; Addition
ADD AL, NUM1 ; NUM1 + NUM2
MOV SUM, AL  ; Store the result

; Subtraction
MOV AL, NUM1
SUB AL, NUM2 ; NUM1 - NUM2
MOV RES, AL  ; Store the result

; Multiplication
MOV AL, NUM1
MOV CL, NUM2
MUL CL  ; NUM1 * NUM2
MOV MULTI, AL ; Store the result

; Division
MOV AL, NUM1
MOV BL, NUM2
DIV BL ; NUM1 / NUM2
MOV COCI, AL ; Store the quotient
MOV RESI, AH ; Store the remainder

Usage

  1. Assemble and link the code using an assembler (e.g., TASM, MASM).
  2. Run the executable.
  3. Input two single-digit numbers when prompted.
  4. The calculator will perform the operations and store the results.

Memory Variables

  • NUM1: First number
  • NUM2: Second number
  • SUM: Result of addition
  • RES: Result of subtraction
  • MULTI: Result of multiplication
  • COCI: Quotient of division
  • RESI: Remainder of division

simple-arithmetic-calculator-in-assembly's People

Contributors

kplanisphere avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.