3 Replies - 2027 Views - Last Post: 14 May 2010 - 01:38 AM

#1 Daysaver   User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 24-November 08

calculater.asm

Posted 27 May 2009 - 04:05 AM

Description: made in emu8086
<code>
;ADD.Asm 
;M.D.Shirtliffe
;1.0
  
;SET UP
	ORG 100H

;DISPLAY MESSAGE
	MOV DX,OFFSET INPUT1
	MOV AH,09H
	INT 21H
  
;GET FIRST NUMBER
	MOV AH,08H
	INT 21H
  
;DISPLAY ON SCREEN
	MOV DL,AL
	MOV AH,02H
	INT 21H
  
;MOVE FIRST NUMBER AND CONVERT
	AND DL,15
	MOV BL,DL
   
;BLANK LINE
	MOV DX,OFFSET BLANK
	MOV AH,09H
	INT 21H
   
;DISPLAY MESSAGE
	MOV DX,OFFSET INPUT2
	MOV AH,09H
	INT 21H
  
;GET SECOND NUMBER
	MOV AH,08H
	INT 21H
   
;DISPLAY ON SCREEN
	MOV DL,AL
	MOV AH,02H
	INT 21H

;MOVE SECOND NUMBER AND CONVERT
	AND DL,15
	MOV CL,DL
  
;BLANK LINE
	MOV DX,OFFSET BLANK
	MOV AH,09H
	INT 21H
  
;DISPLAY MESSAGE
	MOV DX,OFFSET ANSWER
	MOV AH,09H
	INT 21H
   
;ADD NUMBERS
	MOV AL,BL
	ADD AL,CL
	MOV DL,AL
	OR DL,48
  
;DISPLAY ANSWER

	MOV AH,02H
	INT 21H
   
;TIDY UP
  
	INT 20H
   
;MESSAGES
  
INPUT1 DB 'Please input a number :-','$'
   
INPUT2 DB 'Please input a second number :-','$'
   
BLANK DB '',13,10,'$'
   
ANSWER DB 'The answer is:- ','$'


;SUB.Asm 
;M.D.Shirtliffe
;1.0
  
;SET UP
	ORG 100H

;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT1
  	MOV AH,09H
  	INT 21H
  
;GET FIRST NUMBER
  	MOV AH,08H
  	INT 21H
  
;DISPLAY ON SCREEN
  	MOV DL,AL
  	MOV AH,02H
  	INT 21H
  
;MOVE FIRST NUMBER AND CONVERT
  	AND DL,15
  	MOV BL,DL
   
;BLANK LINE
   	MOV DX,OFFSET BLANK
   	MOV AH,09H
   	INT 21H
   
;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT2
   	MOV AH,09H
   	INT 21H
  
;GET SECOND NUMBER
   	MOV AH,08H
   	INT 21H
   
;DISPLAY ON SCREEN
   	MOV DL,AL
   	MOV AH,02H
   	INT 21H

;MOVE SECOND NUMBER AND CONVERT
   	AND DL,15
   	MOV CL,DL
  
;BLANK LINE
   	MOV DX,OFFSET BLANK
  	MOV AH,09H
  	INT 21H
  
;DISPLAY MESSAGE
   	MOV DX,OFFSET ANSWER
   	MOV AH,09H
   	INT 21H
   
;SUB NUMBERS
	MOV AL,BL
	SUB AL,CL
	MOV DL,AL
  	OR DL,48
  
;DISPLAY ANSWER

  	MOV AH,02H
   	INT 21H
   
;TIDY UP
  
	INT 20H
   
;MESSAGES
  
INPUT1 DB 'Please input a number :-','$'
   
INPUT2 DB 'Please input a second number :-','$'
   
BLANK DB '',13,10,'$'
   
ANSWER DB 'The answer is:- ','$'

;MUL.Asm 
;M.D.Shirtliffe
;1.0
  
;SET UP
	ORG 100H

;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT1
  	MOV AH,09H
  	INT 21H
  
;GET FIRST NUMBER
  	MOV AH,08H
  	INT 21H
  
;DISPLAY ON SCREEN
  	MOV DL,AL
  	MOV AH,02H
  	INT 21H
  
;MOVE FIRST NUMBER AND CONVERT
  	AND DL,15
  	MOV BL,DL
   
;BLANK LINE
   	MOV DX,OFFSET BLANK
   	MOV AH,09H
   	INT 21H
   
;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT2
   	MOV AH,09H
   	INT 21H
  
;GET SECOND NUMBER
   	MOV AH,08H
   	INT 21H
   
;DISPLAY ON SCREEN
   	MOV DL,AL
   	MOV AH,02H
   	INT 21H

;MOVE SECOND NUMBER AND CONVERT
   	AND DL,15
   	MOV CL,DL
  
;BLANK LINE
   	MOV DX,OFFSET BLANK
  	MOV AH,09H
  	INT 21H
  
;DISPLAY MESSAGE
   	MOV DX,OFFSET ANSWER
   	MOV AH,09H
   	INT 21H
   
;MUL NUMBERS
	MOV AL,BL
	MUL CL
	MOV DL,AL
  	OR DL,48
  
;DISPLAY ANSWER

  	MOV AH,02H
   	INT 21H
   
;TIDY UP
  
	INT 20H
   
;MESSAGES
  
INPUT1 DB 'Please input a number :-','$'
   
INPUT2 DB 'Please input a second number :-','$'
   
BLANK DB '',13,10,'$'
   
ANSWER DB 'The answer is:- ','$'

;DIV.asm
;M.D.Shirtliffe
;1.0
  
;SET UP
	ORG 100H

;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT1
  	MOV AH,09H
  	INT 21H
  
;GET FIRST NUMBER
  	MOV AH,08H
  	INT 21H
  
;DISPLAY ON SCREEN
  	MOV DL,AL
  	MOV AH,02H
  	INT 21H
  
;MOVE FIRST NUMBER AND CONVERT
  	AND DL,15
  	MOV BL,DL
   
;BLANK LINE
   	MOV DX,OFFSET BLANK
   	MOV AH,09H
   	INT 21H
   
;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT2
   	MOV AH,09H
   	INT 21H
  
;GET SECOND NUMBER
   	MOV AH,08H
   	INT 21H
   
;DISPLAY ON SCREEN
   	MOV DL,AL
   	MOV AH,02H
   	INT 21H

;MOVE SECOND NUMBER AND CONVERT
   	AND DL,15
   	MOV CL,DL
  
;BLANK LINE
   	MOV DX,OFFSET BLANK
  	MOV AH,09H
  	INT 21H
  
;DISPLAY MESSAGE
   	MOV DX,OFFSET ANSWER
   	MOV AH,09H
   	INT 21H
   
;DIV NUMBERS
	MOV AX,BX
	DIV CL
	MOV DL,AL
  	OR DL,48
  
;DISPLAY ANSWER

  	MOV AH,02H
   	INT 21H
   
;TIDY UP
  
	INT 20H
   
;MESSAGES
  
INPUT1 DB 'Please input a number :-','$'
   
INPUT2 DB 'Please input a second number :-','$'
   
BLANK DB '',13,10,'$'
   
ANSWER DB 'The answer is:- ','$'

CALC.ASM
Matthew Shirtliffe
#make_COM# ;emu8086 MAKES A .COM FILE WHEN COMPILED

include 'emu8086.inc' ;defines library for easier input/output

ORG     100h ;STARTS PROGRAM IN 100h

; get first number:
CALL    PTHIS

DB 13, 10, 'Calculator' ,13, 10 ;PRINTS MESSEGE IN '   ' ON SCREEN
DB 13, 10, '', 0  ;BLANK ; adds a blank line LINE
BEGIN:
CALL    PTHIS
DB 13, 10, '' ,13, 10
DB 13, 10, 'Press 1 Addition' ,13, 10           ;PRINTS MESSEGE IN '   ' ON SCREEN
DB 13, 10, 'Press 2 Subtraction' ,13, 10        ;PRINTS MESSEGE IN '   ' ON SCREEN
DB 13, 10, 'Press 3 Multiplacation' ,13, 10     ;PRINTS MESSEGE IN '   ' ON SCREEN
DB 13, 10, 'Press 4 Division' ,13, 10           ;PRINTS MESSEGE IN '   ' ON SCREEN
DB 13, 10, 'Press anyother key to exit' ,13, 10 ;PRINTS MESSEGE IN '   ' ON SCREEN
DB 13, 10, 'Please press now ', 0               ;PRINTS MESSEGE IN '   ' ON SCREEN

CALL    scan_num

; keep first number:
MOV     BX, CX  ;MOVES THE VALUE IN CX TO BX

CMP BX,1 	;COMPARES THE VALUE IN BX TO THE LITERAL 1
JE ONE 		;IF BX AND LITERAL ARE EQUAL THEN JUMP TO LINE LABEL ONE

CMP BX,2	;COMPARES THE VALUE IN BX TO THE LITERAL 2
JE TWO		;IF BX AND LITERAL ARE EQUAL THEN JUMP TO LINE LABEL TWO

CMP BX,3	;COMPARES THE VALUE IN BX TO THE LITERAL 3
JE THREE	;IF BX AND LITERAL ARE EQUAL THEN JUMP TO LINE LABEL THREE

CMP BX,4	;COMPARES THE VALUE IN BX TO THE LITERAL 4
JE FOUR		;IF BX AND LITERAL ARE EQUAL THEN JUMP TO LINE LABEL FOUR

JMP STOP	;ANY OTHER KEY STOPS PROGRAM, THIS IS CALLED KEY TRAPPING



;JE JUMP EQUAL CAN ONLY JUMP A SHORT DISTANCE IN CODE, SO WE USE AN UNCONDITIONAL JUMP JMP
;TO GET OVER THIS PROBLEM

ONE:		;THIS IS A LINE LABEL
JMP ONE1:	;JUMPS TO ADDITION 

TWO:        ;THIS IS A LINE LABEL
JMP TWO2:   ;JUMPS TO SUBTRACTION

THREE:      ;THIS IS A LINE LABEL
JMP THREE3: ;JUMPS TO MULTIPLICATION

FOUR:       ;THIS IS A LINE LABEL
JMP FOUR4:  ;JUMPS TO DIVISION

STOP:       ;stops program if any undesired input is pressed
JMP EXIT:   ;jumps to exit

ONE1:
CALL    PTHIS
DB 13, 10, 'You selected ADD: ', 0 ;PRINTS MESSEGE IN '   ' ON SCREEN


;DISPLAY MESSAGE
	MOV DX,OFFSET INPUT1 ;PRINTS "Please input a number :-"
	MOV AH,09H   ;moves 9 hexidecimal to ah
	INT 21H ; takes input
  
;GET FIRST NUMBER
call SCAN_NUM ; reads and stores in CX
  
;DISPLAY ON SCREEN
	MOV DX,CX ; moves value from CX to DX
	MOV AH,02H ;moves 2 hexidecimal to ah
	INT 21H ; takes input
  
;MOVE FIRST NUMBER AND CONVERT
	MOV BX,DX ;moves value from DX to BX 
   
;BLANK ; adds a blank line LINE
	MOV DX,OFFSET BLANK ; adds a blank line  
	MOV AH,09H ;moves 9 hexidecimal to ah
	INT 21H ; takes input 
	   
;DISPLAY MESSAGE
	MOV DX,OFFSET INPUT2 ;Prints Please input a second number :- 
	MOV AH,09H  ;moves 9 hexidecimal to ah
	INT 21H ; takes input
  
;GET SECOND NUMBER
call SCAN_NUM ; reads and stores in CX
   
;DISPLAY ON SCREEN
	MOV DX,CX ; moves value from CX to DX
	MOV AH,02H ;moves 2 hexidecimal to ah
	INT 21H ; takes input

;MOVE SECOND NUMBER AND CONVERT
	
	MOV CX,DX ; moves value from DX to CX
  
;BLANK ; adds a blank line LINE
	MOV DX,OFFSET BLANK ; adds a blank line
	MOV AH,09H  ;moves 9 hexidecimal to ah
	INT 21H ; takes input
  
;DISPLAY MESSAGE
	MOV DX,OFFSET ANSWER ;prints 'The answer is:- '
	MOV AH,09H  ;moves 9 hexidecimal to ah
	INT 21H ; takes input
   
;ADD NUMBERS
	MOV AX,BX  ;moves the value in bx into ax
	ADD AX,CX  ;adds value in cx to ax
	
  
;DISPLAY ANSWER

call PRINT_NUM  ;prints a signed number in ax
	
   
JMP BEGIN  ;brings program back to the beginning


   

TWO2:
CALL    PTHIS
DB 13, 10, 'You selected SUB: ', 0   ;PRINTS MESSEGE IN '   ' ON SCREEN
;SET UP


;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT1 ;PRINTS "Please input a number :-"
  	MOV AH,09H
  	INT 21H ; takes input
  
;GET FIRST NUMBER
  	call SCAN_NUM ; reads and stores in CX
  	;INT 21H ; takes input
  
;DISPLAY ON SCREEN
  	MOV DX,CX ; moves value from CX to DX
  	MOV AH,02H ;moves 2hex to ah
  	INT 21H ; takes input
  
;MOVE FIRST NUMBER AND CONVERT
  	MOV BX,DX   ;moves value in dx to bx
   
;BLANK ; adds a blank line LINE
   	MOV DX,OFFSET BLANK ; adds a blank line
   	MOV AH,09H     ;moves 9 hex to ah
   	INT 21H ; takes input
   
;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT2 ;Prints Please input a second number :-
   	MOV AH,09H  ;moves 9 hex to ah
   	INT 21H ; takes input
  
;GET SECOND NUMBER
   	call SCAN_NUM ; reads and stores in CX
   
   
;DISPLAY ON SCREEN
   	MOV DX,CX ; moves value from CX to DX
   	

;MOVE SECOND NUMBER AND CONVERT
   	MOV CX,DX ; moves value from DX to CX
  
;BLANK ; adds a blank line LINE
   	MOV DX,OFFSET BLANK ; adds a blank line
  	MOV AH,09H
  	INT 21H ; takes input
  
;DISPLAY MESSAGE
   	MOV DX,OFFSET ANSWER
   	MOV AH,09H
   	INT 21H ; takes input
   
;SUB NUMBERS
	MOV AX,BX
	SUB AX,CX
	
  
;DISPLAY ANSWER
 call PRINT_NUM ;prints
  	
   
JMP BEGIN

   

THREE3:
CALL    PTHIS
DB 13, 10, 'You selected MUL: ', 0


;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT1 ;PRINTS "Please input a number :-"
  	MOV AH,09H
  	INT 21H ; takes input
  

 call SCAN_NUM ; reads and stores in CX
  
;DISPLAY ON SCREEN
  	MOV DX,CX ; moves value from CX to DX
	MOV AH,02H
	INT 21H ; takes input
  
;MOVE FIRST NUMBER AND CONVERT
  	;AND DL,15
  	MOV BX,DX
   
;BLANK ; adds a blank line LINE
   	MOV DX,OFFSET BLANK ; adds a blank line
   	MOV AH,09H
   	INT 21H ; takes input
   
;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT2 ;Prints Please input a second number :-
   	MOV AH,09H
   	INT 21H ; takes input
  
;GET SECOND NUMBER
   	call SCAN_NUM ; reads and stores in CX
   
;DISPLAY ON SCREEN
   	MOV DX,CX ; moves value from CX to DX
	MOV AH,02H
	INT 21H ; takes input

;MOVE SECOND NUMBER AND CONVERT
   	
	MOV CX,DX ; moves value from DX to CX
  
;BLANK ; adds a blank line LINE
   	MOV DX,OFFSET BLANK ; adds a blank line
  	MOV AH,09H
  	INT 21H ; takes input
  
;DISPLAY MESSAGE
   	MOV DX,OFFSET ANSWER  ; prints the awnser
   	MOV AH,09H ;moves 9 hex to ah
   	INT 21H ; takes input
   
;MUL NUMBERS
	MOV AX,BX ;voves 
	MUL CX ;multiplies CX and AX
	
  
;DISPLAY ANSWER

call PRINT_NUM  ;put value in ax
	
   
JMP BEGIN ;goes back to the begining

  



FOUR4:
CALL    PTHIS   ;prints a string
DB 13, 10, 'You selected DIV: ', 0  ;prints You selected DIV:


;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT1 ;PRINTS "Please input a number :-"
  	MOV AH,09H ;put 9 hex in ah
  	INT 21H ; takes input
  
;GET FIRST NUMBER
  	;MOV AH,08H
  	;INT 21H ; takes input
  call SCAN_NUM ; reads and stores in CX
  	
  
;DISPLAY ON SCREEN
  	MOV DX,CX ; moves value from CX to DX
  	MOV AH,02H ;moves 02 hex to AH
  	INT 21H ; takes input
  
;MOVE FIRST NUMBER AND CONVERT
  	MOV BX,DX ;moves DX value to BX
   
;BLANK ; adds a blank line LINE
   	MOV DX,OFFSET BLANK ; adds a blank line
   	MOV AH,09H ;moves 09 hex to AH
   	INT 21H ; takes input
   
;DISPLAY MESSAGE
   	MOV DX,OFFSET INPUT2 ;Prints Please input a second number :-
   	MOV AH,09H  ;moves 09 hex to AH
   	INT 21H ; takes input
  
;GET SECOND NUMBER
   call SCAN_NUM ; reads and stores in CX
   
;DISPLAY ON SCREEN
   	MOV DX,CX ; moves value from CX to DX
   	MOV AH,02H  ;moves 02 hex to AH
   	INT 21H ; takes input

;MOVE SECOND NUMBER AND CONVERT
   	MOV CX,DX ; moves value from DX to CX
  
;BLANK ; adds a blank line LINE
   	MOV DX,OFFSET BLANK ; adds a blank line
  	MOV AH,09H ;moves 09 hex to AH
  	INT 21H ; takes input
  
;DISPLAY MESSAGE
   	MOV DX,OFFSET ANSWER  ;prints the awswer is
   	MOV AH,09H ;moves 09 hex to AH
   	INT 21H ; takes input
   
;DIV NUMBERS              
	MOV AX,BX ;moves BX value to AX
	DIV Cl    ;divides AX and CL

  
;DISPLAY ANSWER
 CALL PRINT_NUM  ;put value in ax 
    
 
   
JMP BEGIN ;goes back to thr beginning

   
;MESSAGES
  
INPUT1 DB 'Please input a number :-','$'
   
INPUT2 DB 'Please input a second number :-','$'
   
BLANK DB '',13,10,'$'
   
ANSWER DB 'The answer is:- ','$'


EXIT:
CALL    PTHIS
DB 13, 10, 'EXIT: ', 0
HLT
;RET


;=================================
; here we define the functions
; from emu8086.inc

DEFINE_SCAN_NUM

; SCAN_NUM reads a
; number from the user and stores
; it in CX register.


DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS

; PRINT_NUM prints a signed
; number in AX.
; PRINT_NUM_UNS prints an unsigned
; number in AX (required by 
; PRINT_NUM):

DEFINE_PTHIS

; PTHIS prints NULL terminated
; string defined just after
; the CALL PTHIS instruction:

;=================================
END

</code>


Is This A Good Question/Topic? 0
  • +

Replies To: calculater.asm

#2 nathanpc   User is offline

  • SCIENCE!
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,171
  • Joined: 31-July 09

Re: calculater.asm

Posted 04 December 2009 - 10:04 AM

Very nice work!
Was This Post Helpful? 0
  • +
  • -

#3 nadmike   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-February 10

Re: calculater.asm

Posted 11 February 2010 - 09:16 PM

GREAT!! how about a code with an output: Enter Expression: 12345+12345 ; The Sum is = 24690 ; for addition OR Enter Expression: 12345-12345 The Difference is = 0 -im just bothered for this Machine Problem
Was This Post Helpful? 0
  • +
  • -

#4 ditol   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 14-May 10

Re: calculater.asm

Posted 14 May 2010 - 01:38 AM

Thanks for job.....::
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1