News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

compiled PE file crash , please review my little code

Started by Laish, October 02, 2012, 05:52:29 PM

Previous topic - Next topic

Laish

Hi,
i have wrote a simple app that is suppose to print to the Console the result of 2 to the power of 38 , it is working and give me the result but then it crash, I would like to know what am i doing wrong, i am think that the crash has more to do with the Console app construction rather with the code logic. So what do you think i can change here ?

.386
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\msvcrt.inc
includelib \masm32\lib\msvcrt.lib

.data

formatstr db "%lld",0

.code
start:
xor edx, edx
mov eax, 2
mov ecx, 38

x1: dec ecx
jz ready
rcl eax, 1
rcl edx, 1
jmp x1

ready:
invoke crt__cprintf, addr formatstr, eax, edx


end start


Thanks.

jj2007

Give it a chance to exit properly:

invoke crt__cprintf, addr formatstr, eax, edx
ret


The official way is invoke ExitProcess, 0 but that would require some more includes.

Welcome to the forum :icon14:

Laish

Hey, Thanks . You suggestion works.


  • is there a simpler way to invoke the printf of Microsoft CRT ?
  • what you mean by the "official way", by whom ?

hutch--


MichaelW

If you are trying to display the combined values of EAX and EDX as a single 64-bit value, in the Microsoft format specifications you should use the size prefix "I64". The size prefixes "ll" and "l" specify 32-bit values.


;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
    .data
    .code
;==============================================================================
start:
;==============================================================================

    mov eax, 1
    mov edx, 2
    printf("%.16llXh\n", eax, edx)

    mov eax, 1
    mov edx, 2
    printf("%.16lXh\n", eax, edx)

    mov eax, 1
    mov edx, 2
    printf("%.16I64Xh\n\n", eax, edx)

    inkey
    exit
;==============================================================================
END start


0000000000000001h
0000000000000001h
0000000200000001h


Or on 64-bit platforms you can use "I".

http://msdn.microsoft.com/en-us/library/56e442dc(v=vs.71).aspx

Well Microsoft, here's another nice mess you've gotten us into.

dedndave

i would use SHL EAX,1, then RCL EDX,1
actually, i would probably use XOR EAX,EAX, then MOV EDX,40h and be done with it   :P
xor edx, edx
mov eax, 2
mov ecx, 38

x1: dec ecx
jz ready
rcl eax, 1
rcl edx, 1
jmp x1

Gunther

Hi Laish,

welcome to the forum. You're on the right way.  :t

Gunther
You have to know the facts before you can distort them.

Vortex