I am new to win32 programming and also not much of a wise guy in new processors assembly too. I did assembler to Z80, and it is alike, but some trick differences between them.

However, I have a problem now with a small code I wrote and assembled with MASM32. Ill put the whole code here.
The line where I get the fatal error is the marked one. Ill put more info on the thread about it, as it is needed.

Hope some one lightens up here!! :)


.model flat, stdcall
option casemap:none
include e:\masm32\include\windows.inc
include e:\masm32\include\kernel32.inc
include e:\masm32\include\user32.inc
includelib e:\masm32\lib\user32.lib
includelib e:\masm32\lib\kernel32.lib
;e:\masm32\bin\ml /c /coff /Cp a:\tt.asm
;e:\masm32\bin\link /SUBSYSTEM:WINDOWS /LIBPATH:e:\masm32\lib tt.obj

MsgCaption db "Hora precisa!! :)",0
MsgBoxText db "O programa que mostra a EXAAAAAATA hora que voc? o executou. Sem coisais in?teis. Enjoy!",0
UI db "Voc? executou o programa exatamente ?s:",0
Relogio db 0,0,0,0,0,0,0,0

Ofiseti db 5,16,27,38,47,53,59,65,0

jmp Pulo
String db "Ano: ***** ","Mes: ***** ","DiS: ***** ","Dia: ***** ","As *****:","*****:","*****",".*****",0

Pulo: invoke MessageBox, NULL,addr MsgBoxText, addr MsgCaption, MB_OK

push eax
mov eax,offset Relogio ;
call GetLocalTime ;Puts time in address at EAX

push ebx
push ecx
push edx
push edi
push esi

; ----- START -----

mov edx,offset Ofiseti
Num: xor ecx,ecx
mov ecx,
mov edi,offset String ;1st add. de string (thousands)
add edi,ecx
mov esi,offset Relogio ;offset do primeiro valor
call W2S0
inc edx
mov edx,
test edx,0
jnz Num

; ----- END -----

invoke MessageBox, NULL,addr String, addr UI, MB_OK

pop eax
pop bx
pop ecx
pop edx
pop edi
pop esi

invoke ExitProcess,NULL

; ------------ START ------------

W2S0: mov eax,
mov bx,30h ;SET

Ite1: sub ax,2710h
jl Ite2
inc bx
jmp Ite1

Ite2: add ax,2710h ;fiz ax number for next Iteration
add edi,2 ;points SI 2 bytes up ( WORD! ;)
; :-d

W2S1: mov bx,30h

Ite3: sub ax,3e8h
jl Ite4
inc bx
jmp Ite3

Ite4: add ax,3e8h
mov ,bx
add edi,2

W2S2: mov bx,30h

Ite5: sub ax,64h
jl Ite6
inc bx
jmp Ite5

Ite6: add ax,64h
mov ,bx
add edi,2

W2S3: mov bx,30h

Ite7: sub ax,0ah
jl Ite8
inc bx
jmp Ite7

Ite8: add ax,0ah
mov ,bx
add edi,2

W2S4: mov bx,30h ; for the last one!
add bx,ax ; what remains in AX is simple units!!
mov ,bx

; ------------- END -------------

end start

Posted on 2002-09-04 18:59:38 by wicr0s0ft
mmm... you should debugger and make lots practice with it, wicr0s0ft.

Posted on 2002-09-04 21:28:22 by dion
I haven't bothered trying to straighten out your loop, but here are three suggestions:

- is edi containing a valid pointer? How do you check that before you use it?

- you are moving a DWORD (ebx) to the location pointed to by edi, then incrementing edi by SIZEOF(WORD) == 2 bytes, so next time you copy a DWORD it will partially overwrite your previously moved DWORD. Are you meaning to copy a WORD or a DWORD?

-try using the syntax "mov DWORD PTR , ebx", just to make sure that you and the compiler do not get confused.
Posted on 2002-09-05 00:28:06 by sluggy

from your code:

push eax
mov eax,offset Relogio ;
call GetLocalTime ;Puts time in address at EAX

I can see that you should read some docs about win32 programming. Parameters for Win32 functions such as GetLocalTime will never be transfered with registers but by pushing them onto the stack, so the correct form of this call would be:

mov eax,offset Relogio ;
push eax
call GetLocalTime

or, even smaller:

push offset Relogio
call GetLocalTime

or, with "invoke":

invoke GetLocalTime, addr Relogio
Posted on 2002-09-05 02:33:19 by japheth
Fisrt of: thanks for all that replied to this. :)

I am sorry for the very raw code I left here, I was I a real rush yesterday....

Ill try to explain here what all that code is supposed to do.
The programs does only two visible things ( what we see when we run it ), wich is to display to messages, one with a "welcome" line and another with the info returned by SystemTime...

The DATA: the 1st 2 strings are shownn in the fisrt dialog. The 3rd one is the caption for the 2nd dialog, and this dialog's text is in the code section, as I was thinking that the error was because I was overwritten the bytes of .data section... as you see, my problem here are most of concepts... :-\ ... continuing: the "Relogio" data is the destination for the time struct;
the Ofiseti: is constructed with "*" in the places where we will replace with the values (Words)... as a Word can carry numbers of 5 digits (<65535).... the No 0x213 on memory would result in 00531....

The W2S0 routine (Word to String ;) works like this: gets the interger value and substract 0x2710 (10k :) from it until the result is neggative.... we count those, of course, to add 0x30 to them.... next step is to do the same thing with the remain (we add 0x2710 to eax after we find that we BLEW it....) but subtracting 0x3e8 from it.... I think you got the idea of how it works now. After this we call the Message box with our "fized" time message... :)

Dion: yes, I also think I should.... I started to debug my program in SICE, but there I thing I dont know YET about how win32 programs work.... what better way of discovering that than creating a win32 program and reversing it yourself?? ;)

sluggy: so what are you saying is that:

-the fault page my program cause is due to a probable tentative of writing in a memory address OUTSIDE my program, and that is also NOT allocated for it ( I dont use any malloc in this ). Could you tell me what I CANNOT do with a win32 program... for example, is there a register I CANNOT in absolute NO circunstances modify.... even if I restore it after I use it? If you could show me URLs or docs that provide this info, instead of having to explain all this bits, you are welcome too! :)

i did get the win32.hlp... but it didnt said HOW it gets the address of the destination struct... :( ... so, I tried to guess!! :-D
I know about invoke... but I am beggining to win32 asm, so Ill do PUSHs for a while... when Im doing enough pushs to consume tiime, Ill use the macros... ;) ... do you know where the MASM32 macros are stored?? So I could modify/add to that file my own macros too.

Thanks for the tip :)
Posted on 2002-09-05 17:00:14 by wicr0s0ft