Accueil > > > FLOATTOHEX CODE DE BRUNEWS RETRENSCRIS EN ASM PAR MOI
FLOATTOHEX CODE DE BRUNEWS RETRENSCRIS EN ASM PAR MOI
Information sur la source
Description
convertis nombre reel en simple et double hexadecimal petit utilitaire pour dévelopeur trés utile avec masm32 parceque l'on ne peut pas mettre un float literalement sur la pile. ex: push 1.5f ;erreur push 3FC00000h ;ok fld dword ptr [esp] add esp,4 ainsi il n'est pas obligatoire de definir une variable ! ATTENTION Ce programme utilise des instructions SSE2 1 - il faut savoir si votre proc comporte le jeux d'instruction SSE2 2 - pour compiler il faut remplacer le ml.exe d'origine avec celui qui ce trouve dans le ZIP,ou dans SP5 qui ce trouve à l'addresse http://mirror.href.com/thestarman/asm/masm.htm. Sinon il ne reconnaitra pas la syntaxe xmm. Ce code peut être un BON didactel pour SSE2
Source
- .686p
- .model flat,stdcall
- option casemap:none
- .xmm
-
- include windows.inc
- include kernel32.inc
- include user32.inc
- includelib kernel32
- includelib user32.lib
-
-
- AppDlgProc PROTO :HWND,:UINT,:WPARAM,:LPARAM
- ProcEdFloat PROTO :HWND,:UINT,:WPARAM,:LPARAM
- FloatsToHex PROTO
-
- .CONST
-
- IDD_APP EQU 101
- IDI_APP EQU 102
- ID_TXT EQU 1001
- ID_DBL EQU 1002
- ID_FLT EQU 1003
-
-
-
- .DATA
- ;ALIGN 16
- BNDIXPZERO dq 4024000000000000h
- BNUNDIXIEM dq 3FB999999999999Ah
- BNMINUSDBL dq 8000000000000000h
-
-
-
- hdbl dd 0
- hflt dd 0
- htxt dd 0
- oldFloatProc dd 0
-
-
- .CODE
- START: INVOKE DialogBoxParam,400000h,101,0,addr AppDlgProc,400000h
- INVOKE ExitProcess,0
-
- ;################################################## AppDlgProc ####################################################################
-
- AppDlgProc PROC hdlg:HWND,msg:UINT,wParam:WPARAM,lParam:LPARAM
- mov eax,msg
- cmp eax,WM_INITDIALOG
- je WMINIT
- cmp eax,WM_COMMAND
- je WMCMD
- jmp DLG
- WMINIT: INVOKE LoadIcon,400000h,IDI_APP
- INVOKE SetClassLong,hdlg,GCL_HICON,eax
- INVOKE GetDlgItem,hdlg,ID_TXT
- mov htxt,eax
- INVOKE SendMessage,eax, EM_LIMITTEXT, 15, 0
- INVOKE SetWindowLong,htxt, GWL_WNDPROC,ADDR ProcEdFloat
- mov oldFloatProc,eax
- INVOKE GetDlgItem,hdlg,ID_DBL
- mov hdbl,eax
- INVOKE GetDlgItem,hdlg,ID_FLT
- mov hflt,eax
- jmp DLG
- WMCMD: mov eax,wParam
- and eax,0FFFFh
- cmp eax,IDOK
- jnz @F
- INVOKE FloatsToHex
- jmp DLG
- @@: cmp eax,IDCANCEL
- jnz DLG
- INVOKE EndDialog,hdlg,0
- DLG: sub eax,eax
- ret
- AppDlgProc ENDP
-
- ;##################################################### ProcEdFloat #############################################################
-
- ProcEdFloat PROC hwnd:HWND,msg:UINT,wParam:WPARAM,lParam:LPARAM
- LOCAL buf[16]:BYTE
- mov eax,msg
- cmp eax,WM_CHAR
- je WMCHAR
- jmp DEFRET
- WMCHAR: mov eax,wParam
- cmp eax,VK_BACK
- je DEFRET
- cmp eax,57
- jg NOGOOD
- cmp eax,48
- jge DEFRET
- cmp eax,44
- jl NOGOOD
- cmp eax,46
- jg NOGOOD
- cmp eax,45
- jge GVERIF
- mov wParam,46
- GVERIF: INVOKE GetWindowText,hwnd,addr buf, 16
- lea edi,buf
- mov ecx,eax
- mov eax,wParam
- repne scasb
- jne DEFRET
- NOGOOD: sub eax,eax
- ret
- DEFRET: INVOKE CallWindowProc,oldFloatProc, hwnd, msg, wParam, lParam
- ret
- ProcEdFloat ENDP
-
- ;########################################################### FloatsToHex #########################################################
-
- FloatsToHex PROC
- sub esp, 32
- mov ecx, 16
- mov eax, esp
- INVOKE GetWindowText,htxt,eax,16
- mov ecx, esp
- call bnatod
- DB 0F2h,0Fh,11h,44h,24h,14h ;movsd qword ptr[esp+20],XMM0
- cvtsd2ss XMM2,XMM0
- mov edx, esp
- mov ecx, dword ptr[esp+24]
- call bndwordtox
- mov edx, eax
- mov ecx, dword ptr[esp+20]
- call bndwordtox
- push esp
- push hdbl
- call SetWindowText
- movss dword ptr[esp+20], XMM2
- mov edx, esp
- mov ecx, dword ptr[esp+20]
- call bndwordtox
- push esp
- push hflt
- call SetWindowText
- add esp, 32
- sub eax,eax
- ret
- FloatsToHex ENDP
-
- ;############################################################ bndwordtox ####################################################
- ;ECX = dwnum, EDX = szdst
- bndwordtox PROC
- mov al, cl
- add edx, 8
- and cl, 15
- shr al, 4
- add cl, 48
- add al, 48
- cmp cl, 57
- jbe short L1
- add cl, 7
- L1: cmp al, 57
- jbe short L2
- add al, 7
- L2: mov byte ptr[edx-1], cl
- mov byte ptr[edx-2], al
- shr ecx, 8
- mov byte ptr[edx], 0
- mov al, cl
- and cl, 15
- shr al, 4
- add cl, 48
- add al, 48
- cmp cl, 57
- jbe short L3
- add cl, 7
- L3: cmp al, 57
- jbe short L4
- add al, 7
- L4: mov byte ptr[edx-3], cl
- mov byte ptr[edx-4], al
- shr ecx, 8
- mov al, cl
- and cl, 15
- shr al, 4
- add cl, 48
- add al, 48
- cmp cl, 57
- jbe short L5
- add cl, 7
- L5: cmp al, 57
- jbe short L6
- add al, 7
- L6: mov byte ptr[edx-5], cl
- mov byte ptr[edx-6], al
- shr ecx, 8
- mov byte ptr[edx], 0
- mov al, cl
- and cl, 15
- shr al, 4
- add cl, 48
- add al, 48
- cmp cl, 57
- jbe short L7
- add cl, 7
- L7: cmp al, 57
- jbe short L8
- add al, 7
- L8: mov byte ptr[edx-7], cl
- mov byte ptr[edx-8], al
- mov eax, edx
- ret
- bndwordtox ENDP
-
- ;####################################################### bnatod ###########################################################
- ;ECX = psz
- bnatod PROC
- push ebx
- xorps XMM0, XMM0
- DB 0F2h,0Fh,10h,0Dh ;movsd XMM1,
- DD OFFSET BNDIXPZERO ;qword ptr BNDIXPZERO
- xor ebx, ebx
- xor edx, edx
- xor eax, eax
- movapd XMM3, XMM0
- cmp byte ptr[ecx], 45
- jne short outZERO
- add ecx, 1
- add ebx, 1
- outZERO:mov al, [ecx]
- cmp al, 48
- jne short goINT
- add ecx, 1
- jmp short outZERO
- goINT: cmp al, 46
- je short goDCML
- sub al, 48
- js short goSIGN
- cmp al, 9
- ja short goSIGN
- cvtsi2sd XMM2, eax
- mulsd XMM0, XMM1
- add ecx, 1
- addsd XMM0, XMM2
- mov al, [ecx]
- jmp short goINT
- goDCML: add ecx, 1
- mov al, [ecx]
- inDCML: sub al, 48
- js short dcmlIF
- cmp al, 9
- ja short dcmlIF
- cvtsi2sd XMM2, eax
- mulsd XMM0, XMM1
- add ecx, 1
- add edx, 1
- addsd XMM0, XMM2
- mov al, [ecx]
- jmp short inDCML
- dcmlIF: test edx, edx
- je short goSIGN
- DB 0F2h,0Fh,10h,15h ;MOVSD XMM2,
- DD OFFSET BNUNDIXIEM ;qword ptr BNUNDIXIEM
- dcmlADD:sub edx, 1
- mulsd XMM0, XMM2
- jne short dcmlADD
- goSIGN: comisd XMM0, XMM3
- je short atodEXIT
- test ebx, ebx
- je short atodEXIT
- DB 0F2h,0Fh,10h,0Dh ;movsd XMM1,
- DD OFFSET BNMINUSDBL ;qword ptr BNMINUSDBL
- subsd XMM1, XMM0
- movapd XMM0, XMM1
- atodEXIT:
- pop ebx
- sub eax,eax
- ret
- bnatod ENDP
-
- END START
.686p
.model flat,stdcall
option casemap:none
.xmm
include windows.inc
include kernel32.inc
include user32.inc
includelib kernel32
includelib user32.lib
AppDlgProc PROTO :HWND,:UINT,:WPARAM,:LPARAM
ProcEdFloat PROTO :HWND,:UINT,:WPARAM,:LPARAM
FloatsToHex PROTO
.CONST
IDD_APP EQU 101
IDI_APP EQU 102
ID_TXT EQU 1001
ID_DBL EQU 1002
ID_FLT EQU 1003
.DATA
;ALIGN 16
BNDIXPZERO dq 4024000000000000h
BNUNDIXIEM dq 3FB999999999999Ah
BNMINUSDBL dq 8000000000000000h
hdbl dd 0
hflt dd 0
htxt dd 0
oldFloatProc dd 0
.CODE
START: INVOKE DialogBoxParam,400000h,101,0,addr AppDlgProc,400000h
INVOKE ExitProcess,0
;################################################## AppDlgProc ####################################################################
AppDlgProc PROC hdlg:HWND,msg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,msg
cmp eax,WM_INITDIALOG
je WMINIT
cmp eax,WM_COMMAND
je WMCMD
jmp DLG
WMINIT: INVOKE LoadIcon,400000h,IDI_APP
INVOKE SetClassLong,hdlg,GCL_HICON,eax
INVOKE GetDlgItem,hdlg,ID_TXT
mov htxt,eax
INVOKE SendMessage,eax, EM_LIMITTEXT, 15, 0
INVOKE SetWindowLong,htxt, GWL_WNDPROC,ADDR ProcEdFloat
mov oldFloatProc,eax
INVOKE GetDlgItem,hdlg,ID_DBL
mov hdbl,eax
INVOKE GetDlgItem,hdlg,ID_FLT
mov hflt,eax
jmp DLG
WMCMD: mov eax,wParam
and eax,0FFFFh
cmp eax,IDOK
jnz @F
INVOKE FloatsToHex
jmp DLG
@@: cmp eax,IDCANCEL
jnz DLG
INVOKE EndDialog,hdlg,0
DLG: sub eax,eax
ret
AppDlgProc ENDP
;##################################################### ProcEdFloat #############################################################
ProcEdFloat PROC hwnd:HWND,msg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL buf[16]:BYTE
mov eax,msg
cmp eax,WM_CHAR
je WMCHAR
jmp DEFRET
WMCHAR: mov eax,wParam
cmp eax,VK_BACK
je DEFRET
cmp eax,57
jg NOGOOD
cmp eax,48
jge DEFRET
cmp eax,44
jl NOGOOD
cmp eax,46
jg NOGOOD
cmp eax,45
jge GVERIF
mov wParam,46
GVERIF: INVOKE GetWindowText,hwnd,addr buf, 16
lea edi,buf
mov ecx,eax
mov eax,wParam
repne scasb
jne DEFRET
NOGOOD: sub eax,eax
ret
DEFRET: INVOKE CallWindowProc,oldFloatProc, hwnd, msg, wParam, lParam
ret
ProcEdFloat ENDP
;########################################################### FloatsToHex #########################################################
FloatsToHex PROC
sub esp, 32
mov ecx, 16
mov eax, esp
INVOKE GetWindowText,htxt,eax,16
mov ecx, esp
call bnatod
DB 0F2h,0Fh,11h,44h,24h,14h ;movsd qword ptr[esp+20],XMM0
cvtsd2ss XMM2,XMM0
mov edx, esp
mov ecx, dword ptr[esp+24]
call bndwordtox
mov edx, eax
mov ecx, dword ptr[esp+20]
call bndwordtox
push esp
push hdbl
call SetWindowText
movss dword ptr[esp+20], XMM2
mov edx, esp
mov ecx, dword ptr[esp+20]
call bndwordtox
push esp
push hflt
call SetWindowText
add esp, 32
sub eax,eax
ret
FloatsToHex ENDP
;############################################################ bndwordtox ####################################################
;ECX = dwnum, EDX = szdst
bndwordtox PROC
mov al, cl
add edx, 8
and cl, 15
shr al, 4
add cl, 48
add al, 48
cmp cl, 57
jbe short L1
add cl, 7
L1: cmp al, 57
jbe short L2
add al, 7
L2: mov byte ptr[edx-1], cl
mov byte ptr[edx-2], al
shr ecx, 8
mov byte ptr[edx], 0
mov al, cl
and cl, 15
shr al, 4
add cl, 48
add al, 48
cmp cl, 57
jbe short L3
add cl, 7
L3: cmp al, 57
jbe short L4
add al, 7
L4: mov byte ptr[edx-3], cl
mov byte ptr[edx-4], al
shr ecx, 8
mov al, cl
and cl, 15
shr al, 4
add cl, 48
add al, 48
cmp cl, 57
jbe short L5
add cl, 7
L5: cmp al, 57
jbe short L6
add al, 7
L6: mov byte ptr[edx-5], cl
mov byte ptr[edx-6], al
shr ecx, 8
mov byte ptr[edx], 0
mov al, cl
and cl, 15
shr al, 4
add cl, 48
add al, 48
cmp cl, 57
jbe short L7
add cl, 7
L7: cmp al, 57
jbe short L8
add al, 7
L8: mov byte ptr[edx-7], cl
mov byte ptr[edx-8], al
mov eax, edx
ret
bndwordtox ENDP
;####################################################### bnatod ###########################################################
;ECX = psz
bnatod PROC
push ebx
xorps XMM0, XMM0
DB 0F2h,0Fh,10h,0Dh ;movsd XMM1,
DD OFFSET BNDIXPZERO ;qword ptr BNDIXPZERO
xor ebx, ebx
xor edx, edx
xor eax, eax
movapd XMM3, XMM0
cmp byte ptr[ecx], 45
jne short outZERO
add ecx, 1
add ebx, 1
outZERO:mov al, [ecx]
cmp al, 48
jne short goINT
add ecx, 1
jmp short outZERO
goINT: cmp al, 46
je short goDCML
sub al, 48
js short goSIGN
cmp al, 9
ja short goSIGN
cvtsi2sd XMM2, eax
mulsd XMM0, XMM1
add ecx, 1
addsd XMM0, XMM2
mov al, [ecx]
jmp short goINT
goDCML: add ecx, 1
mov al, [ecx]
inDCML: sub al, 48
js short dcmlIF
cmp al, 9
ja short dcmlIF
cvtsi2sd XMM2, eax
mulsd XMM0, XMM1
add ecx, 1
add edx, 1
addsd XMM0, XMM2
mov al, [ecx]
jmp short inDCML
dcmlIF: test edx, edx
je short goSIGN
DB 0F2h,0Fh,10h,15h ;MOVSD XMM2,
DD OFFSET BNUNDIXIEM ;qword ptr BNUNDIXIEM
dcmlADD:sub edx, 1
mulsd XMM0, XMM2
jne short dcmlADD
goSIGN: comisd XMM0, XMM3
je short atodEXIT
test ebx, ebx
je short atodEXIT
DB 0F2h,0Fh,10h,0Dh ;movsd XMM1,
DD OFFSET BNMINUSDBL ;qword ptr BNMINUSDBL
subsd XMM1, XMM0
movapd XMM0, XMM1
atodEXIT:
pop ebx
sub eax,eax
ret
bnatod ENDP
END START
Conclusion
Ce code est de Brunews moi je ne comprend rien que ce soit pour la routine de convertion ou que ce soit des instructions SSE2. J'ai fait que retrenscrire un code pour VC en code pour MASM32.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Convertion asm vers hex (ou bin) [ par mistigry ]
J'utilise un PIC16F870 avec le compilateur CH Basic V1.2, ce compilateur me fournit des fichier asm (ou bsc) et pour pouvoir transférer le fichier sur
convertion chaine hexa en decimal [ par mousse85 ]
Quelqu'un pourrai m'aider ? Il me faudrai un morceau de code qui me permettrai de convertir une chaine Hexadecimal, se trouvant dans une variable de t
convertion binaire vers ascii [ par MUSICMANIAC ]
bonjour,comment fait on pour convertir un fichier binaire 16 bitsen plusieurs caracteres ascii?language assaembleurmicro pic16f84
Utilisation de la FPU [ par vecchio56 ]
J'essaie d'utiliser la FPU pour faire ne serait-ce qu'une fonction très simple, qui revoie l'argument qu'on lui passe:__declspec(naked) float __fastca
Inserer de l'hexadecimal avec Visual Basic [ par meuh33 ]
Bonjour !Je souhaite remplacer une partie du code en hexadecimal dans un exe via une aplication visual basic 6, comment faire ?je sais envoyer de
Problème de convertion [ par titaniume ]
Comment réaliser des cds-rom pc boot, avec saut de cd.Lorsque l'on a un dvd-rom pc.Y a t-il un logiciel ou une technique pour réaliser cela?J'ai déjà
MASM ne gère pas le SSE2 ? [ par epineurien ]
Bonjour à tous !Moi et mon compilo. , je pourrais écrire un roman...Voilà le problême, je voudrait utiliser le SSE2 pour accélerer les calculs, problê
|
Derniers Blogs
[MIX 2010] - TELECHARGEZ INTERNET EXPLORER 9 EN PREVIEW ![MIX 2010] - TELECHARGEZ INTERNET EXPLORER 9 EN PREVIEW ! par redo
La Preview de Windows Explorer 9 est maintenant disponible à l'adresse suivante : http://ie.microsoft.com/testdrive/ Cette version ne nécessite pas un redémarrage de votre machine pour être exploitée . Cette version est fonctionnelle mais reste cependant ...
Cliquez pour lire la suite de l'article par redo [MIX 2010] - KEYNOTE DAY 2 ONLINE : WINDOWS INTERNET EXPLORER 9, JQUERY, ODATA ET DALLAS CTP2 ![MIX 2010] - KEYNOTE DAY 2 ONLINE : WINDOWS INTERNET EXPLORER 9, JQUERY, ODATA ET DALLAS CTP2 ! par redo
Dans la lignée du premier keynote, retrouvez la vidéo du second keynote en ligne : Visionnez la vidéo à l'url suivante : http://www.microsoft.com/presspass/events/mix/VideoGallery.aspx Vous y retrouverez ainsi les speakers Scott Guthrie, Dean Hachamovitch...
Cliquez pour lire la suite de l'article par redo [MIX 2010] - RETOUR D'EXPéRIENCE DéVELOPPEMENT SEESMIC SUR WINDOWS PHONE 7[MIX 2010] - RETOUR D'EXPéRIENCE DéVELOPPEMENT SEESMIC SUR WINDOWS PHONE 7 par redo
En avant première, Loic le retour d'expérience de Loïc Le Meur du portage de l'application http://seesmic.com/ sur plateforme Windows Phone 7 . c'était d'ailleurs une des rares opportunités de tester, voir toucher le nouveau device . voyez par vous-même :...
Cliquez pour lire la suite de l'article par redo [MIX 2010] - LE KEYNOTE DAY 1 DISPONIBLE ONLINE ![MIX 2010] - LE KEYNOTE DAY 1 DISPONIBLE ONLINE ! par redo
Si tout comme moi, vous avez manqué de peu le premier keynote du Microsoft Mix 2010, je vous invite à prendre deux heure et le consulter ci-dessous . Visionnez le Keynote à l'url suivante : http://www.microsoft.com/Presspass/events/mix/videoGallery.aspx?c...
Cliquez pour lire la suite de l'article par redo VISUAL STUDIO TALK SHOW: EF4VISUAL STUDIO TALK SHOW: EF4 par Matthieu MEZIL
La semaine dernière, j'étais à Montréal pour y animer des conférences sur Entity Framework. J'en ai profité pour enregister un podcast Visual Studio Talk Show que vous pouvez retrouver ici ....(read more) ...
Cliquez pour lire la suite de l'article par Matthieu MEZIL
Forum
RE : CSHARPRE : CSHARP par ghuysmans99
Cliquez pour lire la suite par ghuysmans99 CSHARPCSHARP par nano16
Cliquez pour lire la suite par nano16
Logiciels
Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods Konvertor (4.00)KONVERTOR (4.00)Le logiciel est un gestionnaire multimedia affichant, jouant et convertissant plus de 2000 format... Cliquez pour télécharger Konvertor
|