Let's say you have some code in the .data section:

doodle db "*****,3,*****"

Is there anyway to change the ,3, into something else? (Perhaps a smiley face or somesuch.)

I was thinking if I had the registers all set up, I could do something like:

~~assume there is code above~~
mov si, 0
mov al, doodle[si]
~~continue down to loop~
characterloop:
cmp doodle[si], ',3,'
jne L1
mov al, 01h
jmp othercode

Any hints or tips would greatly be appreciated.

Dani AI

Generated

Two different DB forms were being mixed up.
doodle db "*****,3,*****" creates a single string that contains the comma and the ASCII digit 3 (ASCII 0x33).
doodle db "*****",3,"*****" inserts a single numeric byte with value 3 (0x03) between the star characters. That numeric 3 is not the same as the printable character '3'. The star * is ASCII 0x2A, so testing for '*' is a single-byte compare; testing for the sequence ,3, requires checking three bytes in order.

A straightforward runtime approach is a byte-by-byte scan: find a comma, check the next byte (either 3 or '3' depending on how you assembled it), then check the following comma, and if it matches write the replacement byte. Example (adjust registers for 16-bit vs 32-bit code and ensure you know the buffer length or a terminator):

mov si, OFFSET doodle        ; or lea esi,doodle in 32-bit
scan_loop:
    mov al, byte ptr [si]
    cmp al, ',' 
    jne advance
    cmp byte ptr [si+1], 3    ; use '3' (0x33) if you assembled ASCII '3'
    jne advance
    cmp byte ptr [si+2], ','
    jne advance
    mov byte ptr [si+1], 1    ; replace with codepage smiley 0x01 (if desired)
advance:
    inc si
    ; stop when known length or a zero terminator is reached

Note 's not byte [bx] trick flips all bits in a byte — useful for bitwise transformations but not for turning 0x03 into a printable smiley. Also ensure the data sits in a writable segment (use .data) before modifying it. For DOS/console smileys use CP437 codes (0x01/0x02); see Code page 437 for which byte values map to glyphs (Code page 437). For DB/CMP/byte semantics consult the MASM docs (DB directive).

Recommended Answers

All 2 Replies

Let's say you have some code in the .data section:

doodle db "*****",3,"*****"

Is there anyway to change the ,3, into something else? (Perhaps a smiley face or somesuch.)

I was thinking if I had the registers all set up, I could do something like:

~~assume there is code above~~
mov si, 0
mov al, doodle[si]
~~continue down to loop~
characterloop:
cmp doodle[si], ',3,'
jne L1
mov al, 01h
jmp othercode

Any hints or tips would greatly be appreciated.

I want to be able to interact with the ",3," in the program if possible. Also, is the way to detect a * the same as the way to detect the ",3,"? Thank you in advance.

deadstag db 'aCiDI0',6,'I0AcId'
; damn six gets iNvErTeD \/
mov bx, deadstag+6
not byte [bx] ; six got changed to something ELSE

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.