News:

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

Main Menu

Macro for displaying values

Started by peter_asm, August 19, 2014, 06:17:37 AM

Previous topic - Next topic

peter_asm

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

jj2007

include \masm32\include\masm32rt.inc

CodeSize MACRO algo      ; adapted from MasmBasic
  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

qWord

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).
MREAL macros - when you need floating point arithmetic while assembling!