pouët.net

OpenWatcom macros in inline assembly question

category: code [glöplog]
 
I am looking for a way to repeat a block of code without having to manually copy paste
I was looking at some code where I repeated a big block 160 times, and I was thinking why do I do this? Why not just use some macro?

I use this syntax:
_asm {
};

I was searching the openwatcom docs to see if it supports macros to repeat blocks of code, but couldn't find anything concrete, neither when searching on the internet. I read it's some microsoft assembler syntax so I searched a bit more and found here https://www.phatcode.net/res/223/files/html/Chapter_8/CH08-9.html that I should use the REPEAT n, ENDM

It doesn't seem to work with OpenWatcom _asm, I get compiler syntax errors. I am not sure if I should stop trying as maybe it doesn't exist, or there is some other keyword that does the job.

What are the alternatives? I admit I haven't used the other inline assembly syntax that starts with a Pragma Aux and passes it as a string, I found it awkward. But could that be a solution to repeat blocks of code? My other solution would be to simply write a preprocessor to do the job, but I want to avoid it if possible.
added on the 2022-02-06 11:12:40 by Optimus Optimus
I remember darkly using openwatcom for my first steps in C (DOS) and that inline assembly sucked hard, no real asm syntax, so I switched to MSVC for Dos with a modified stub for sizecoding ...
added on the 2022-02-06 11:36:29 by Asato Asato
Code: #define KKLUDGE _asm { mov eax, 1 } \ _asm { mov eax, 2 } \ _asm { mov eax, 3 } \ _asm { mov eax, 4 } \ _asm { mov eax, 5 } \ void main() { KKLUDGE KKLUDGE KKLUDGE KKLUDGE KKLUDGE KKLUDGE }
added on the 2022-02-06 12:03:36 by yzi yzi
i myself gave up and used external assembler (first FASM, switched to NASM now), plus you can always define custom calling convention for external procedure via #pragma aux :)
added on the 2022-02-06 13:36:28 by wbcbz7 wbcbz7
Quote:
Code: KKLUDGE


That's a nice idea. I think at one time I defined the macro inside _asm, like _asm { KKLUDGE } but of course that didn't work. Now, when I split the code in multiple _asm sections I end up with another problem, a jump after my repeating block that goes before will not see the label. But maybe I can solved with saving the address in the stack or something (it's a long jump not a JR). Ok, I think I could work around this for now.
added on the 2022-02-06 19:50:12 by Optimus Optimus
Can't you put your asm-code in a separate file and tell your makefile to use your favourite assembler on it?
Downside would be that this results in an external function which requires an actual call while an inline-function could be, well, inlined.
added on the 2022-02-09 13:56:13 by hfr hfr

login