calculator needed...

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2007
Posts: 3
Reputation: zunnur is an unknown quantity at this point 
Solved Threads: 0
zunnur zunnur is offline Offline
Newbie Poster

Re: calculator needed...

 
0
  #11
Mar 29th, 2007
Originally Posted by takkischitt View Post
hello...

I'm looking for a calculator program written in assembler... it needs to do all the basic functions of a calculator eg add, subract, multiply, devide...

if anyone can point me in the right direction of where to find one it would be greatly apprecitaed...!

thanx...

neil...
Hi,

You can copy simple calc from here..

#make_com#
include 'emu8086.inc'

ORG 100h

JMP start

msg1 DB 'Enter operation number[1~4]: $'
msg2 DB 'Enter 1st No: $'
msg3 DB 'Enter 2nd No: $'
msg4 DB 'The result is: $'
msg5 db 'Thank you for using My Calculator Program ', 13, 10, '$'

calcOP DB '?', 0

num1 DW ?
num2 DW ?
opr DW ?


start:
PRINTN 'Welcome to My Calculator Program'
PRINTN '[Loading...]'
PRINTN ''
PRINTN ''
PRINTN 'Please select type of arithmetic operation:'
PRINTN '1. Addition'
PRINTN '2. Subtraction'
PRINTN '3. Multiplication'
PRINTN '4. Division'

LEA DX, msg1 ; output of a string at DSX
MOV AH, 09h
INT 21h

MOV DX, 2
LEA DI, calcOP
CALL GET_STRING

PUTC 13
PUTC 10

LEA DX, msg2 ; first number
MOV AH, 09h
INT 21h
CALL scan_num
MOV num1, CX

PUTC 13
PUTC 10

LEA DX, msg3 ; second number
MOV AH, 09h
INT 21h
CALL scan_num
MOV num2, CX

PUTC 13
PUTC 10

LEA DX, msg4 ; result
MOV AH, 09h
INT 21h

CMP calcOP, '1'
JE do_plus

CMP calcOP, '2'
JE do_minus

CMP calcOP, '3'
JE do_mult

CMP calcOP, '4'
JE do_div

end:
PUTC 13
PUTC 10

LEA DX, msg5
MOV AH, 09h
INT 21h

RET

do_plus:

MOV AX, num1
ADD AX, num2
CALL PRINT_NUM
JMP end

do_minus:

MOV AX, num1
SUB AX, num2
CALL PRINT_NUM
JMP end

do_mult:

MOV AX, num1
IMUL num2
CALL PRINT_NUM
JMP end

do_div:
MOV DX, 0
MOV AX, num1
IDIV num2
CALL PRINT_NUM
JMP end

DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
DEFINE_GET_STRING

END
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Assembly Forum
Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC