Image Map Image Map
Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: MASM question--determining segment of a variable for conditional assembly

  1. #11
    Join Date
    Feb 2017
    Location
    Guildford, U.K.
    Posts
    475
    Blog Entries
    1

    Default

    Would a construct such as
    PUSH WORD PTR (SEG (FAR PTR (DATA)))
    POP ES
    be interpreted correctly? It's been a long time...

  2. #12
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    36,113
    Blog Entries
    18

    Default

    I don't think you need to be that complicated; just a simple push seg should suffice:
    Code:
                                            .model  small,c
                                            .286
    
     0000                                   .data
    
     0000 0000                      One     dw      0
    
     0000                                   .code
    
     0000  68 ---- R                        push    seg One
    
                                            end
    Note that (1) it's restricted to 186 and better and (2) it relies on the linker to fill in the segment value.

  3. #13
    Join Date
    Feb 2017
    Location
    Guildford, U.K.
    Posts
    475
    Blog Entries
    1

    Default

    Quote Originally Posted by Chuck(G) View Post
    I don't think you need to be that complicated; just a simple push seg should suffice:

    Note that (1) it's restricted to 186 and better and (2) it relies on the linker to fill in the segment value.
    I was thinking about a model and segment-independent macro though, hence the (MASM-specific, yuck!) explicit type casting and generalised x86 immediate value word push. The linker-dependent segment relocation fixup is the same.

  4. #14
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    36,113
    Blog Entries
    18

    Default

    Of course, all of this relates to the simple assembly time question of "What segment did I declare this variable in?"

    I can see only two possible answers that an optimal MASM might return:

    1. You declared it in the segment named (fill in the blank)
    2. You haven't declared it yet, so I don't know.

    Curiously, MASM can't even answer the question for a variable declared in an absolute segment (i.e. declared in a "SEGMENT AT xxxx").

    It would seem like a no-brainer.

  5. #15

    Default

    A bit off topic, but still related to this.

    Using the large model, how can I force an array to be located at, for example, segnemt 2, offset 0?.

    I managed to program a simple code which loads sound samples to a buffer, and plays them from there. I want that buffer to use an entire segment (exactly 64K) so that the sound blaster can read all samples stored there using DMA.

    For the moment I just used malloc, and code from root42 https://www.youtube.com/watch?v=hn-9oL-ClCE. The code allocated a 32K buffer that lies inside a segment, but I can't make it allocate 64K inside one segment. The start address is always not zero, and the last part of the buffer goes to the next 64k block in memory, (resulting in no sound when playing that part).

    I thought I could define a 64k array in assembly and declare it like this:

    Code:
    org 0
    _sound_data	label	word
    dw 00000h, 00000h, 00000h, 00000h, ...
    The org instruction does work, it moves the array inside the segment, but the compiler places the arrays just after the program code, so "org" advances from a non zero offset. How could I define a free segment to store the array?.


    Thanks!.

  6. #16
    Join Date
    Jun 2012
    Location
    UK - Worcester
    Posts
    4,461

    Default

    Is this a C compiler question as opposed to a MASM one?

    Anyhow, providing the compiler/assembler locates the start of the array on a 16-byte boundary, you can determine the segment of the start of the array and the offset is automatically 0.

    I would, however, put my data in a separate segment and use the tools to locate that segment on a paragraph boundary. This can usually be specified as a parameter to the segment (or group) directive of the assembler.

    I am using the Intel ASM86 tools these days on a DOS box and not MASM. I need to locate my segments absolutely (to match the hardware) and I am doing this via directives to the locator. I am writing embedded code for communications cards.

    Dave

  7. #17

    Default

    Quote Originally Posted by daver2 View Post
    Is this a C compiler question as opposed to a MASM one?
    Both, I just wanted to know the best, simpler way to do it. Im using tasm, and I could not find any docs about storing data at particular addresses or segments. For example, game boy compilers will paste assembly data/code at a specific location in rom, if you use "_CODE_X" flags (or #pragma x in c). I thought there was something similar for MS-DOS.

  8. #18
    Join Date
    Jun 2012
    Location
    UK - Worcester
    Posts
    4,461

    Default

    I have just looked up the MASM documentation and you can define a specific segment name specifying paragraph (segment) alignment and optionally locating the segment at a specific address if you really want to.

    See MASM documentation related to SEGMENT and ENDS. Check the documentation for: alignment PARA and location AT.

    You can then identify (at run-time) where the segment is located by using the SEG operator.

    I will lookup the tasm documentation now.

    Which 'tasm' are you referring to by the way? There are a number of assembler products identified as 'tasm'.

    The Telemark TASM doesn't appear to support these directives (on a very quick look at least).

    Borland Turbo Assembler (TASM) seems to support similar directives to MASM.

    Dave
    Last edited by daver2; January 26th, 2021 at 06:24 AM.

  9. #19

    Default

    Quote Originally Posted by daver2 View Post
    Borland Turbo Assembler (TASM) seems to support similar directives to MASM.

    Dave
    Sorry, I forgot to specify, I'm using that one, "Borland Turbo Assembler". It's good to know there are similar directives, (I should have read more turbo assembler docs).

    Thanks.

  10. #20
    Join Date
    Jun 2012
    Location
    UK - Worcester
    Posts
    4,461

    Default

    The Borland Turbo Assembler supports the same syntax as the MASM assembler (according to the documentation).

    SEGMENT, ENDS, PARA and AT keywords apply in a similar manner.

    I can't give you an exact syntax - but if you have a go and post the results (I suggest you create a separate thread for your discussion though) I may be able to help further.

    Dave

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •