flat assembler
Message board for the users of flat assembler.

Index > Windows > Please help to see why this code compiler error?

Author
Thread Post new topic Reply to topic
MR.Z



Joined: 12 Mar 2025
Posts: 18
MR.Z 17 Mar 2025, 13:09
The fasm program generated by AI in windows10 environment pops up a confirmation box, but why the prompt "push MB_YESNOCANCEL|MB_ICONQUESTION" when compiling is wrong? The full code is as follows:
format PE console
entry main

include 'win32a.inc'

section '.data' data readable writable
msg db 'Do you want to continue?', 0
caption db 'Confirmation', 0

section '.text' code readable executable
main:
; 初始化数据段
mov eax, [esp+4] ; 获取命令行参数的起始地址(我们不需要,但保持堆栈平衡)
and esp, 0FFFFFFF0h ; 16字节对齐堆栈
call __main_startup ; FASM 启动代码,初始化数据段等

; 调用 MessageBoxA 函数
push MB_YESNOCANCEL|MB_ICONQUESTION ; uType
push caption ; lpCaption
push msg ; lpText
push 0 ; hWnd
call [MessageBoxA]

; 检查返回值
test eax, eax
jz exit_no

; 用户点击了“是”或“确定”
push msgbox_yes
call [printf]
add esp, 4

jmp exit

exit_no:
; 用户点击了“否”或“取消”
push msgbox_no
call [printf]
add esp, 4

exit:
; 退出程序
push 0
call [ExitProcess]

section '.idata' import data readable
library user32, 'user32.dll', kernel32, 'kernel32.dll'

import user32, \
MessageBoxA, 'MessageBoxA'

import kernel32, \
ExitProcess, 'ExitProcess', \
__main_startup, '__mainCRTStartup' ; FASM 启动代码和 C 运行时启动代码(可选)

section '.bss' resb 1

msgbox_yes db 'User clicked Yes or OK!', 13, 10, 0
msgbox_no db 'User clicked No or Cancel!', 13, 10, 0
Post 17 Mar 2025, 13:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20632
Location: In your JS exploiting you and your system
revolution 17 Mar 2025, 13:22
fasm uses or for numerical bitwise ORing.

fasm uses | for logical ORing.

push expects a numerical value and doesn't accept logical values.

Therefore use:
Code:
push MB_YESNOCANCEL or MB_ICONQUESTION     
Post 17 Mar 2025, 13:22
View user's profile Send private message Visit poster's website Reply with quote
MR.Z



Joined: 12 Mar 2025
Posts: 18
MR.Z 17 Mar 2025, 14:09
revolution wrote:
fasm uses or for numerical bitwise ORing.

fasm uses | for logical ORing.

push expects a numerical value and doesn't accept logical values.

Therefore use:
Code:
push MB_YESNOCANCEL or MB_ICONQUESTION     


You're so amazing! How did you know that?
Post 17 Mar 2025, 14:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20632
Location: In your JS exploiting you and your system
revolution 17 Mar 2025, 23:08
MR.Z wrote:
How did you know that?
Because I am not an "AI".
Post 17 Mar 2025, 23:08
View user's profile Send private message Visit poster's website Reply with quote
MR.Z



Joined: 12 Mar 2025
Posts: 18
MR.Z 18 Mar 2025, 00:39
revolution wrote:
MR.Z wrote:
How did you know that?
Because I am not an "AI".

Wow, relying on AI learning is still relatively easy to mislead.
Post 18 Mar 2025, 00:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20632
Location: In your JS exploiting you and your system
revolution 18 Mar 2025, 00:51
"AI" isn't about precision, it is about generalisation.

Programming requires precision.
Post 18 Mar 2025, 00:51
View user's profile Send private message Visit poster's website Reply with quote
MR.Z



Joined: 12 Mar 2025
Posts: 18
MR.Z 18 Mar 2025, 01:03
revolution wrote:
"AI" isn't about precision, it is about generalisation.

Programming requires precision.

So how do I learn fasm? I don't want to waste your time because of a small problem.
Post 18 Mar 2025, 01:03
View user's profile Send private message Reply with quote
Mat-Quasar



Joined: 02 Mar 2025
Posts: 82
Mat-Quasar 18 Mar 2025, 06:35
MR.Z wrote:

So how do I learn fasm?


As suggested by bzt in reply to your thread ( https://board.flatassembler.net/topic.php?p=243066#243066 ), you can read FASM documentation.

If you have downloaded flat assembler for Windows, you can find FASM.pdf in the unzipped folder.

I suggest you read the following section:
Quote:
1.2 Assembly syntax

Chapter 2 Instruction set
2.1 The x86 architecture instructions
2.1.1 Data movement instructions
2.1.2 Type conversion instructions
2.1.3 Binary arithmetic instructions
2.1.4 Decimal arithmetic instructions
2.1.5 Logical instructions
2.1.6 Control transfer instructions
2.1.8 Strings operations
2.1.10 Conditional operations
2.1.11 Miscellaneous instructions


2.4 Formatter directives
2.4.1 MZ executable
2.4.2 Portable Executable
2.4.4 Executable and Linkable Format

Chapter 3 Windows programming


Assembly programming is all about (1) CPU instruction (see Chapter 2), (2) OS library call (see Chapter 3) and (3) Binary file format (see Section 2.4).

You can start with a simple "Hello, world!" program first.

All the best in your learning journey!
Post 18 Mar 2025, 06:35
View user's profile Send private message Reply with quote
MR.Z



Joined: 12 Mar 2025
Posts: 18
MR.Z 18 Mar 2025, 08:59
Mat-Quasar wrote:
MR.Z wrote:

So how do I learn fasm?


As suggested by bzt in reply to your thread ( https://board.flatassembler.net/topic.php?p=243066#243066 ), you can read FASM documentation.

If you have downloaded flat assembler for Windows, you can find FASM.pdf in the unzipped folder.

I suggest you read the following section:
Quote:
1.2 Assembly syntax

Chapter 2 Instruction set
2.1 The x86 architecture instructions
2.1.1 Data movement instructions
2.1.2 Type conversion instructions
2.1.3 Binary arithmetic instructions
2.1.4 Decimal arithmetic instructions
2.1.5 Logical instructions
2.1.6 Control transfer instructions
2.1.8 Strings operations
2.1.10 Conditional operations
2.1.11 Miscellaneous instructions


2.4 Formatter directives
2.4.1 MZ executable
2.4.2 Portable Executable
2.4.4 Executable and Linkable Format

Chapter 3 Windows programming


Assembly programming is all about (1) CPU instruction (see Chapter 2), (2) OS library call (see Chapter 3) and (3) Binary file format (see Section 2.4).

You can start with a simple "Hello, world!" program first.

All the best in your learning journey!


Great, finally you don't have to read the entire fasm document all over again, you can look at the required knowledge, thank you for your answers and blessings!
Post 18 Mar 2025, 08:59
View user's profile Send private message Reply with quote
Mat-Quasar



Joined: 02 Mar 2025
Posts: 82
Mat-Quasar 18 Mar 2025, 09:09
兄弟,加油!懂得读些英文文档是大有帮助的。

(我不是中国人)
Post 18 Mar 2025, 09:09
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.