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,707 of 4,675   
   s_dubrovich@nospicedham.yahoo.com to James Harris   
   Re: String literals in asm source code   
   23 Dec 18 09:57:06   
   
   On Friday, December 21, 2018 at 1:51:19 PM UTC-6, 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.   
   >   
   >   
   > 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).   
   >   
   >   
   > 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?   
   >   
   > --   
   > James Harris   
      
   Re Option 2..   
      
   I use nasm -fbin   
   I control the memory model by how I express the sections.   
   The 'expression' needs doing once at the beginning, thereafter just indicate   
   the sections.   
      
   ex. small model where CS = DS :   
      
   all the .text sections are followed by the .data sections and the addressing   
   flows from one through the other.   
      
   [SECTION .text align=1 vstart=BiosOffset]   
   [SECTION .data align=1 vfollows=.text]   
      
   [SECTION .text]   
      
   jmp	near INIT	;; 0. Enter from BOOT ROM or LOADER, as Cold Boot.   
   .   
   .   
   .   
      
   [SECTION .text]   
      
   Fill_DMA:   
    	CLD   
      
    	push	ES   
    	push	DS   
    	pop	ES   
      
     	mov	SI, msgTest	;; src   = DS:SI   
     	mov	DI, Local_DMA	;; dest. = ES:DI   
   .lp:   
   	LODSB			;; DS:SI++   
   	cmp	al,0		;; ck terminator byte   
   	je	.done   
   	STOSB			;; otherwise, AL->ES:DI++   
   	jmp	.lp   
   .done:   
   	mov	al, 1Ah		;; ctrl-z text termination   
   	stosb   
      
   	pop	ES   
      
   	RET   
      
   [SECTION .data]		;; 73 bytes, + a null   
      
   msgTest: db 'This is string data to test writing to a file, an also test TYPE '   
   	 db 'command.',0   
      
      
   [SECTION .text]   
   .   
   .   
   .   
      
   So this works for me, maybe suitable for you. (shrug)   
      
   Merry Christmas to All..   
      
   Steve   
      
   --- 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