KEMBAR78
MP Project | PDF | Assembly Language | Computer Program
0% found this document useful (0 votes)
18 views10 pages

MP Project

This project report details the development of a simple calculator program in Assembly language that performs basic arithmetic operations on the x86 architecture using MASM. The project aims to enhance understanding of low-level programming techniques, including input handling, operation selection, and arithmetic logic implementation. Future improvements suggested include multi-digit input, error handling, floating point operations, GUI integration, and support for negative numbers.
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)
18 views10 pages

MP Project

This project report details the development of a simple calculator program in Assembly language that performs basic arithmetic operations on the x86 architecture using MASM. The project aims to enhance understanding of low-level programming techniques, including input handling, operation selection, and arithmetic logic implementation. Future improvements suggested include multi-digit input, error handling, floating point operations, GUI integration, and support for negative numbers.
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
You are on page 1/ 10

Project Report: Simple

Calculator in Assembly
Language

Abstract

This project presents the development of a simple


calculator program using Assembly language. The
calculator performs basic arithmetic operations such
as addition, subtraction, multiplication, and division.
Designed for the x86 architecture using MASM
(Microsoft Macro Assembler), this program
demonstrates low-level programming techniques and
how arithmetic logic is implemented at the machine
level.
Objective
The main objective of this project is to:
• Understand and implement arithmetic
operations using Assembly language.
• Gain hands-on experience with x86
architecture and MASM.
• Demonstrate control flow and interrupt
handling in low-level programming.
• Explore how calculators operate at the
assembly language level.
Project Segment
The project is divided into the following
segments:
1. Input Handling: Accept user input
for two numbers and an operator.
2. Operation Selection: Based on
the operator, select the corresponding
arithmetic routine.
3. Arithmetic Logic: Perform
addition, subtraction, multiplication,
or division using Assembly
instructions.
4. Display Output: Show the result
using standard output routines.
Code:
asm
CopyEdit
.model small
.stack 100h

.data
num1 db ?
num2 db ?
result db ?
msg1 db 'Enter first number: $'
msg2 db 'Enter second number: $'
msg3 db 'Enter operator (+, -, *, /): $'
msg4 db 'Result: $'
newline db 13, 10, '$'

.code
main:
mov ax, @data
mov ds, ax

; Get first number


lea dx, msg1
call print
call read_num
mov num1, al

; New line
lea dx, newline
call print

; Get second number


lea dx, msg2
call print
call read_num
mov num2, al
; New line
lea dx, newline
call print

; Get operator
lea dx, msg3
call print
call read_char
mov bl, al

; Perform operation
mov al, num1
mov ah, 0
mov bh, 0
mov bl, num2

cmp bl, 0
je div_by_zero

cmp bl, '+'


je do_add
cmp bl, '-'
je do_sub
cmp bl, '*'
je do_mul
cmp bl, '/'
je do_div
jmp end_prog

do_add:
add al, bl
jmp show_result

do_sub:
sub al, bl
jmp show_result

do_mul:
mul bl
jmp show_result

do_div:
xor ah, ah
div bl
jmp show_result

div_by_zero:
lea dx, newline
call print
lea dx, msg4
call print
lea dx, newline
call print
jmp end_prog

show_result:
lea dx, newline
call print
lea dx, msg4
call print
call print_num
jmp end_prog

; Function to read a character


read_char:
mov ah, 1
int 21h
ret

; Function to read a single digit number


read_num:
call read_char
sub al, '0'
ret

; Function to print string


print:
mov ah, 9
int 21h
ret

; Function to print number in AL


print_num:
add al, '0'
mov dl, al
mov ah, 2
int 21h
ret

end_prog:
mov ah, 4ch
int 21h
end main
Output
Example:

sql
CopyEdit
Enter first number: 4
Enter second number: 3
Enter operator (+, -, *, /): +
Result: 7
Improvement
Although the calculator is functional, the following
improvements can be made:

1. Multi-digit Input: Enhance the input system to


accept and process multi-digit numbers.
2. Error Handling: Improve error checking for invalid
operators and divide-by-zero.
3. Floating Point Operations: Extend functionality
to support decimal calculations using FPU
instructions.
4. GUI Interface: Integrate with a graphical interface
using higher-level languages for better usability.
5. Negative Numbers: Add support for negative
number calculations.

Conclusion
This project demonstrated how a basic
calculator could be implemented using
Assembly language. It provided insights
into low-level operations, register
manipulation, and the overall structure of
an Assembly program. While basic, this
calculator lays the foundation for more
complex Assembly language applications
and improves understanding of computer
arithmetic at the hardware-near level.

You might also like