[TIASM, Brass] Flexible Macros

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

[TIASM, Brass] Flexible Macros

Post by driesguldolf »

Say you have a macro that negates a 16 bit register
you could make macros like this:

Code: Select all

.deflong NEG_HL
   ld a, h
   cpl
   ld h, a
   ld a, l
   cpl
   ld l, a
   inc hl
.enddeflong
but what do you need to do if you want to make a more flexible macro: (pseudo)

Code: Select all

.macro NEGATE(reg as string):
   ld a, reg(0)
   cpl
   ld reg(0), a
   ld a, reg(1)
   cpl
   ld reg(1), a
   inc reg
.endmacro
Is this even possible in Brass? And if it is, how do you tell Brass that reg is a string and reg(0) is the first character and reg(1) is the 2nd?
Any ideas?
Last edited by driesguldolf on Sun 24 Jun, 2007 3:26 pm, edited 1 time in total.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Well TASM is a bitch with this sort of thing(good thing you werent using it), but maybe in Brass..
I asked Ben about that too but I don't think he knew what I meant..
I don't know of any other way than this and I'm not even sure whether it works:

Code: Select all

.deflong NEGATE(regH, regL)
 ld a,regH
 cpl
 ld regH,a
 ld a,regL
 cpl
 ld regL,a
 inc regH regL ;not 100% sure what to do with the whitespace..
.enddeflong
sadly there is no subtring..
You could also hardcode every case with {curly brackets} which means the macro with matching input will be chosen. http://benryves.com/bin/brass/directives/define.htm
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

hehe, thanks King Harold, it works

I tried to compile that along with a "inc hl" and "inc h l"
it gave "23" as opcode in both cases! yay
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

This will probably be completely different in the new Brass (any news on that?)
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Yes, a quirk in Brass is that it ignored spaces when assembling (apart from inside strings) so inc h l will work. The "new" Brass isn't current in development, sorry.
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

I know it's a bit off topic (King Harold made a topic about it somewhere...)
But ben there is a serious problem with the .align directive, as King Harold said they appear correctly in the listing file but not in the intel hex file...
Strange, I tried the alternative (.org ($ + $00FF) & $FF00) but that give EXACT the same result as .align, it probabely is the fault of the intel hex writer...
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

It probably is a bug in the hex file writer, then. I'll look into it - sorry for the inconvenience!
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

I think i told you about this problem too ben a while ago on IRC. Though i did manage to overcome it by placing the table i needed at the start of an APP page. Brass is still ftw btw :).
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
Post Reply