Jump to content
IGNORED

Mad-Assembler (MADS)


 Share

Recommended Posts

  • 4 months later...

Not sure if this is the right topic for questions about MADS, so if not please move it to wherever it fits..

 

My question is about if it's possible to iterate through those indexed arrays. Or the indexed structs.

I mean, it's really nice to have these structures and arrays, yet I somehow cannot find anything about how to iterate through these with MADS.

 

Maybe someone can give me a pointer (pun intended) on how to accomplish this.

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

In an experiment with a nested .REPT I see unexpected behaviour.

 

    org $2000
    
    .rept 4, #    
;    .byte :1
    .rept 4, :1, #
    .byte :1, :2
    .endr
    .endr

 

With the line commented out the output is:

 

 mads 2.1.5 build 3 (21 Feb 22)
Source: test.asm
     1                     org $2000
     2                     
     3                     .rept 4, #    
     6                     .BYTE :1, :2
     8                     .endr
Source: REPT
     8                     .endr
Source: REPT
     6 FFFF> 2000-201F> 00 00        .BYTE 0, 0
     6 2002 00 01            .BYTE 0, 1
     6 2004 00 02            .BYTE 0, 2
     6 2006 00 03            .BYTE 0, 3
Source: test.asm
     6                     .endr
Source: REPT
     6 2008 00 00            .BYTE 0, 0
     6 200A 00 01            .BYTE 0, 1
     6 200C 00 02            .BYTE 0, 2
     6 200E 00 03            .BYTE 0, 3
Source: test.asm
     6                     .endr
Source: REPT
     6 2010 00 00            .BYTE 0, 0
     6 2012 00 01            .BYTE 0, 1
     6 2014 00 02            .BYTE 0, 2
     6 2016 00 03            .BYTE 0, 3
Source: test.asm
     6                     .endr
Source: REPT
     6 2018 00 00            .BYTE 0, 0
     6 201A 00 01            .BYTE 0, 1
     6 201C 00 02            .BYTE 0, 2
     6 201E 00 03            .BYTE 0, 3
Source: test.asm
Source: test.asm

 

But with the line included it becomes:

 

mads 2.1.5 build 3 (21 Feb 22)
Source: test.asm
     1                     org $2000
     2                     
     3                     .rept 4, #    
     4                     .BYTE :1
     6                     .BYTE :1, :2
     8                     .endr
Source: REPT
     4 FFFF> 2000-2023> 00        .BYTE 0
     4                     .endr
Source: REPT
     6 2001 00 00            .BYTE 0, 0
     6 2003 00 01            .BYTE 0, 1
     6 2005 00 02            .BYTE 0, 2
     6 2007 00 03            .BYTE 0, 3
Source: test.asm
     4 2009 01                .BYTE 1
     4                     .endr
Source: REPT
     6 200A 01 00            .BYTE 1, 0
     6 200C 01 01            .BYTE 1, 1
     6 200E 01 02            .BYTE 1, 2
     6 2010 01 03            .BYTE 1, 3
Source: test.asm
     4 2012 02                .BYTE 2
     4                     .endr
Source: REPT
     6 2013 02 00            .BYTE 2, 0
     6 2015 02 01            .BYTE 2, 1
     6 2017 02 02            .BYTE 2, 2
     6 2019 02 03            .BYTE 2, 3
Source: test.asm
     4 201B 03                .BYTE 3
     4                     .endr
Source: REPT
     6 201C 03 00            .BYTE 3, 0
     6 201E 03 01            .BYTE 3, 1
     6 2020 03 02            .BYTE 3, 2
     6 2022 03 03            .BYTE 3, 3
Source: test.asm
Source: test.asm

 

Is this a bug? I can use this as an alternative way to reference the outer variable for it to be passed correctly to the inner but not produce code:
 

    org $2000
    
    .rept 4, #    
@myvar:1 equ :1
    .rept 4, @myvar:1, #
    .byte :1, :2
    .endr
    .endr

 

Producing:

 

mads 2.1.5 build 3 (21 Feb 22)
Source: test.asm
     1                     org $2000
     2                     
     3                     .rept 4, #    
     4                 @MYVAR:1 EQU :1
     6                     .BYTE :1, :2
     8                     .endr
Source: REPT
     4 = 0000            @MYVAR0 EQU 0
     4                     .endr
Source: REPT
     6 FFFF> 2000-201F> 00 00        .BYTE 0, 0
     6 2002 00 01            .BYTE 0, 1
     6 2004 00 02            .BYTE 0, 2
     6 2006 00 03            .BYTE 0, 3
Source: test.asm
     4 = 0001            @MYVAR1 EQU 1
     4                     .endr
Source: REPT
     6 2008 01 00            .BYTE 1, 0
     6 200A 01 01            .BYTE 1, 1
     6 200C 01 02            .BYTE 1, 2
     6 200E 01 03            .BYTE 1, 3
Source: test.asm
     4 = 0002            @MYVAR2 EQU 2
     4                     .endr
Source: REPT
     6 2010 02 00            .BYTE 2, 0
     6 2012 02 01            .BYTE 2, 1
     6 2014 02 02            .BYTE 2, 2
     6 2016 02 03            .BYTE 2, 3
Source: test.asm
     4 = 0003            @MYVAR3 EQU 3
     4                     .endr
Source: REPT
     6 2018 03 00            .BYTE 3, 0
     6 201A 03 01            .BYTE 3, 1
     6 201C 03 02            .BYTE 3, 2
     6 201E 03 03            .BYTE 3, 3
Source: test.asm
Source: test.asm

 

Link to comment
Share on other sites

@Wrathchild these nested loops are not behaving good, I had an issue and got elegant solution directly in this very thread:

 

it is using the temporary labels (those with questionmarks)... it is well readable and what is important is that it is forward compatible (not relying on nested loop behavior of particular mads release)

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...