News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Is this possible?

Started by LordAdef, December 11, 2020, 09:48:18 AM

Previous topic - Next topic

LordAdef

Hello everyone!
I had this idea and was wondering if this could be done, or implemented.I find this quite useful for error checking but still preserving code readability.
Say:
invoke foo 12, 12, 12
-- check error
invoke foo2 22, 12, 12
-- check error
invoke foo3 12, 12, 12
-- check error
invoke foo4 12, 12, 12
-- check error


Now assume I have a macro (called errorCheck) to check the return error code. It would be cleaner to leave the error code macro in the same line:
invoke foo  12, 12, 12     @errorCheck
invoke foo2 22, 12, 12     @errorCheck
invoke foo3 12, 12, 12     @errorCheck
invoke foo4 12, 12, 12     @errorCheck

It's very not "asmy", but it would be a cool feature and easy to implement
Can that be done?
Thanks in advance for the replies

jj2007

Hello Alex,

Here is an undocumented bit from MasmBasic.inc:
invnzLine=0
include \masm32\MasmBasic\MasmBasic.inc ; download
invnz macro mainarg, args:VARARG
Local tmp$, inzLine
  ifb <args>
call mainarg
  else
invoke mainarg, args
  endif
  if usedeb eq 77
.if !eax
INT 3
mov ebp, ebp
.endif
  elseif usedeb
.if !eax
pushad
inzLine=@Line-invnzLine
tmp$ CATSTR <" ** invnz, line >, %inzLine, <: &mainarg failed: ">
% PrintLine tmp$, Err$()
popad
.endif
  endif
ENDM
  Init
  invnz GetCaretPos, 0
EndOfCode


Output:
** invnz, line 25: GetCaretPos failed: Accesso a posizione di memoria non valido.

For usedeb=0, no extra code will be generated, it behaves exactly like a normal invoke GetCaretPos, 0
If you put usedeb=77 before invnz GetCaretPos, 0, it will crash into the just-in-time debugger (mine is Olly), and the first instruction you see is mov ebp, ebp

A more sophisticated macro is gdi+ as e.g. in gdi+ GdipCreateFromHDC, PtDC, addr APs.apGdiDC. Look for gdiSaveEcx in MasmBasic.inc :cool:

LordAdef

Nice Johen!
But my idea would be whatever macro you want after the "@" (or something else), in the same line in the asm file
At building time, the thing would be parsed back to the line below. Basically, adding an "\n" before the macro

I am following the development of this new language, and the developer is using this for for preprocessor compiler things. I found this idea quite usefel for us, too.
UASM is known for doing some cool stuff. This one would be interesting...

HSE

Hi Alex!

Something like this must work:
InvokeCheck macro checking, parameters:VARARG
    invoke <parameters>
    &checking
endm

Usage:
@errorCheckOne macro k1
  ...
endm
  etc

InvokeCheck <@errorCheckOne esk1>, foo, 12, 12, 12
InvokeCheck <@errorCheckTwo>, foo2,  12, 12
InvokeCheck <@errorCheck>, foo3,  12, 12, 12, 32


Regards. HSE
Equations in Assembly: SmplMath

jj2007

Quote from: LordAdef on December 11, 2020, 10:36:01 AM
But my idea would be whatever macro you want after the "@" (or something else), in the same line in the asm file
At building time, the thing would be parsed back to the line below. Basically, adding an "\n" before the macro

Sorry, Alex, I don't understand - can you post an example?

morgot

Can UASM mix 32 bit and 64 bit both code (such as Fasm / Yasm) ?
Without pre-processor, in one file, as example:


use64

    push rbp
    mov rbp, rsp
...
use32
push ebp
mov ebp,esp
Sorry for the bad English

DebugBSD

Quote from: morgot on December 16, 2020, 12:54:41 PM
Can UASM mix 32 bit and 64 bit both code (such as Fasm / Yasm) ?
Without pre-processor, in one file, as example:


use64

    push rbp
    mov rbp, rsp
...
use32
push ebp
mov ebp,esp


Hi morgot,

UASM64 let you mix code from both 32 and 64 bit. Look at the PDF document which comes with your UASM instalation (See Section 6 - Page 23 - Option FLAT).

Please, next time post your question in a different thread :)
Happy Hacking!

LordAdef

QuoteSorry, Alex, I don't understand - can you post an example?


Sorry JJ, I complicated something that's easy:


Basically, I wanted to write 2 lines of code in 1:


mov eax, 100     @mov ebx, 3 ; this is bizarre but it would work
Invoke somethin   @someMacroHere

This is equal to this, when parsed by uasm:


mov eax, 100   
mov ebx, 3
Invoke somethin   
SomeMacroHere



Surely I could write a proggy to insert a \n, and readjust the code. But this is not practical.


I think the good usage would be for macros to be inserted.




HSE

Quote from: LordAdef on December 18, 2020, 06:19:49 AM
mov eax, 100     @mov ebx, 3 ; this is bizarre but it would work
Invoke somethin   @someMacroHere

bizarre macro line1, line2
   &line1
   &line2
endm

bizarre < mov eax, 100 >,< mov ebx, 3 >
bizarre < Invoke somethin >,< someMacroHere >

:biggrin: 

Of course you can make UASM read " @ " (with spaces or tabs) like end of line. But you have to make more modifications because "@" is a valid symbol frequently used:comment @
bizarre <mov ecx, 100>,<someMacroHere>
@
Equations in Assembly: SmplMath

jj2007

Like this? Good ol' BASIC syntax using ":" as a separator? That is what mcs does (but I never use it):

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  mcs mov eax, 1 : mov ebx, 12 : m2m ecx, 123 : mov edx, 1234 : deb 4, "test", eax, ebx, ecx, edx
EndOfCode


test
eax             1
ebx             12
ecx             123
edx             1234


Your version cannot work, because such a line must start with a macro:
Quotemov eax, 100     @mov ebx, 3 ; this is bizarre but it would work

What you could do, however, is insert a preprocessor before the assembly step. As HSE rightly noted, @ is not a good delimiter but # could do the trick :cool:

Anyway, just for fun I have hacked together an example using _# as a delimiter:

include \masm32\MasmBasic\MasmBasic.inc
  Init

  ; method A: use the mcs macro
  mcs mov eax, 1 : mov ebx, 12 : m2m ecx, 123 : mov edx, 1234 : deb 4, "test A", eax, ebx, ecx, edx

  ; method B: use a delimiter and a preprocessor
  mov eax, 1 _# mov ebx, 11 _# m2m ecx, 111 _# mov edx, 1111 _# deb 4, "test B", eax, ebx, ecx, edx

EndOfCode


See attachment, to be used with RichMasm.

HSE

Quote from: jj2007 on December 18, 2020, 08:32:17 AM
  mcs mov eax, 1 : mov ebx, 12 : m2m ecx, 123 : mov edx, 1234 : deb 4, "test", eax, ebx, ecx, edx

Very nice JJ  :thumbsup:

I have a little problem with sintax:mcs mov eax, 1 : <assume ebx: nothing> : mov ebx, 12 : m2m ecx, 123 : mov edx, 1234
 
Equations in Assembly: SmplMath

LordAdef

Quote; method B: use a delimiter and a preprocessor
  mov eax, 1 _# mov ebx, 11 _# m2m ecx, 111 _# mov edx, 1111 _# deb 4, "test B", eax, ebx, ecx, edx


Quote
Of course you can make UASM read " @ " (with spaces or tabs) like end of line. But you have to make more modifications because "@" is a valid symbol frequently used:


Hi guys!!

This is exactly what I want!!! I use "@" only as an example, it could be anything.

QuoteOf course you can make UASM read " @ " (with spaces or tabs) like end of line

I have no ideia how to make UASM do that


I see MANY very good reasons to have this at hand. Mainly for debugging, profiling, error checkings and quick tests.

HSE

Quote from: LordAdef on December 18, 2020, 09:04:51 AM
QuoteOf course you can make UASM read " @ " (with spaces or tabs) like end of line
I have no ideia how to make UASM do that
You only have to rewrite UASM source code and compile it.  :biggrin:

More easy are JJ's ideas, I think.  :thumbsup:
Equations in Assembly: SmplMath

LordAdef

Quote from: HSE on December 18, 2020, 09:20:00 AM
Quote from: LordAdef on December 18, 2020, 09:04:51 AM
QuoteOf course you can make UASM read " @ " (with spaces or tabs) like end of line
I have no ideia how to make UASM do that
You only have to rewrite UASM source code and compile it.  :biggrin:

More easy are JJ's ideas, I think.  :thumbsup:
hahahahahahahah I see!! I imagine so, but the way you said it I thought there was already a way to do it. My bad!
JJ's idea is really nice, but the pre processor one preserves the code as is, which is my main idea. I might write a preprocessor proggy to test the concept.

jj2007

Quote from: HSE on December 18, 2020, 08:50:57 AMI have a little problem with sintax:mcs mov eax, 1 : <assume ebx: nothing> : mov ebx, 12 : m2m ecx, 123 : mov edx, 1234
 

You are too ambitious, HSE :biggrin:

assume ebx: nothing

Quote from: LordAdef on December 18, 2020, 09:27:13 AMI might write a preprocessor proggy to test the concept.

You can test it with the preprocessor included above. It's multi.exe :cool: