Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

Do not use the blue keys on this terminal.


programming / alt.lang.asm / MASM nested function

SubjectAuthor
o MASM nested functionT. Ment

1
Subject: MASM nested function
From: T. Ment
Newsgroups: alt.lang.asm
Organization: A noiseless patient Spider
Date: Fri, 7 Aug 2020 20:27 UTC
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: t.m...@protocol.invalid (T. Ment)
Newsgroups: alt.lang.asm
Subject: MASM nested function
Date: Fri, 07 Aug 2020 20:27:11 +0000
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <1rbrifpmqr7ivem24jahgsvmn26hs11s99@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="552472b27adf833b6cfca5d440eff947";
logging-data="22168"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZdvFkeaYZPS36oJYqnTgJTb+uTYvWm8E="
Cancel-Lock: sha1:KNAoOKIVSmtSyDLHLl9X265zrQQ=
X-Newsreader: Forte Agent 1.93/32.576 English (American)
View all headers
In a PROC with LOCAL variables, I wanted to factor duplicate code and
make it a subroutine. I've read you can define a PROC within a PROC, but
MASM 5.1 said "block nesting" error. Maybe that only works with older
versions, or full segment directives. IDK.

So I tried this:


blah
blah
blah

call mysub

blah
blah
blah

call mysub

blah
blah
blah

ret

mysub:

blah
blah
blah

pop cx
jmp cx


Call pushes IP on the stack, and pop/jmp acts like a return. I didn't
want to use RET because then MASM creates duplicate epilogue code. Build
with /La, in the listing you can see.

PROC LOCAL stack variables are visible in the subroutine. Nice trick.





1
rocksolid light 0.7.2
clearneti2ptor