The MASM Forum

General => The Campus => Topic started by: xandaz on December 03, 2020, 03:21:55 AM

Title: easy for experts...
Post by: xandaz on December 03, 2020, 03:21:55 AM
    I'm used to convert both memory reigsters to hex and binary but when it comes to decimal things become a little more dificult. Can someone land a hand? Thanks
Title: Re: easy for experts...
Post by: jj2007 on December 03, 2020, 03:43:19 AM
str$()?
Title: Re: easy for experts...
Post by: xandaz on December 03, 2020, 03:53:20 AM
   sorry for this but i'm not used to use macros that much. would it be something like this?
invoke SetWindowText,hStatic,WM_SETTEXT,0, str$(eax)

   is this the way you do it? Thanks
Title: Re: easy for experts...
Post by: xandaz on December 03, 2020, 04:02:41 AM
   it gives error can't find  crt__itow. what the hell i'm i doing wrong?
Title: Re: easy for experts...
Post by: jj2007 on December 03, 2020, 05:03:27 AM
Instead of numerous include statements, use only one:

include \masm32\include\masm32rt.inc

.data
HelloW$ db "Hello World", 0

.code
start:
  print str$(eax), " is the current value of eax"
  exit

end start


Have a look at masm32rt.inc, it's a very interesting file.
Title: Re: easy for experts...
Post by: TimoVJL on December 03, 2020, 05:06:45 AM
Check SetDlgItemInt() function.
BOOL WINAPI SetDlgItemInt(
  _In_  HWND hDlg,
  _In_  int nIDDlgItem,
  _In_  UINT uValue,
  _In_  BOOL bSigned
);

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setdlgitemint
Title: Re: easy for experts...
Post by: Vortex on December 03, 2020, 05:16:08 AM
wsprintf example :

.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include     \masm32\include\masm32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\masm32.lib

.data

format1     db '%u',0

.data?

buffer      db 32 dup(?)

.code

start:

    mov     eax,1234

    invoke  wsprintf,ADDR buffer,ADDR format1,eax
    invoke  StdOut,ADDR buffer

    invoke  ExitProcess,0

END start
Title: Re: easy for experts...
Post by: avcaballero on December 03, 2020, 06:35:12 AM
Two examples I made long ago. The first one is quite simple and write down a unsigned word number, from 65535 to 1, the second one writes signed numbers from -65535 to 65534, a bit more elaborated but easy too. First one with fasm sintax, the second with nasm. Both in DOS format.
Title: Re: easy for experts...
Post by: hutch-- on December 03, 2020, 06:49:02 AM
xandaz,

Include the following line AFTER all of the include files and get the functionality of all of the macros.

      include \masm32\macros\macros.asm         ; masm32 macro file

Title: Re: easy for experts...
Post by: jj2007 on December 03, 2020, 08:04:08 AM
Quote from: jj2007 on December 03, 2020, 05:03:27 AM
Instead of numerous include statements, use only one:

include \masm32\include\masm32rt.in

That includes even macros.asm :cool:

(it slows down assembly to have so many includes included; on my Core i5 by about 0.05 seconds)
Title: Re: easy for experts...
Post by: xandaz on December 03, 2020, 08:30:27 AM
   Thanks very much guys. You've been exceedingly helpful. I'll bare that in my heart.  :thumbsup:
Title: Re: easy for experts...
Post by: Vortex on December 03, 2020, 07:10:41 PM
dwtoa from masm32.lib :


Quotedwtoa proc public uses esi edi dwValue:DWORD, lpBuffer:DWORD

Description

dwtoa convert a DWORD value to an ascii string.

Parameters

1. dwValue The DWORD value to convert.
2. lpBuffer The address of the buffer to put the converted DWORD into.

Return Value

There is no return value.

Comments

The buffer for the converted value should be large enough to hold the string including the terminating zero.
Title: Re: easy for experts...
Post by: jj2007 on December 03, 2020, 09:10:45 PM
Quote from: Vortex on December 03, 2020, 07:10:41 PM
dwtoa from masm32.lib :

\masm32\macros\macros.asm (included with masm32rt.inc):

    str$ MACRO DDvalue
      LOCAL rvstring
      .data
        rvstring db 20 dup (0)
        align 4
      .code
      invoke dwtoa,DDvalue,ADDR rvstring
      EXITM <ADDR rvstring>
    ENDM
Title: Re: easy for experts...
Post by: xandaz on December 03, 2020, 10:01:06 PM
   Thanks y'all.  :thumbsup:
Title: Re: easy for experts...
Post by: xandaz on December 03, 2020, 11:35:40 PM
   Hi there. I was wondering what macro should i use with str$() to add the word line in the precedence of of the line number. thanks in advance  :thumbsup:
Title: Re: easy for experts...
Post by: jj2007 on December 04, 2020, 01:11:54 AM
Which "word line"? Post an example.
Title: Re: easy for experts...
Post by: xandaz on December 04, 2020, 01:20:52 AM
   It goes like this:
   .if uMsg==WM_CHAR || uMsg==WM_MOUSEMOVE
        invoke  SendMessage,hWnd,EM_LINEINDEX,-1,0
        invoke  SendMessage,hWnd,EM_LINEFROMCHAR,eax,0
        inc     eax
        push    eax
        invoke  SendMessage,hMdi,WM_MDIGETACTIVE,0,0
        invoke  GetWindowLong,eax,GWL_USERDATA
        mov     edi,eax
        invoke  SendMessage,[edi.MdiStruct.hStatic],WM_SETTEXT,0,addr szEmptyString
        pop     eax
        invoke  SendMessage,[edi.MdiStruct.hStatic],WM_SETTEXT,0,ustr$(eax)

    Just wanted to add the word 'line' to the line number as in WM_SETTEXT,0,ustr$(eax)
Title: Re: easy for experts...
Post by: hutch-- on December 04, 2020, 03:06:53 AM
Allocate a buffer that is large enough to hold all of the string data you have in mind then use either "cat$()" or the macro "strcat" to join the strings. You will find this data in the help file on the menu "High Level Macro Help". There is a ton of stuff there that you will find really useful.
Title: Re: easy for experts...
Post by: xandaz on December 04, 2020, 03:12:01 AM
  yeah Hutch...thanks for the help i've been trying  WM_SETTEXT,0,cat$(offsset szLine,ustr$(eax)) but it crashes.
Title: Re: easy for experts...
Post by: hutch-- on December 04, 2020, 03:19:25 AM
Try constructing the string separately then show it in a MessageBox().
Title: Re: easy for experts...
Post by: xandaz on December 04, 2020, 03:23:07 AM
   ok...i'll try that.
Title: Re: easy for experts...
Post by: xandaz on December 04, 2020, 03:51:22 AM
   The macro works fine. the problem is that i'm using cat$(offset Buffer,"ln ",ustr$(eax)) and although i've attentiveally set the first character of Buffer to 0 it keeps adding to the string.
Title: Re: easy for experts...
Post by: xandaz on December 04, 2020, 04:39:13 AM
    working perfectlly. Thanks a lot
Title: Re: easy for experts...
Post by: jj2007 on December 04, 2020, 04:44:44 AM
Quote from: xandaz on December 04, 2020, 03:12:01 AM
  yeah Hutch...thanks for the help i've been trying  WM_SETTEXT,0,cat$(offsset szLine,ustr$(eax)) but it crashes.


First arg is the destination buffer, x$ in this example:
  Local x$[100]:BYTE
  mov ecx, 123
  print cat$(addr x$, "Line ", str$(ecx))


In MasmBasic you could use invoke SendMessage,[edi.MdiStruct.hStatic],WM_SETTEXT,0, Str$("Line %i", eax)
Title: Re: easy for experts...
Post by: xandaz on December 04, 2020, 04:46:50 AM
   yeah thanks JJ. î got it working thanks to you guys but i have to confess it's kinda slow.