0% found this document useful (0 votes)
56 views8 pages

Calculator Report

This document outlines a project for a simple command-line calculator implemented in x86 Assembly language for the 8086 microprocessor. It accepts two single-digit numbers and an arithmetic operator, performing addition, subtraction, multiplication, and division with error handling for invalid inputs. The document includes the code and a description of the program's functionality.

Uploaded by

galalalinader75
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views8 pages

Calculator Report

This document outlines a project for a simple command-line calculator implemented in x86 Assembly language for the 8086 microprocessor. It accepts two single-digit numbers and an arithmetic operator, performing addition, subtraction, multiplication, and division with error handling for invalid inputs. The document includes the code and a description of the program's functionality.

Uploaded by

galalalinader75
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Kingdom of Saudi Arabia

Ministry of Education

University of Bisha

College of Computer Science


and Information Technology

Computer Science major

Calculator

Project Number 6

‫غايه عبدالرحمن الغامدي‬


444803303
DR. Omnia Babkr
Table of Contents
1. Input

2. Description

3. Code

4. Output (Print Screen)


1. Input
The program takes three inputs from the user:

- First digit (between 0 and 9)

- An operator (+, -, *, /)

- Second digit (between 0 and 9)

2. Description
This project is a simple command-line calculator written in x86 Assembly language for the
8086 microprocessor using MS-DOS interrupts.

Functionality:

- Accepts two single-digit numbers and an arithmetic operator.


- Supports the four basic operations: addition, subtraction, multiplication, and division.
- Displays the result of the operation.
- For division, it also displays the remainder.
- Includes input validation for both digits and operators.
- Handles errors such as division by zero and invalid input.

3. Code

.model small
.stack 100h
.data
welcome_msg db 'Single-Digit Calculator (+, -, *, /)', 0Dh, 0Ah, '$'
num1_prompt db 0Dh, 0Ah, 'Enter first digit (0-9): $'
op_prompt db 0Dh, 0Ah, 'Enter operator (+, -, *, /): $'
num2_prompt db 0Dh, 0Ah, 'Enter second digit (0-9): $'
result_msg db 0Dh, 0Ah, 'Result: $'
remainder_msg db ' remainder: $'
invalid_op db 0Dh, 0Ah, 'Error: Invalid operator!', 0Dh, 0Ah, '$'
div_zero db 0Dh, 0Ah, 'Error: Division by zero!', 0Dh, 0Ah, '$'
invalid_digit db 0Dh, 0Ah, 'Error: Please enter 0-9!', 0Dh, 0Ah, '$'
newline db 0Dh, 0Ah, '$'

num1 db 0
num2 db 0
operator db 0
result db 0
remainder db 0
.code
main proc
mov ax, @data
mov ds, ax

mov ah, 9
mov dx, offset welcome_msg
int 21h

mov ah, 9
mov dx, offset num1_prompt
int 21h
call get_digit
mov num1, al

mov ah, 9
mov dx, offset op_prompt
int 21h
mov ah, 1
int 21h
mov operator, al

mov ah, 9
mov dx, offset num2_prompt
int 21h
call get_digit
mov num2, al

cmp operator, '+'


je addition
cmp operator, '-'
je subtraction
cmp operator, '*'
je multiplication
cmp operator, '/'
je division

mov ah, 9
mov dx, offset invalid_op
int 21h
jmp end_program
addition:
mov al, num1
add al, num2
mov result, al
jmp display_result

subtraction:
mov al, num1
sub al, num2
mov result, al
jmp display_result

multiplication:
mov al, num1
mul num2
mov result, al
jmp display_result

division:
mov al, num1
mov ah, 0
mov bl, num2
cmp bl, 0
je division_error
div bl
mov result, al
mov remainder, ah
jmp display_result

division_error:
mov ah, 9
mov dx, offset div_zero
int 21h
jmp end_program

display_result:
mov ah, 9
mov dx, offset result_msg
int 21h

mov dl, result


add dl, '0'
mov ah, 2
int 21h

cmp operator, '/'


jne end_program

mov ah, 9
mov dx, offset remainder_msg
int 21h

mov dl, remainder


add dl, '0'
mov ah, 2
int 21h

end_program:
mov ah, 9
mov dx, offset newline
int 21h
mov ah, 0
int 16h

mov ah, 4ch


int 21h
main endp

get_digit proc
get_input:
mov ah, 1
int 21h

cmp al, '0'


jb invalid_input
cmp al, '9'
ja invalid_input

sub al, '0'


ret

invalid_input:
mov ah, 9
mov dx, offset invalid_digit
int 21h
jmp get_input
get_digit endp

end main

4. Output (Print Screen)

You might also like