flat assembler
Message board for the users of flat assembler.

Index > Windows > Write modulo result

Author
Thread Post new topic Reply to topic
TmX



Joined: 02 Mar 2006
Posts: 821
Location: Jakarta, Indonesia
TmX
I tried to calculate the result of modulo operation, let's say 1234 mod 10

Code:
format PE console 4.0
entry main

include 'win32a.inc'

section '.data' data readable writeable
num1 dd 1234
num2 dd 10
fmt db "%d", 13, 10, 0

section '.code' code readable executable
main:
        xor edx, edx
        mov ebx, num1
       mov ecx, num2
       div ecx
     cinvoke printf, fmt, edx
    invoke ExitProcess, 0
       
section '.idata' import data readable
library kernel32,'kernel32.dll', msvcrt,'msvcrt.dll'
import kernel32, ExitProcess,'ExitProcess'
import msvcrt, printf, 'printf'    


Why is the output of the code 4101638, not 4?
Post 05 Sep 2012, 15:48
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1408
Location: Toronto, Canada
AsmGuru62
MOVE EAX,NUM1
Post 05 Sep 2012, 16:11
View user's profile Send private message Send e-mail Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 821
Location: Jakarta, Indonesia
TmX
Still yields the wrong result... :/
Post 06 Sep 2012, 06:08
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 692
Location: Adelaide
sinsi
Brackets.
Post 06 Sep 2012, 06:26
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 821
Location: Jakarta, Indonesia
TmX
You mean like this?

Code:
xor edx, edx
mov eax, num1
mov ecx, num2
div ecx
cinvoke printf, fmt, [edx]    


The output is 1234.
The reminder of a DIV operation is stored in EDX, right?
http://css.csail.mit.edu/6.858/2011/readings/i386/DIV.htm
Post 06 Sep 2012, 08:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17247
Location: In your JS exploiting you and your system
revolution
num1 is a pointer. But we assume you actually want the number stored at num1, is that correct? If so then:
Code:
mov eax,[num1]    
Post 06 Sep 2012, 08:05
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1408
Location: Toronto, Canada
AsmGuru62
And brackets on num2 also.
Post 06 Sep 2012, 10:24
View user's profile Send private message Send e-mail Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 821
Location: Jakarta, Indonesia
TmX
Code:
xor edx, edx
mov eax, [num1]
mov ecx, [num2]
div ecx
cinvoke printf, fmt, edx
invoke ExitProcess, 0    


works as expected. thanks Very Happy
Post 06 Sep 2012, 15:13
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.