0

I am new to learning assembly language. I have the following code to read a string with a five character limit.

.model small
.stack 100h
.data
    message    db "Type a word: ", '$'

    keyboardArea label byte
    maxkeys    db 5
    charsInput db ?
    buffer     db 32 dup(0)
.code
    main proc
        mov ax, @data
        mov ds, ax

        mov dx, offset message
        mov ah, 9h
        int 21h

        mov dx, offset keyboardArea
        mov ah, 0Ah
        int 21h

        mov ah, 4Ch
        int 21h
    main endp
end

How can I print the number of characters read?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Diego FC
  • 75
  • 5
  • 2
    [Displaying numbers with DOS](https://stackoverflow.com/q/45904075) covers the general case, but your input limit is only 5 (despite reserving 32 bytes in the buffer), so `charsInput` will always be a single-digit number. So just load it and `add dl, '0'` for a print-char DOS call. – Peter Cordes Aug 30 '22 at 22:02
  • Ok, I tried to load the offset of charsInput in the DX register as with the other variables, then, I wrote what you put in your comment (add dl, '0') to then use mov ah, 2h; int 21h but when I run, it always prints the letter 'A' as the first letter, no matter what word I write (it overwrites the "T" of the variable printed at the beginning, "message"). Am I skipping something or where should I load charsInput? Thank you in advance. – Diego FC Aug 30 '22 at 23:13
  • 3
    You want to load the byte from memory, not its address. `mov dl, [charsInput]`. – Peter Cordes Aug 30 '22 at 23:28
  • You just saved me, I really appreciate it. – Diego FC Aug 30 '22 at 23:53

0 Answers0