Vulpes

test_floats_s

Nov 30th, 2011
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extern      printf
  2. extern      reg_print
  3. extern      stk_print
  4.  
  5. segment     .data
  6.  
  7. fpstackprint:   db      `st7: [%.4E] `,10,`st6: [%.4E] `,10,`st5: [%.4E] `,10,`st4: [%.4E] `,10,
  8.         db      `st3: [%.4E] `,10,`st2: [%.4E] `,10,`st1: [%.4E] `,10,`st0: [%.4E] `,10,10,0  
  9.  
  10. hex_of_float:   db      `x%.8f`,10,0
  11.  
  12.  
  13.  
  14. segment     .txt
  15.         global      test_floats
  16.  
  17.  
  18.  
  19. ;;;------------------------------------------------------------------------------------------------------------------------
  20. ;;;   begin main section
  21. ;;;------------------------------------------------------------------------------------------------------------------------
  22.  
  23. test_floats:
  24. ;;test_floats(float * num1, float * num2);
  25.  
  26.  
  27.         ;mov        ezx,        [ebp+08h]   ;; arg 1 num1 3.5
  28.         ;mov        ezx,        [ebp+0Ch]   ;; arg 2 num2 1.5
  29.  
  30.         enter       0,0
  31.         pusha      
  32.        
  33.         mov     eax,        1
  34.  
  35.         mov     esi,        [ebp+08h]
  36.         fld     dword [esi]
  37.         mov     esi,        [ebp+0Ch]
  38.         fld     dword [esi]
  39.         fldz
  40.         fldz
  41.         fldz
  42.         fldz
  43.         fld1
  44.         fld1
  45.         ;^ this portion here, I just fill out the float stack with 8 numbers
  46.  
  47.        
  48.         mov     ecx,        esp
  49.         mov     edx,        ebp
  50.         call        reg_print
  51.         call        stk_print
  52.  
  53.         call        print_fpstack
  54.         ;; segfault occurs before this line
  55.         ;^ something not right with the esp & ebp when this is called
  56.        
  57.  
  58.  
  59.        
  60.         mov     ecx,        esp
  61.         mov     edx,        ebp
  62.         call        reg_print
  63.         call        stk_print
  64.  
  65.  
  66.                                 ;; [0]  [011 1111 1111]  [1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]    
  67.                                 ;; 0011 1111 1111 1100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
  68.                                 ;; x 3FF8 0000 0000 0000
  69.         ;mov        eax,        3FFC0000h   ;; this is 1.75f
  70.         ;mov        ebx,        00000000h
  71.         ;push       eax
  72.         ;push       ebx
  73.  
  74.         ;sub        esp,        8       ;; emulating a PUSH
  75.         ;fst        qword [esp]         ;; this is supposed to take st0 & put it into memory (4 bytes)
  76.        
  77.         ;push       hex_of_float
  78.         ;call       printf
  79.  
  80.         ;pop        eax
  81.  
  82.         ;call       print_fpstack
  83.  
  84.         ;fld1
  85.  
  86.         popa
  87.         leave
  88.         ret
  89. ;;;------------------------------------------------------------------------------------------------------------------------
  90. ;;;   end main section
  91. ;;;------------------------------------------------------------------------------------------------------------------------
  92.  
  93. print_fpstack:
  94.        
  95.         enter       0,0
  96.         ;pusha
  97.  
  98.         mov     ecx,        esp
  99.         mov     edx,        ebp
  100.         call        reg_print
  101.         call        stk_print           ;;ok so far
  102.  
  103.  
  104.  
  105.         sub     esp,        8       ;; emulating a PUSH  what if my psuh is backwards ... again
  106.         fstp        qword [esp]         ;; this is supposed to take st0 & put it into memory (8 bytes)
  107.  
  108.         sub     esp,        8
  109.         fstp        qword [esp]
  110.  
  111.         sub     esp,        8
  112.         fstp        qword [esp]
  113.  
  114.         sub     esp,        8
  115.         fstp        qword [esp]
  116.  
  117.         sub     esp,        8
  118.         fstp        qword [esp]
  119.  
  120.         sub     esp,        8
  121.         fstp        qword [esp]
  122.  
  123.         sub     esp,        8
  124.         fstp        qword [esp]
  125.  
  126.         sub     esp,        8
  127.         fstp        qword [esp]
  128.    
  129.         push        fpstackprint
  130.  
  131.  
  132.         mov     ecx,        esp
  133.         mov     edx,        ebp
  134.         call        reg_print
  135.         call        stk_print
  136.  
  137.  
  138.         call        printf
  139.  
  140.  
  141.         mov     ecx,        esp
  142.         mov     edx,        ebp
  143.         call        reg_print
  144.         call        stk_print
  145.  
  146.         add     esp,        04h     ;; fpstackprint push - pop'd
  147.  
  148.         fld     qword [esp]         ;;1
  149.         add     esp,        08h
  150.  
  151.         fld     qword [esp]         ;;2
  152.         add     esp,        08h
  153.  
  154.         fld     qword [esp]         ;;3
  155.         add     esp,        08h
  156.  
  157.         fld     qword [esp]         ;;4
  158.         add     esp,        08h
  159.  
  160.         fld     qword [esp]         ;;5
  161.         add     esp,        08h
  162.  
  163.         fld     qword [esp]         ;;6
  164.         add     esp,        08h
  165.  
  166.         fld     qword [esp]         ;;7
  167.         add     esp,        08h
  168.  
  169.         fld     qword [esp]         ;;8, 8 floats a,ha-ha-ha-ha (the count)
  170.         add     esp,        08h
  171.  
  172.         ;add        esp,        4Ah;
  173.        
  174.  
  175.  
  176.         ;popa
  177.         leave
  178.         ret
Advertisement
Add Comment
Please, Sign In to add comment