home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 3,697 of 4,675   
   JJ to James Harris   
   Re: String literals in asm source code   
   22 Dec 18 05:07:12   
   
   From: jj4public@nospicedham.vfemail.net   
      
   On Fri, 21 Dec 2018 19:49:50 +0000, James Harris wrote:   
   > What's the most readable way to include string literals in asm source code?   
   >   
   > Option 1   
   > ========   
   >   
   > I usually define string literals in a separate block, like this.   
   >   
   > ;**********   
   > ;   
   > ; Data section   
   > ;   
   > ;**********   
   > section .data   
   > msg_started:         db "Operation started", 0   
   > msg_finished_errors: db "Operation finished. Number of errors: ", 0   
   >   
   > Then, later,   
   >   
   > ;**********   
   > ;   
   > ; Text section   
   > ;   
   > ;**********   
   >    mov ebx, msg_started   
   >   
   > The downside to that is that the message can be separated from its use   
   > by a few screens-worth of scrolling.   
      
   I use this layout in most cases. If the code section is too long, I put the   
   data section contents in a separate file - as an include file for the main   
   source code. Considering that I can quickly switch between main and include   
   files' tab in the text editor. However, I'd do this only after the   
   development is completed. Otherwise, it'd be troublesome to trace if there's   
   a compilation error.   
      
   > Option 2   
   > ========   
   >   
   > To avoid a large separation between def and use one could temporarily   
   > drop to the data section as needed in the middle of other code (I'll use   
   > nops to indicate other executable code).   
   >   
   >    nop   
   >    nop   
   >    nop   
   > section .data   
   > msg_started: db "Operation started", 0   
   > section .text   
   >    mov ebx, msg_started   
   >   
   > The downside of that is it is arguably harder to read (and doesn't deal   
   > with duplicate strings well).   
      
   IMO, that's quite a useful layout but, what if there are other parts of the   
   source code which need to be laid out like that? Does the compiler allows   
   multiple section declarations with the same section name?   
      
   > Option 3   
   > ========   
   >   
   > Or, maybe a macro could effect option 2 - something like the following.   
   > (This is illustrative, not tested code.)   
   >   
   >    mov ebx, string_literal(db "Operation started", 0)   
   >   
   > Of course, code layout is not a major issue but it is one of   
   > convenience; and readability is important. So I wondered what other   
   > people do to incorporate strings in code. What have you found to be the   
   > most readable and easiest to work with?   
      
   I don't think macros can be used using that kind of syntax for this purpose.   
   While it may be possible using the proper syntax, it's basically still the   
   same as Option 2, just simpler. And with the same problem.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca