News:

Download Pelles C here: http://www.pellesc.se

Main Menu

Magic division

Started by Vortex, Yesterday at 08:50:06 PM

Previous topic - Next topic

Vortex

Here is an example of an alternative division method :

.386
.model flat,stdcall
option casemap:none

printf PROTO C :DWORD,:VARARG

ExitProcess PROTO :DWORD

.data

msg         db '4500 / 3 = %u',0

.code

start:

    mov     eax,4500
    mov     edx,0AAAAAAABh
    mul     edx
    shr     edx,1
    invoke  printf,ADDR msg,edx

    invoke  ExitProcess,0

END start
Code it... That's all...

Vortex

Here is the signed version :

.386
.model flat,stdcall
option casemap:none

printf PROTO C :DWORD,:VARARG

ExitProcess PROTO :DWORD

.data

msg         db '-15000 / 3 = %d',0

.code

start:

    mov     eax,-15000
    mov     ecx,eax
    mov     edx,055555556h
    imul    edx
    sar     ecx,31
    sub     edx,ecx
    invoke  printf,ADDR msg,edx

    invoke  ExitProcess,0

END start
Code it... That's all...