News:

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

Main Menu

Dead Code

Started by Biterider, January 07, 2023, 08:12:55 PM

Previous topic - Next topic

Biterider

Hi John
I was wondering if there is a way to remove dead code from a simple asm file, perhaps using one of the UASM features when it analyzes the code on the various passes.
I am fully aware that a solution is to build a library, but I am currently interested in plain files.
Example:

C1 = 0
C2 = 0

Code1 proto
Code2 proto

.code

start proc
  C1 = 1
  invoke Code1

  invoke ExitProcess, 0
start endp

if C1 eq 1
Code1 proc
  echo Code1
  C2 = 1
  invoke Code2
  add eax, eax
  ret
Code1 endp
endif

if C2 eq 1
Code2 proc
  echo Code2
  sub eax, eax
  ret
Code2 endp
endif

end

This can work, but it is ugly and error prone :sad:
You just have to change the code and it doesn't work anymore...

Biterider

johnsa

It's not impossible, but it would be a very large development effort to replicate what you're doing with the equates there. Tracking within a single file might not be the whole picture, if the proc is extern or used after linking. Some code may not be under a proper PROC directive either. I think this sort of feature would be best as a linker/post-linker step to remove unreachable/dead code rather than doing it at assemble/pass time where it may be quite error prone. The equate option seems ok to me, and you'd see similar used in C/C++.

jj2007

Quote from: Biterider on January 07, 2023, 08:12:55 PM
This can work, but it is ugly and error prone :sad:

I use such constructs all the time and am quite happy with it. Indeed, I have a shortcut: if I type if1<space> in my editor, it inserts
if 1
x
else
endif


It shouldn't be too difficult to write a plugin for QEditor that checks if SomeAlgo proc gets invoked or called in the source. If somebody provides me a big enough source (>5000 lines) that assembles in a standard Masm32 SDK setting and has dead code, I volunteer to write that plugin.

I doubt it's a real problem, though. Even in the 25k lines of my editor's source, there is probably not a single really unused byte. And I assume most of us know what they are doing. It's a different story, of course, if you use large third party libraries...

Biterider

Hi Johnsa , JJ
Thanks for the replies.
Plan "B" is something similar to what JJ had in mind, a preprocessor that sets the inclusion flags.
As Johnsa said, there are many considerations to take before disabling a code block....  :rolleyes:

Biterider

HSE

Hi

Quote from: Biterider on January 10, 2023, 12:53:41 AM
a preprocessor that sets the inclusion flags.

The hard part is to know how macros are expanded. Nidud translated that part of AsmC to assembly. I presume that must be same as UASM.

Some years ago I have an "out of order line" problem, but found the line before assembly AsmC source code was ready  :biggrin:

HSE
Equations in Assembly: SmplMath