[Nasm-bugs] [Bug 3392813] New: Assembly comments may affect generated machine instructions

noreply-nasm at dev.nasm.us noreply-nasm at dev.nasm.us
Wed Sep 28 10:25:56 PDT 2022


https://bugzilla.nasm.us/show_bug.cgi?id=3392813

            Bug ID: 3392813
           Summary: Assembly comments may affect generated machine
                    instructions
           Product: NASM
           Version: 2.15.xx
          Hardware: PC
                OS: Linux
            Status: OPEN
          Severity: normal
          Priority: Medium
         Component: Assembler
          Assignee: nobody at nasm.us
          Reporter: pw.piotr.wyrwas at gmail.com
                CC: chang.seok.bae at intel.com, gorcunov at gmail.com,
                    hpa at zytor.com, nasm-bugs at nasm.us
     Obtained from: From OS distribution

So I've been working on low-level software project when I noticed odd
behaviour, which is very likely to be related to the comments in the assembly
source code.

The following is small segment of said project's code which is responsible for
changing
the video mode:

[program.asm] -----------------------------------

(..)

;; Just for finding this segment later in the disassembler output
nop

VideoMode:
        mov ah, 0x0             ;; \
        mov al, 0x2             ;; | Change the video mode to 80x25 text
        int 0x10                ;; /

        ret

nop

(..)

-----------------------------------

This code was later compiled using the following command:
nasm -f bin program.asm -o program

.. and then disassembled:
objdump --disassemble-all --target binary --architecture i386
--disassembler-options=intel program

The `mov al, 10x2` command does not exist at the expected location in the
disassembly:

  (..)
  20:   90                      nop
  21:   b4 00                   mov    ah,0x0
  23:   cd 10                   int    0x10
  25:   c3                      ret    
  26:   90                      nop
  (..)

Then I removed the comments from the code, which yielded the following
disassembly:

  (..)
  20:   90                      nop
  21:   b4 00                   mov    ah,0x0
  23:   b0 02                   mov    al,0x2
  25:   cd 10                   int    0x10
  27:   c3                      ret    
  28:   90                      nop
  (..)

Conclusion: For some reason the comments placed in the source code may affect
machine instruction generated by NASM. The code fragment I've shared in this
bug report is just an example - I've noticed the same behaviour with other
parts of my code involving comments with the '\' (backslash) character.

The full source code on gist:
https://gist.github.com/piotrwyrw/9845eec605a19de1e86d7ed8a1f10319

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are watching all bug changes.


More information about the Nasm-bugs mailing list