Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Model small
- stack 100h
- Dataseg
- MenuText db "Welcome to the calculator : ",13,10,"To Add -> + ",13,10,"To Sub -> - ",13,10, "To Mul -> *" ,13,10,"To Div -> / ",13,10,"To Mod -> % ",13,10,"To Pow -> ^",13,10,"To Exit -> x","$"
- Num1Text db "Please Enter Number 1 (0-255) : " , "$"
- Num2Text db "Please Enter Number 2 (0-255) : " , "$"
- OperText db "Please Enter The Arithmetic : " , "$"
- ResultText db "The Result is : ","$"
- WrongOper db "Error : You Entered A Wrong Arithmetic , Please Repeat : ","$"
- Num1Str db 4 dup(?)
- Num2Str db 4 dup(?)
- Num1Int db ?
- Num2Int db ?
- ResultInt db ?
- ResultString db 4 dup(?)
- Oper db ?
- Temp dw ?
- Codeseg
- NewLine: ; פרוצדורה שיורדת שורה
- push ax
- push dx
- mov ah,2
- mov dl,13
- int 21h
- mov dl,10
- int 21h
- pop dx
- pop ax
- ret
- PrintLine: ; פרוצדורה שמדפיסה מחרוזת
- push bp
- mov bp , sp
- push ax
- push dx
- mov dx , [bp+4]
- mov ah,9
- int 21h
- pop dx
- pop ax
- pop bp
- ret 2
- StringInput: ;פרוצדורה שקולטת מחרוזת
- push bp
- mov bp , sp
- push ax
- push bx
- mov bx , [bp+4]
- Kelet:
- mov ah,1
- int 21h
- cmp al,0dH
- je Kelet2
- mov [bx],al
- inc bx
- jmp Kelet
- Kelet2:
- mov byte ptr[bx] , '$'
- pop bx
- pop ax
- pop bp
- ret 2
- IntToStr: ; string לטיפוס int פרוצדורה שממירה מטיפוס
- push bp
- mov bp , sp
- push ax
- push bx
- push dx
- push cx
- mov cx , 0
- mov bx , [bp+4]
- mov al , [bx]
- mov bx , [bp+6]
- mov ah , 0
- mov dl , 10
- I1:
- cmp al,0
- je I2
- mov ah,0
- div dl
- push ax
- inc cx
- jmp I1
- I2:
- pop ax
- add ah,30H
- mov [bx] , ah
- inc bx
- loop I2
- mov byte ptr [bx] , '$'
- pop cx
- pop dx
- pop bx
- pop ax
- pop bp
- ret 4
- StringToInt: ;int לטיפוס string פרוצדורה שממירה מטיפוס
- push bp
- mov bp , sp
- push ax
- push bx
- push dx
- mov ax , 0
- mov dl , 10
- mov bx , [bp+6]
- S1:
- cmp byte ptr [bx] , '$'
- je s2
- mul dl
- mov dh , [bx]
- sub dh , 30H
- add al , dh
- inc bx
- jmp s1
- S2:
- mov bx , [bp+4]
- mov [bx] , al
- pop dx
- pop bx
- pop ax
- pop bp
- ret 4
- PlusDo:
- push ax
- mov al , Num1Int
- add al , Num2Int
- mov ResultInt , al
- pop ax
- ret
- MinusDo:
- push ax
- mov al , Num1Int
- Sub al , Num2Int
- mov ResultInt , al
- pop ax
- ret
- MultiDo:
- push ax
- mov al , Num1Int
- mul Num2Int
- ;mov ResultInt , byte ptr ax
- mov Temp , ax
- mov al , byte ptr Temp
- mov ResultInt , al
- pop ax
- ret
- DivideDo:
- push ax
- mov ax , word ptr Num1Int
- div Num2Int
- mov ResultInt , al
- pop ax
- ret
- ModDo:
- push ax
- mov ax , word ptr Num1Int
- div Num2Int
- mov ResultInt , ah
- pop ax
- ret
- PowDo:
- push ax
- push cx
- mov ch , 0
- mov cl, Num2Int
- dec cl
- mov al , Num1Int
- Lo1:
- mul Num1Int
- mov Temp , ax
- mov al , byte ptr Temp
- loop Lo1
- mov ResultInt , al
- pop cx
- pop ax
- ret
- ;***********************************************************************
- Start:
- mov ax,@data
- mov ds,ax
- Menu:
- push offset MenuText
- call PrintLine
- call NewLine
- ;End Menu
- NumbersInput:
- Num1Inp:
- push offset Num1Text
- call PrintLine
- call NewLine
- push offset Num1Str
- call StringInput
- call NewLine
- Num2Inp:
- push offset Num2Text
- call PrintLine
- call NewLine
- push offset Num2Str
- call StringInput
- call NewLine
- ;End NumbersInput
- NumbersToInt:
- Num1ToInt:
- push offset Num1Str
- push offset Num1Int
- call StringToInt
- Num2ToInt:
- push offset Num2Str
- push offset Num2Int
- call StringToInt
- ;End NumbersToInt
- OperationInput:
- push offset OperText
- call PrintLine
- call NewLine
- mov ah , 1
- int 21h
- mov Oper , al
- call NewLine
- ;End OperationInput
- OperIfs:
- cmp Oper , 2BH
- je Plus
- cmp Oper , 2DH
- je Minus
- cmp Oper , 2AH
- je Multi
- cmp Oper , 2FH
- je Divide
- cmp Oper , 25H
- je ModTag
- cmp Oper , 5EH
- je Pow
- cmp Oper , 78H
- je Exit
- WrongOper1:
- push offset WrongOper
- call PrintLine
- jmp OperationInput
- ;End OperIfs
- Plus:
- call PlusDo
- jmp ResultPrint
- ;End Plus
- Minus:
- call MinusDo
- jmp ResultPrint
- ;End Minus
- Multi:
- call MultiDo
- jmp ResultPrint
- ;End Multi
- Divide:
- call DivideDo
- jmp ResultPrint
- ;End Divide
- Pow:
- call PowDo
- jmp ResultPrint
- ;End Pow
- ModTag:
- call ModDo
- jmp ResultPrint
- ;End ModTag
- ResultPrint:
- push offset ResultString
- push offset ResultInt
- call IntToStr
- push offset ResultText
- call PrintLine
- call NewLine
- push offset ResultString
- call PrintLine
- ;End ResultPrint
- Restart1:
- call NewLine
- call NewLine
- call NewLine
- jmp Menu
- Exit:
- mov ax,4c00h
- int 21h
- End Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement