flat assembler
Message board for the users of flat assembler.

Index > Windows > window console add two number with MMX.

Author
Thread Post new topic Reply to topic
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 26 Dec 2022, 19:28
The console start and crashed.
This is my working source code, any help?
Code:
format PE GUI 4.0
entry start
include 'INCLUDE/WIN32AX.INC'
section '.data' data readable writeable
  consoleTitle db 'Add two numbers using MMX ',0
  offset dd ?
  hConOut dd ?
  FOREGROUND_GREEN dd 10
  FOREGROUND_INTENSITY dd 10
  addr dd ?
  n dd ?
  sizeof.output dd 256  ; I don't find a sizeof for output
  sizeof.prompt dd 256  ; I don't find a sizeof for output
  num1 dd 1
  num2 dd 2
  result dd ?
  prompt db 'Enter two numbers to add:',0
  fo db 'The result is: %d',0   ; format ??
  output db 16 dup (0)

section '.code' code readable executable
  start:
    ; Initialize the console
    invoke AllocConsole
    invoke GetStdHandle, STD_OUTPUT_HANDLE
    mov [hConOut], eax
    invoke SetConsoleTitle, offset consoleTitle
    invoke SetConsoleTextAttribute, [hConOut], FOREGROUND_GREEN or FOREGROUND_INTENSITY
    invoke WriteConsole, [hConOut], offset prompt, sizeof.prompt, addr n, 0

    ; Read the two numbers from the console
    invoke ReadConsole, [hConOut], addr num1, 4, addr n, 0
    invoke ReadConsole, [hConOut], addr num2, 4, addr n, 0

    ; Add the two numbers with MMX
    movd mm0, [num1]
    movd mm1, [num2]
    paddw mm0, mm1
    movd [result], mm0
    emms

    ; Print the result to the console
    invoke wsprintf, offset output, offset fo, [result]
    invoke WriteConsole, [hConOut], offset output, sizeof.output, addr n, 0
    invoke Sleep, 2000
    invoke FreeConsole
    ret

section         '.idata' import data readable writeable
 
library         kernel32,'KERNEL32.DLL',user32,'USER32.DLL',gdi32,'GDI32.DLL'
 
include         'INCLUDE/API/KERNEL32.INC'
include         'INCLUDE/API/USER32.INC'
include         'INCLUDE/API/GDI32.INC'         
Post 26 Dec 2022, 19:28
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1850
Roman 26 Dec 2022, 19:32
Try:
mov eax, [num1]
add eax, [num2]

mov [result], eax

What is this ?
offset output ?

invoke wsprintf, output, fo, [result]
invoke WriteConsole, [hConOut], output, sizeof.output, addr n, 0
Post 26 Dec 2022, 19:32
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 794
Location: Adelaide
sinsi 26 Dec 2022, 20:05
I don't use the macros, but wsprintf is C calling convention, not stdcall, so shouldn't you use cinvoke?
Post 26 Dec 2022, 20:05
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1850
Roman 26 Dec 2022, 20:36
Yes. cinvoke wsprintf, output, fo, [result]
Post 26 Dec 2022, 20:36
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1671
Location: Toronto, Canada
AsmGuru62 27 Dec 2022, 02:28
So... not using OLLYDBG?
Why not?
You would instantly know which line of the code causes a crash.
It is just guessing otherwise.
Post 27 Dec 2022, 02:28
View user's profile Send private message Send e-mail Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 27 Dec 2022, 12:25
The source code in this output shown here is after several hours of testing OpenAI to see if it outputs working source code and even includes other C libraries, I think it is not trained enough to output working source code.

I didn't really have time to work with FASM, but I saw that they also launched fasmg. My assembly knowledge is somewhat limited and I have a few FASM gaps. I haven't really worked with ollydbg, I don't really find good tutorials, just what comes out of assembly programming.

But because I spent time, I wanted to have a working source code and that's why I asked here, and if you have tutorials related to ollydbg or ResourceHacker software to work with res or rc files, it would be great to add them here or in - a special learning post.


Thanks for the replies and I try to solve this source code ... Happy holidays to all developers.
Post 27 Dec 2022, 12:25
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 27 Dec 2022, 12:35
catafest wrote:
But because I spent time, I wanted to have a working source code and that's why I asked here, and if you have tutorials related to ollydbg or ResourceHacker software to work with res or rc files, it would be great to add them here or in - a special learning post.[/i]
I used OllyDbg in my video tutorials, perhaps they might be of some help.
Post 27 Dec 2022, 12:35
View user's profile Send private message Visit poster's website Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 27 Dec 2022, 13:03
Tomasz Grysztar wrote:
catafest wrote:
But because I spent time, I wanted to have a working source code and that's why I asked here, and if you have tutorials related to ollydbg or ResourceHacker software to work with res or rc files, it would be great to add them here or in - a special learning post.[/i]
I used OllyDbg in my video tutorials, perhaps they might be of some help.

Thank you.
Post 27 Dec 2022, 13:03
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1850
Roman 27 Dec 2022, 19:06
catafest wrote:
The source code in this output shown here is after several hours of testing OpenAI to see if it outputs working source code and even includes other C libraries, I think it is not trained enough to output working source code.

Hm OpenAI .
You using chatGP for generated asm code ?
Show video how you do this.
Post 27 Dec 2022, 19:06
View user's profile Send private message Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 27 Dec 2022, 21:15
Just I start asking and tested the result, when I got an error I ask to fix it, most of the responses were based on the FASM documentation and some part of the source code refer to c programming language. For example:

fix error in your source code error: undefined symbol 'FOREGROUND_GREEN'.


To fix the "undefined symbol" error caused by the FOREGROUND_GREEN symbol in your code, you can follow these steps:

Make sure that the FOREGROUND_GREEN symbol is defined in the include file or the library file that is being used by your program. The FOREGROUND_GREEN symbol is a constant that is used to specify the foreground color of the console output, and it is defined in the wincon.h include file. You can include the wincon.h file in your program by using the include directive, as follows:
Copy code
include 'wincon.h'
Post 27 Dec 2022, 21:15
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1850
Roman 27 Dec 2022, 21:31
Try
FOREGROUND_GREEN = 10
FOREGROUND_INTENSITY = 10

Code:
;and remove all offset
invoke SetConsoleTitle,  consoleTitle
invoke SetConsoleTextAttribute, [hConOut], 10+10
    
    
Post 27 Dec 2022, 21:31
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1850
Roman 28 Dec 2022, 12:41
My variant work fine. And i get 'The result is: 17'
Code:
format PE GUI 4.0
entry Start
include 'INCLUDE/WIN32AX.INC'
SECTION '.data' DATA READABLE WRITEABLE executable
        consoleTitle db 'Add two numbers using MMX ',0
  ;offset dd ?
  hConOut dd ?
  FOREGROUND_GREEN = 10
  FOREGROUND_INTENSITY = 10
  addr dd ?
  n dd ?
  sizeof.output = 256  ; I don't find a sizeof for output
  sizeof.prompt = 256  ; I don't find a sizeof for output
  num1 dd 15
  num2 dd 2
  result dd ?
  prompt db 'Enter two numbers to add:',0
  fo db 'The result is: %d',0   ; format ??
  output db 16 dup (0)


section '.code' code readable writeable executable

Start:
    invoke AllocConsole
    invoke GetStdHandle, STD_OUTPUT_HANDLE
    mov [hConOut], eax
    invoke SetConsoleTitle,  consoleTitle
    invoke SetConsoleTextAttribute, [hConOut], FOREGROUND_GREEN or FOREGROUND_INTENSITY
    invoke WriteConsole, [hConOut],  prompt, sizeof.prompt, addr n, 0

    ; Read the two numbers from the console
    invoke ReadConsole, [hConOut], addr num1, 4, addr n, 0
    invoke ReadConsole, [hConOut], addr num2, 4, addr n, 0

    ; Add the two numbers with MMX
    movd mm0, [num1]
    movd mm1, [num2]
    paddw mm0, mm1
    movd [result], mm0
    emms

    ; Print the result to the console
    cinvoke wsprintf,  output,  fo, [result]
    invoke WriteConsole, [hConOut],  output, sizeof.output, addr n, 0
    invoke Sleep, 2000
    invoke FreeConsole

    invoke MessageBox,0,'Done ! Exit',0,0

    invoke ExitProcess,0  
    
Post 28 Dec 2022, 12:41
View user's profile Send private message Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 21 Jan 2023, 11:57
thank you @Roman
... good to know, I see the errors versus my default example ...
Post 21 Jan 2023, 11:57
View user's profile Send private message Visit poster's website Yahoo Messenger 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.