0

I'm using Emu 8086 to code the work: Enter a string and print it.

But I don't know why the program doesn't print the right string I entered. Example, when I enter: "123456789", the result is "d (tab) 123456789". I think because I declared variable x is "100,?,101 dup('$')", therefore 'd' is corresponding to 100 in ascii. And tab is corresponding to 9 (the number of characters I entered) in ascii.

Here is my code:

.model small
.stack 100h
.data
      x db 100,?,101 dup('$')
      tab db 10,13,'$'
.code
main proc 
    mov ax, @data
    mov ds, ax

    mov ah, 10
    lea dx, x
    int 21h

    mov ah, 9
    lea dx, tab
    int 21h

    mov ah, 9
    lea dx, x
    int 21h

    mov ah, 4ch
    int 21h

    main endp

end main

Can anyone explain this problem? Thank you!

rkhb
  • 14,159
  • 7
  • 32
  • 60
hieu le khac
  • 1
  • 1
  • 1
  • `x` is not variable. It is just memory label, pointing to certain memory address. Then at that address you define byte 100, which you correctly recognized as "d". So you ask DOS to print "string" from address where 100 is stored (and further bytes store the length, input string, CR character and some random bytes up till `tab` memory address, where another `13, 10, '$'` will be found, and there the `9` service will stop printing (unless there would be some accidental "$" already inside the buffer following `x`). There are no variables in asm and you get what you asked for (display of memory). – Ped7g Sep 03 '18 at 10:39
  • If you want to print only the raw input buffer, you have to ask DOS to print from address `x+2` (skipping the two bytes defining lengths), i.e. `lea dx,[x+2]`. And you should first write "$" terminator into memory after the last character you want to print, in case you want to use `ah=9` DOS service. – Ped7g Sep 03 '18 at 10:40
  • Take a look here: https://stackoverflow.com/questions/24816507/how-to-fix-the-output-for-x86-turbo-assembly-language/24819739#24819739 – rkhb Sep 03 '18 at 12:36
  • For a thorough explanation of the DOS input function 0Ah, see here: https://stackoverflow.com/questions/47379024/how-buffered-input-works – Fifoernik Sep 06 '18 at 13:01

0 Answers0