Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern printf
- extern reg_print
- extern stk_print
- segment .data
- fpstackprint: db `st7: [%.4E] `,10,`st6: [%.4E] `,10,`st5: [%.4E] `,10,`st4: [%.4E] `,10,
- db `st3: [%.4E] `,10,`st2: [%.4E] `,10,`st1: [%.4E] `,10,`st0: [%.4E] `,10,10,0
- hex_of_float: db `x%.8f`,10,0
- segment .txt
- global test_floats
- ;;;------------------------------------------------------------------------------------------------------------------------
- ;;; begin main section
- ;;;------------------------------------------------------------------------------------------------------------------------
- test_floats:
- ;;test_floats(float * num1, float * num2);
- ;mov ezx, [ebp+08h] ;; arg 1 num1 3.5
- ;mov ezx, [ebp+0Ch] ;; arg 2 num2 1.5
- enter 0,0
- pusha
- mov eax, 1
- mov esi, [ebp+08h]
- fld dword [esi]
- mov esi, [ebp+0Ch]
- fld dword [esi]
- fldz
- fldz
- fldz
- fldz
- fld1
- fld1
- ;^ this portion here, I just fill out the float stack with 8 numbers
- mov ecx, esp
- mov edx, ebp
- call reg_print
- call stk_print
- call print_fpstack
- ;; segfault occurs before this line
- ;^ something not right with the esp & ebp when this is called
- mov ecx, esp
- mov edx, ebp
- call reg_print
- call stk_print
- ;; [0] [011 1111 1111] [1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
- ;; 0011 1111 1111 1100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
- ;; x 3FF8 0000 0000 0000
- ;mov eax, 3FFC0000h ;; this is 1.75f
- ;mov ebx, 00000000h
- ;push eax
- ;push ebx
- ;sub esp, 8 ;; emulating a PUSH
- ;fst qword [esp] ;; this is supposed to take st0 & put it into memory (4 bytes)
- ;push hex_of_float
- ;call printf
- ;pop eax
- ;call print_fpstack
- ;fld1
- popa
- leave
- ret
- ;;;------------------------------------------------------------------------------------------------------------------------
- ;;; end main section
- ;;;------------------------------------------------------------------------------------------------------------------------
- print_fpstack:
- enter 0,0
- ;pusha
- mov ecx, esp
- mov edx, ebp
- call reg_print
- call stk_print ;;ok so far
- sub esp, 8 ;; emulating a PUSH what if my psuh is backwards ... again
- fstp qword [esp] ;; this is supposed to take st0 & put it into memory (8 bytes)
- sub esp, 8
- fstp qword [esp]
- sub esp, 8
- fstp qword [esp]
- sub esp, 8
- fstp qword [esp]
- sub esp, 8
- fstp qword [esp]
- sub esp, 8
- fstp qword [esp]
- sub esp, 8
- fstp qword [esp]
- sub esp, 8
- fstp qword [esp]
- push fpstackprint
- mov ecx, esp
- mov edx, ebp
- call reg_print
- call stk_print
- call printf
- mov ecx, esp
- mov edx, ebp
- call reg_print
- call stk_print
- add esp, 04h ;; fpstackprint push - pop'd
- fld qword [esp] ;;1
- add esp, 08h
- fld qword [esp] ;;2
- add esp, 08h
- fld qword [esp] ;;3
- add esp, 08h
- fld qword [esp] ;;4
- add esp, 08h
- fld qword [esp] ;;5
- add esp, 08h
- fld qword [esp] ;;6
- add esp, 08h
- fld qword [esp] ;;7
- add esp, 08h
- fld qword [esp] ;;8, 8 floats a,ha-ha-ha-ha (the count)
- add esp, 08h
- ;add esp, 4Ah;
- ;popa
- leave
- ret
Advertisement
Add Comment
Please, Sign In to add comment