The MASM Forum

General => The Campus => Topic started by: peter_asm on August 19, 2014, 06:17:37 AM

Title: Macro for displaying values
Post by: peter_asm on August 19, 2014, 06:17:37 AM
Let's say I wanted to print size of code between 1 label and another while the assembler was generating object code, is this possible using a macro?
Like, I wanted length of code between label_A and label_B


%out Size of code is (label_B - label_A)

label_A:
  xor eax, eax
  ret
label_B:


Then when i assemble, it would display.

Size of code is 3

[edit] nevermind, found way using @CatStr
Title: Re: Macro for displaying values
Post by: jj2007 on August 19, 2014, 06:36:41 AM
include \masm32\include\masm32rt.inc

CodeSize MACRO algo      ; adapted from MasmBasic (http://masm32.com/board/index.php?topic=94.0)
  pushad
  mov eax, offset &algo&_endp
  sub eax, offset &algo&_s
  print str$(eax), " bytes for &algo&", 13, 10
  popad
ENDM

.code
start:
  xx_s:         ; start label
  xor eax, eax
  xx_endp:      ; end label
  CodeSize xx
  exit
end start
Title: Re: Macro for displaying values
Post by: qWord on August 19, 2014, 07:09:54 AM
Quote from: peter_asm on August 19, 2014, 06:17:37 AM[edit] nevermind, found way using @CatStr
Be warned,  MASM does (AFAIK) only show correct result for something like @CatStr(%lbl2-lbl1) as long as no forward reference occurs in the range [lbl1,lbl2).