Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2013
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Model small
  2. stack 100h
  3. Dataseg
  4.     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","$"
  5.     Num1Text db "Please Enter Number 1 (0-255) : " , "$"
  6.     Num2Text db "Please Enter Number 2 (0-255) : " , "$"
  7.     OperText db "Please Enter The Arithmetic : " , "$"
  8.     ResultText db "The Result is : ","$"
  9.     WrongOper db "Error : You Entered A Wrong Arithmetic , Please Repeat : ","$"
  10.     Num1Str db 4 dup(?)
  11.     Num2Str db 4 dup(?)
  12.     Num1Int db ?
  13.     Num2Int db ?
  14.     ResultInt db ?
  15.     ResultString db 4 dup(?)
  16.     Oper db ?
  17.     Temp dw ?
  18.  
  19. Codeseg
  20. NewLine:                               ; פרוצדורה שיורדת שורה
  21.     push ax
  22.     push dx
  23.     mov ah,2
  24.     mov dl,13
  25.     int 21h
  26.     mov dl,10
  27.     int 21h
  28.     pop dx
  29.     pop ax
  30.     ret
  31.    
  32. PrintLine:                             ; פרוצדורה שמדפיסה מחרוזת
  33.         push bp
  34.         mov bp , sp
  35.         push ax
  36.         push dx
  37.         mov dx , [bp+4]
  38.         mov ah,9
  39.         int 21h
  40.         pop dx
  41.         pop ax
  42.         pop bp
  43.     ret 2
  44.    
  45. StringInput:                           ;פרוצדורה שקולטת מחרוזת
  46.     push bp
  47.     mov bp , sp
  48.     push ax
  49.     push bx
  50.     mov bx , [bp+4]
  51.    
  52.     Kelet:
  53.         mov ah,1
  54.         int 21h
  55.         cmp al,0dH
  56.         je Kelet2
  57.         mov [bx],al
  58.         inc bx
  59.         jmp Kelet
  60.     Kelet2:
  61.         mov byte ptr[bx] , '$'
  62.         pop bx
  63.         pop ax
  64.         pop bp
  65.     ret 2
  66.    
  67. IntToStr:                         ; string לטיפוס int פרוצדורה שממירה מטיפוס
  68.     push bp
  69.     mov bp , sp
  70.     push ax
  71.     push bx
  72.     push dx
  73.     push cx
  74.     mov cx , 0
  75.     mov bx , [bp+4]
  76.     mov al , [bx]
  77.     mov bx , [bp+6]
  78.     mov ah , 0
  79.     mov dl , 10
  80.     I1:
  81.         cmp al,0
  82.         je I2
  83.         mov ah,0
  84.         div dl
  85.         push ax
  86.         inc cx
  87.         jmp I1
  88.     I2:
  89.         pop ax
  90.         add ah,30H
  91.         mov [bx] , ah
  92.         inc bx
  93.         loop I2
  94.         mov byte ptr [bx] , '$'
  95.         pop cx
  96.         pop dx
  97.         pop bx
  98.         pop ax
  99.         pop bp
  100.        
  101.     ret 4
  102.    
  103. StringToInt:                      ;int לטיפוס string פרוצדורה שממירה מטיפוס
  104.     push bp
  105.     mov bp , sp
  106.     push ax
  107.     push bx
  108.     push dx
  109.     mov ax , 0
  110.     mov dl , 10
  111.     mov bx , [bp+6]
  112.     S1:
  113.         cmp byte ptr [bx] , '$'
  114.         je s2
  115.         mul dl
  116.         mov dh , [bx]
  117.         sub dh , 30H
  118.         add al , dh
  119.         inc bx
  120.         jmp s1
  121.     S2:
  122.         mov bx , [bp+4]
  123.         mov [bx] , al
  124.         pop dx
  125.         pop bx
  126.         pop ax
  127.         pop bp
  128.    
  129.     ret 4  
  130.  
  131. PlusDo:
  132.     push ax
  133.     mov al , Num1Int
  134.     add al , Num2Int
  135.     mov ResultInt , al
  136.     pop ax
  137.     ret
  138.    
  139. MinusDo:
  140.     push ax
  141.     mov al , Num1Int
  142.     Sub al , Num2Int
  143.     mov ResultInt , al
  144.     pop ax
  145.     ret
  146.    
  147. MultiDo:
  148.     push ax
  149.     mov al , Num1Int
  150.     mul Num2Int
  151.     ;mov ResultInt , byte ptr ax
  152.     mov Temp , ax
  153.     mov al , byte ptr Temp
  154.     mov ResultInt , al
  155.     pop ax
  156.     ret
  157.    
  158. DivideDo:
  159.     push ax
  160.     ;mov ax , word ptr Num1Int
  161.     mov ah , 0
  162.     mov al , Num1Int
  163.     div Num2Int
  164.     mov ResultInt , al
  165.     pop ax
  166.     ret
  167.  
  168. ModDo:
  169.     push ax
  170.     ;mov ax , word ptr Num1Int
  171.     mov ah , 0
  172.     mov al , Num1Int
  173.     div Num2Int
  174.     mov ResultInt , ah
  175.     pop ax
  176.     ret
  177.    
  178. PowDo:
  179.     push ax
  180.     push cx
  181.     mov ch , 0
  182.     mov cl, Num2Int
  183.     dec cl
  184.     mov al , Num1Int
  185.     Lo1:
  186.         mul Num1Int
  187.         mov Temp , ax
  188.         mov al , byte ptr Temp
  189.     loop Lo1
  190.     mov ResultInt , al
  191.     pop cx
  192.     pop ax
  193.     ret
  194.  
  195. ;***********************************************************************
  196.  
  197. Start:
  198.     mov ax,@data
  199.     mov ds,ax
  200.    
  201.    
  202. Menu:
  203.     push offset MenuText
  204.     call PrintLine
  205.     call NewLine
  206. ;End Menu
  207.  
  208. NumbersInput:
  209.     Num1Inp:
  210.         push offset Num1Text
  211.         call PrintLine
  212.         call NewLine
  213.         push offset Num1Str
  214.         call StringInput
  215.         call NewLine
  216.     Num2Inp:   
  217.         push offset Num2Text
  218.         call PrintLine
  219.         call NewLine
  220.         push offset Num2Str
  221.         call StringInput
  222.         call NewLine
  223. ;End NumbersInput
  224.  
  225. NumbersToInt:
  226.     Num1ToInt:
  227.         push offset Num1Str
  228.         push offset Num1Int
  229.         call StringToInt
  230.     Num2ToInt:
  231.         push offset Num2Str
  232.         push offset Num2Int
  233.         call StringToInt
  234. ;End NumbersToInt  
  235.  
  236. OperationInput:
  237.     push offset OperText
  238.     call PrintLine
  239.     call NewLine
  240.     mov ah , 1
  241.     int 21h
  242.     mov Oper , al
  243.     call NewLine
  244. ;End OperationInput
  245.    
  246. OperIfs:
  247.     cmp Oper , 2BH
  248.     je Plus
  249.     cmp Oper , 2DH
  250.     je Minus
  251.     cmp Oper , 2AH
  252.     je Multi
  253.     cmp Oper , 2FH
  254.     je Divide
  255.     cmp Oper , 25H
  256.     je ModTag
  257.     cmp Oper , 5EH
  258.     je Pow
  259.     cmp Oper , 78H
  260.     je Exit
  261.     WrongOper1:
  262.         push offset WrongOper
  263.         call PrintLine
  264.         jmp OperationInput
  265. ;End OperIfs
  266.  
  267. Plus:
  268.     call PlusDo
  269.     jmp ResultPrint
  270. ;End Plus
  271.  
  272. Minus:
  273.     call MinusDo
  274.     jmp ResultPrint
  275. ;End Minus
  276.  
  277. Multi:
  278.     call MultiDo
  279.     jmp ResultPrint
  280. ;End Multi
  281.  
  282. Divide:
  283.     call DivideDo
  284.     jmp ResultPrint
  285. ;End Divide
  286.  
  287. Pow:
  288.     call PowDo
  289.     jmp ResultPrint
  290. ;End Pow
  291.  
  292. ModTag:
  293.     call ModDo
  294.     jmp ResultPrint
  295. ;End ModTag
  296.  
  297. ResultPrint:
  298.     push offset ResultString
  299.     push offset ResultInt
  300.     call IntToStr
  301.     push offset ResultText
  302.     call PrintLine
  303.     call NewLine
  304.     push offset ResultString
  305.     call PrintLine
  306. ;End ResultPrint
  307.  
  308. Restart1:
  309.     call NewLine
  310.     call NewLine
  311.     call NewLine
  312.     jmp Menu
  313.  
  314. Exit:
  315.     mov ax,4c00h
  316.     int 21h
  317. End Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement