Pushok

assembler calc

Mar 7th, 2011
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .386
  2. .model flat,stdcall
  3. option   casemap:none
  4.     include \masm32\include\masm32.inc
  5.     include \masm32\include\gdi32.inc
  6.     include \masm32\include\user32.inc
  7.     include \masm32\include\kernel32.inc
  8.     include \masm32\include\shell32.inc
  9.     include \masm32\macros\macros.asm
  10.     include \masm32\include\msvcrt.inc
  11.  
  12.     includelib \masm32\lib\masm32.lib
  13.     includelib \masm32\lib\gdi32.lib
  14.     includelib \masm32\lib\user32.lib
  15.     includelib \masm32\lib\kernel32.lib
  16.     includelib \masm32\lib\shell32.lib
  17.     includelib  \masm32\lib\msvcrt.lib
  18.     P proto :DWORD, :DWORD
  19. .DATA
  20.     Hello db "Type your command!: ",0
  21.     InvalidOp db "This is invalid..",0Ah,0
  22.     FirstOp db "Type first operand: ",0
  23.     SecOp db "Type second operand: ",0
  24.     Answer db "%d %c %d = %d",0Ah,0
  25.     AnswerF db "%d %c %d = %d,%d",0Ah,0
  26.     Oper byte 0
  27.     Plus db "+",0
  28.     Op db 8 dup (0)
  29.     Numa db 8 dup (0)
  30.     N_a dword ?
  31.     Numb db 8 dup (0)
  32.     N_b dword ?
  33. .CODE
  34. START:
  35.     lea eax,Hello
  36.     push eax
  37.     call StdOut
  38.     push 8
  39.     lea eax,Op
  40.     push eax
  41.     call StdIn
  42.     xor eax,eax
  43.     lea eax,Op
  44.     cmp byte ptr[eax],'+'
  45.     je ADDICTION
  46.     cmp byte ptr[eax],'-'
  47.     je SUBSTRACTION
  48.     cmp byte ptr[eax],'/'
  49.     je DIVISION
  50.     cmp byte ptr[eax],'*'
  51.     je MULTIPLY
  52.     jmp INVALID
  53. CONTINUE:
  54.     cls
  55.     lea eax, FirstOp
  56.     push eax
  57.     call StdOut
  58.     xor eax,eax
  59.     push 8
  60.     lea eax,Numa
  61.     push eax
  62.     call StdIn
  63.     lea eax,Numa
  64.     push eax
  65.     call atol
  66.     mov N_a,eax
  67.     cls
  68.     push 8
  69.     lea eax,SecOp
  70.     push eax
  71.     call StdOut
  72.     push 8
  73.     lea eax,Numb
  74.     push eax
  75.     call StdIn
  76.     lea eax,Numb
  77.     push eax
  78.     call atol
  79.     mov N_b,eax
  80.     cmp Oper,1
  81.     je AD
  82.     cmp Oper,2
  83.     je SU
  84.     cmp Oper,3
  85.     je DV
  86.     jne MU
  87.     jmp INVALID
  88. AD:
  89.     mov eax,N_a
  90.     add eax,N_b
  91.     push eax
  92.     push N_b
  93.     push '+'
  94.     push N_a
  95.     lea eax,Answer
  96.     push eax
  97.     call crt_printf
  98.     jmp START
  99. SU:
  100.     mov eax,N_a
  101.     sub eax,N_b
  102.     push eax
  103.     push N_b
  104.     push '-'
  105.     push N_a
  106.     lea eax, Answer
  107.     push eax
  108.     call crt_printf
  109.     jmp START
  110. DV:
  111.     mov eax,N_a
  112.     push edx
  113.     xor edx,edx
  114.     div N_b
  115.     mov ebx,edx
  116.     pop edx
  117.     push ebx
  118.     push eax
  119.     push N_b
  120.     push '/'
  121.     push N_a
  122.     lea eax, AnswerF
  123.     push eax
  124.     call crt_printf
  125.     jmp START
  126. MU:
  127.     mov eax,N_a
  128.     mul N_b
  129.     push eax
  130.     push N_b
  131.     push '*'
  132.     push N_a
  133.     lea eax, Answer
  134.     push eax
  135.     call crt_printf
  136.     jmp START
  137. ADDICTION:
  138.     mov Oper,1
  139.     jmp CONTINUE
  140. SUBSTRACTION:
  141.     mov Oper,2
  142.     jmp CONTINUE
  143. DIVISION:
  144.     mov Oper,3
  145.     jmp CONTINUE
  146. MULTIPLY:
  147.     mov Oper,4
  148.     jmp CONTINUE
  149. INVALID:
  150.     push offset InvalidOp
  151.     call StdOut
  152.     jmp START
  153. EXIT:
  154.     invoke  ExitProcess, 0
  155. END  START
Advertisement
Add Comment
Please, Sign In to add comment