Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2013
191
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.     div Num2Int
  162.     mov ResultInt , al
  163.     pop ax
  164.     ret
  165.  
  166. ModDo:
  167.     push ax
  168.     mov ax , word ptr Num1Int
  169.     div Num2Int
  170.     mov ResultInt , ah
  171.     pop ax
  172.     ret
  173.    
  174. PowDo:
  175.     push ax
  176.     push cx
  177.     mov ch , 0
  178.     mov cl, Num2Int
  179.     dec cl
  180.     mov al , Num1Int
  181.     Lo1:
  182.         mul Num1Int
  183.         mov Temp , ax
  184.         mov al , byte ptr Temp
  185.     loop Lo1
  186.     mov ResultInt , al
  187.     pop cx
  188.     pop ax
  189.     ret
  190.  
  191. ;***********************************************************************
  192.  
  193. Start:
  194.     mov ax,@data
  195.     mov ds,ax
  196.    
  197.    
  198. Menu:
  199.     push offset MenuText
  200.     call PrintLine
  201.     call NewLine
  202. ;End Menu
  203.  
  204. NumbersInput:
  205.     Num1Inp:
  206.         push offset Num1Text
  207.         call PrintLine
  208.         call NewLine
  209.         push offset Num1Str
  210.         call StringInput
  211.         call NewLine
  212.     Num2Inp:   
  213.         push offset Num2Text
  214.         call PrintLine
  215.         call NewLine
  216.         push offset Num2Str
  217.         call StringInput
  218.         call NewLine
  219. ;End NumbersInput
  220.  
  221. NumbersToInt:
  222.     Num1ToInt:
  223.         push offset Num1Str
  224.         push offset Num1Int
  225.         call StringToInt
  226.     Num2ToInt:
  227.         push offset Num2Str
  228.         push offset Num2Int
  229.         call StringToInt
  230. ;End NumbersToInt  
  231.  
  232. OperationInput:
  233.     push offset OperText
  234.     call PrintLine
  235.     call NewLine
  236.     mov ah , 1
  237.     int 21h
  238.     mov Oper , al
  239.     call NewLine
  240. ;End OperationInput
  241.    
  242. OperIfs:
  243.     cmp Oper , 2BH
  244.     je Plus
  245.     cmp Oper , 2DH
  246.     je Minus
  247.     cmp Oper , 2AH
  248.     je Multi
  249.     cmp Oper , 2FH
  250.     je Divide
  251.     cmp Oper , 25H
  252.     je ModTag
  253.     cmp Oper , 5EH
  254.     je Pow
  255.     cmp Oper , 78H
  256.     je Exit
  257.     WrongOper1:
  258.         push offset WrongOper
  259.         call PrintLine
  260.         jmp OperationInput
  261. ;End OperIfs
  262.  
  263. Plus:
  264.     call PlusDo
  265.     jmp ResultPrint
  266. ;End Plus
  267.  
  268. Minus:
  269.     call MinusDo
  270.     jmp ResultPrint
  271. ;End Minus
  272.  
  273. Multi:
  274.     call MultiDo
  275.     jmp ResultPrint
  276. ;End Multi
  277.  
  278. Divide:
  279.     call DivideDo
  280.     jmp ResultPrint
  281. ;End Divide
  282.  
  283. Pow:
  284.     call PowDo
  285.     jmp ResultPrint
  286. ;End Pow
  287.  
  288. ModTag:
  289.     call ModDo
  290.     jmp ResultPrint
  291. ;End ModTag
  292.  
  293. ResultPrint:
  294.     push offset ResultString
  295.     push offset ResultInt
  296.     call IntToStr
  297.     push offset ResultText
  298.     call PrintLine
  299.     call NewLine
  300.     push offset ResultString
  301.     call PrintLine
  302. ;End ResultPrint
  303.  
  304. Restart1:
  305.     call NewLine
  306.     call NewLine
  307.     call NewLine
  308.     jmp Menu
  309.  
  310. Exit:
  311.     mov ax,4c00h
  312.     int 21h
  313. End Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement