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.
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:
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 ?
Yeah, use the MASM32 macro for printf. :biggrin:
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
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
Hi Laish,
welcome to the forum. You're on the right way. :t
Gunther
Hi Laish,
Welcome to the forum.