0

I'm need to write function, which output a string in real-mode. There is that code:

;; ds:si - string address, cx - length of string
   cld
putc:
   lods
   mov ah, 0x0E
   xor bh, bh    
   int 0x10          ;; display character, advancing cursor and scrolling screen
                     ;; as necessary
   loop putc

But it output only first character few (defined by the CX register) times, a.e. the SI register don't increase. Is where a error?

SubtRose
  • 35
  • 3
  • 1
    `lodsb` definitely does increment SI (since DF=0 after your `cld`). SIngle-step your code in a debugger and look at registers (like AL) before each `int 0x10`, something else must be going on. Are you sure the memory pointed-to by DS:SI holds what you expect? I assume your assembler assembles `lods` to `lodsb` despite the ambiguous operand-size? If not, perhaps it just treated it as a label, not an instruction? NASM warns by default about labels without a `:` for that reason. – Peter Cordes Feb 07 '22 at 17:28

1 Answers1

4

lods isn't a valid instruction mnemonic; you probably mean lodsb.

On my assembler (nasm), a token that isn't a valid mnemonic gets parsed as a label instead, and so no code is emitted. Thus your lods is effectively a no-op, so no wonder SI doesn't increment. (The assembler does give a warning though, does yours?)

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
  • Yes, it work, when put lodsb instead lods. Strangely NASM doesn't emit warning (or error). Also the 8086's Family Intel Manual tell "lods" instruction, but there isn't a word about "lodsb" or "lodsw". Thanks for help – SubtRose Feb 09 '22 at 17:44
  • @SubtRose: With Intel's original ASM-86 assembler, I believe you could write the string instructions with operands, whose types would inform the assembler what size to use. E.g. `wordvar dw ...` ; `lods wordvar` would load bytes. There are some examples on page 2-125 and following. This usage is now unusual and many assemblers probably don't support it at all. Even ASM-86 apparently supported the `movsb` syntax too, see page 2-114. – Nate Eldredge Feb 10 '22 at 04:55
  • @SubtRose: What version of nasm are you using? 2.14.02 warns `lods.asm:5: warning: label alone on a line without a colon might be in error [-w+orphan-labels]` – Nate Eldredge Feb 10 '22 at 04:56