flat assembler
Message board for the users of flat assembler.

Index > Windows > Maybe, something as error?

Author
Thread Post new topic Reply to topic
6a00



Joined: 11 Sep 2009
Posts: 5
6a00 11 Sep 2009, 19:24
When I tried to assembly this code:
Code:
format PE GUI 4.0
entry start
include 'win32a.inc'
;converts num 2 ascii symbols
macro   BIN2ASCII {      ; Enter: â ðåãèñòðå eax - ÷èñëî (BIN)
    mov    edi,[edi]     ;       â ðåãèñòðå edi - Pointer íà áóôåð (ASCII)
    mov    ebx,10
@@: xor    edx,edx
    div    ebx
    or     dl,30h
    dec    edi
    mov    byte [edi],dl
    test   eax,eax
    jnz    @b             ;Âûõîä: â ðåãèñòðå edi - óêàçàòåëü íà áóôåð (ASCII)
}

macro ascii2bin {         ;in edi pointer to data
    mov ebx,10
    xor eax,eax
    mov ecx,eax
aa: mul ebx
    xor edx,edx
    mov dl,[edi]
    xor dl,30h
    add eax,edx
    inc edi
    test edx,edx
    jz @f                 ;out in eax
    loop aa
@@:
}


section '.code' code import writable readable executable
library kernel32,'KERNEL32.DLL',\
user32,'USER32.DLL'
include 'api\kernel32.inc'
include 'api\user32.inc'

class db 'FASMWIN32',0
title db 'ÎÊÍÎ',0
classb db 'BUTTON',0
classe db 'EDIT',0
classs db 'STATIC',0
textb1 db 'add',0
textb2 db 'Î÷èñòèòü',0
textg db 'Ðàìêà',0
textc db 'Clear all',0
errtxt db 'Error',0
_text_result db 'Result',0
hwnd dd ?
_first dd ?
_second dd ?
_result dd ?
t db 'hello',0
text rb 100
dd 0

_buf dd _bufd+100
_bufd: rb 100


wc WNDCLASS 0,WindowProc,0,0,0,0,0,COLOR_BTNFACE+1,0,class

msg MSG

start:

invoke GetModuleHandle,0
mov [wc.hInstance],eax
invoke LoadIcon,0,IDI_APPLICATION
mov [wc.hIcon],eax
invoke LoadCursor,0,IDC_ARROW
mov [wc.hCursor],eax
invoke RegisterClass,wc
cmp eax,0
je error

invoke CreateWindowEx\
,0,class,title,WS_VISIBLE+WS_SYSMENU,128,120,256,192,0,0,[wc.hInstance],0
cmp eax,0
je error
mov [hwnd],eax
msg_loop:
invoke GetMessage,msg,0,0,0
cmp eax,0
je end_loop
invoke IsDialogMessage,[hwnd],msg
cmp eax,0
jne msg_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop

error:
invoke MessageBox,0,errtxt,0,MB_ICONERROR+MB_OK

end_loop:
invoke ExitProcess,[msg.wParam]

proc WindowProc hwnd,wmsg,wparam,lparam
push ebx esi edi
cmp [wmsg],WM_CREATE
je .wmcreate
cmp [wmsg],WM_COMMAND
je .wmcommand
cmp [wmsg],WM_DESTROY
je .wmdestroy
.defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp .finish
.wmcreate:
invoke CreateWindowEx,0,classb,textg,WS_VISIBLE+WS_CHILD+BS_GROUPBOX,5,5,240,150,[hwnd],1000,[wc.hInstance],0
invoke CreateWindowEx,0,classb,textb1,WS_VISIBLE+WS_CHILD+BS_PUSHBUTTON,20,100,100,40,[hwnd],1001,[wc.hInstance],0
invoke CreateWindowEx,0,classb,textb2,WS_VISIBLE+WS_CHILD+BS_PUSHBUTTON,130,100,100,40,[hwnd],1002,[wc.hInstance],0
invoke CreateWindowEx,0,classs,textg,WS_VISIBLE+WS_CHILD,190,145,43,15,[hwnd],1006,[wc.hInstance],0

invoke CreateWindowEx\
,0,classe,0,WS_VISIBLE+WS_CHILD+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL,10,25,230,20,[hwnd],1003,[wc.hInstance],0
mov [_first],eax

invoke CreateWindowEx\
,0,classe,0,WS_VISIBLE+WS_CHILD+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL,10,50,230,20,[hwnd],1004,[wc.hInstance],0
mov [_second],eax

invoke CreateWindowEx,0,classe,_text_result,WS_VISIBLE+WS_CHILD+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL+ES_READONLY\
,10,75,230,20,[hwnd],1005,[wc.hInstance],0
mov [_result],eax

;invoke CreateWindowEx,0,classe,texts,WS_VISIBLE+WS_CHILD+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL,10,25,230,20,[hwnd],1003,[wc.hInstance],0
invoke SetFocus,[_first]
jmp .finish

.wmcommand:
cmp [wparam],1001
je .but1
cmp [wparam],1002
je .but2
jmp .finish
.but1:
invoke SendMessage,[_first],WM_GETTEXT,100,text
mov [text+10],0
mov edi,text
ascii2bin
mov edi,_buf
BIN2ASCII
mov edx,dword[_buf]
sub edx,edi
invoke SendMessage,[_result],WM_SETTEXT,edx,edi
xor edi,edi






jmp .finish
.but2:
invoke SendMessage,[_second],WM_SETTEXT,0,0
invoke SendMessage,[_result],WM_SETTEXT,0,0
invoke SendMessage,[_first],WM_SETTEXT,0,0
jmp .finish
.wmdestroy:
invoke PostQuitMessage,0
mov eax,0
.finish:
pop edi esi ebx
ret
endp
    

it writes undefined symbol:je .wmdestroy
BUT when macro ascii2bin (144 line) is not included in output file program assembly is working without any error.

version 1.68
version of "FASMW.exe" file 0.93.19

winxp32sp02
Post 11 Sep 2009, 19:24
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 11 Sep 2009, 19:39
Do the following change:
Code:
macro ascii2bin {         ;in edi pointer to data
    mov ebx,10
    xor eax,eax
    mov ecx,eax
..aa: mul ebx
    xor edx,edx
    mov dl,[edi]
    xor dl,30h
    add eax,edx
    inc edi
    test edx,edx
    jz @f                 ;out in eax
    loop ..aa
@@:
}
    


The original label "aa" was hiding label ".wmdestroy". Another (not very good) solution would be prefixing the offending references with "aa." (like "je aa.wmdestroy").
Post 11 Sep 2009, 19:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 11 Sep 2009, 22:08
I think it is better to use local labels in macros:
Code:
macro ascii2bin {         ;in edi pointer to data
  local .loop
    mov ebx,10
    xor eax,eax
    mov ecx,eax
.loop: mul ebx
    xor edx,edx
    mov dl,[edi]
    xor dl,30h
    add eax,edx
    inc edi
    test edx,edx
    jz @f                 ;out in eax
    loop .loop
@@:
}    
Post 11 Sep 2009, 22:08
View user's profile Send private message Visit poster's website Reply with quote
6a00



Joined: 11 Sep 2009
Posts: 5
6a00 12 Sep 2009, 12:50
Thank you. I realized where is the problem. But what about label ".but2" ,it did not hide by "aa".
Post 12 Sep 2009, 12:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 12 Sep 2009, 12:54
fasm only reports one error at a time. The first error encountered was the one it showed.
Post 12 Sep 2009, 12:54
View user's profile Send private message Visit poster's website Reply with quote
6a00



Joined: 11 Sep 2009
Posts: 5
6a00 12 Sep 2009, 13:03
Sorry sorry i did not thought good and asked that.
Post 12 Sep 2009, 13:03
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.