unable to jmp to address within one macro from another macro

Started by jimg, March 27, 2018, 03:33:21 AM

Previous topic - Next topic

jimg

Was that subject description confusing enough?

I was cleaning up some old jwasm stuff, and I found this test from four years ago.  I don't know if I ever submitted this problem or not, but things have progressed enough that you might want to look at this some time.  Obviously there's not a big rush for this.

This is a situation I have in my program I use to test execution time for chunks of code.
Basically, the macro is in two parts.  Part1 sets up some stuff, and then sets an address to loop back to for repeated testing.  Then the test code.  Then Part2 macro which does some more stuff and loops back to do the whole process over again.  Anyway, its like this-

Part1 macro
code to be timed
Part2 macro

It works perfectly in masm, but goes into an endless loop in uasm.  I have therefore not included the exe from usam, but did include the exe from masm in the attached file.

To show the problem, this is a simplified version that just copys some characters to a buffer in the three parts to see what's going on.

.686
.model Flat, Stdcall
option Casemap :None   
.nolist
include windows.inc
uselib  MACRO   libname
    include     libname.inc
    includelib  libname.lib
ENDM
uselib user32
uselib kernel32
.list

part1 macro
    mov al,"0"
    stosb
TimingLoop = $
    mov al,"2"
    stosb
endm

part2 macro
    mov al,"3"
    stosb
    mov al,"4"
    stosb
    sub Loops,1
    jnz TimingLoop
endm

.data?
Loops         dd ?
ResultBuffer  db 1000 dup (?)
.code
program:

    mov Loops,4
    lea edi,ResultBuffer
   
    part1

    mov al,"X"  ; the test code
    stosb
   
    part2
   
    mov al,0
    stosb
   
    invoke MessageBox,0,addr ResultBuffer,0,0   

    ; ****  result should be 02X342X342X34
    ret

end program


As the code says, the result should be a messagebox displaying "02X342X342X34"

Again, I can understand why this would not be high on your priority list, but I think it is probably something that should be addressed.

jj2007

That is indeed a somewhat exotic problem. There are two workarounds, though:
TimingLoop = $
TimingLoop equ $
TimingLoop:

jimg

Correct.  In this context,  using "=" or using "equ" should be equivalent.  Both resolve to an address.

looking at the listing for each, the jnz address is wrong in the "=" example.
The correct one jumps back 21, the incorrect one jumps back 2.