• ¡Welcome to Square Theme!
  • This news are in header template.
  • Please ignore this message.
مهمان عزیز خوش‌آمدید. ورود عضــویت


امتیاز موضوع:
  • 31 رای - 2.39 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
Title: سورس کد ماشین حساب (اسمبلی)
حالت موضوعی
#1
Calculater.asm
made in emu8086

کد:
;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
گروه دور همی پارسی کدرز
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg
 
پاسخ
  


موضوعات مشابه ...
موضوع نویسنده پاسخ بازدید آخرین ارسال
  سورس کد نوشتن در بوت سکتور فلاپی (اسمبلی Amin_Mansouri 2 7,846 02-18-2024، 03:23 PM
آخرین ارسال: roozonline
  سورس کد ساعت (اسمبلی) Amin_Mansouri 1 5,222 07-18-2017، 06:29 PM
آخرین ارسال: yaldama15
  سورس کد پرینت اعداد و حروف به صورت وارونه (اسمبلی ۸۰۸۶) Amin_Mansouri 1 6,681 07-18-2017، 04:39 PM
آخرین ارسال: yaldama15
  سورس کد فاکتوریل اسمبلی 8086 Amin_Mansouri 0 4,281 06-08-2014، 10:54 PM
آخرین ارسال: Amin_Mansouri
  سور کد ماشین حساب (اسمبلی) Amin_Mansouri 0 4,832 05-11-2012، 05:27 PM
آخرین ارسال: Amin_Mansouri
  ،سورس کد فرستادن ایمیل از طریق وینساک (اسمبلی) Amin_Mansouri 0 5,103 05-11-2012، 05:07 PM
آخرین ارسال: Amin_Mansouri
  منبع آموزشی اسمبلی son of wisdom 0 4,733 06-16-2011، 10:39 AM
آخرین ارسال: son of wisdom
  آموزش اسمبلی Amin_Mansouri 0 5,262 05-23-2011، 01:00 PM
آخرین ارسال: Amin_Mansouri

پرش به انجمن:


Browsing: 1 مهمان