0

I have problem with an Assembler (16-bits) When I type 'abc' it return me abc too. The question is, how can I get access to 'a' (first element) ? Can I use stack (to chars)?

org 100h

Start:
mov ah,0ah
mov dx,input
int 21h

mov ah,9
mov dx,label
int 21h
mov ah,9
mov dx,input+2
int 21h

End:
mov ax,4c00h
int 21h

label db 10,13,"Your characters: $"
input db 6
db 0
times 8 db "$"
Jester
  • 56,577
  • 4
  • 81
  • 125
Michaello
  • 43
  • 1
  • 1
  • 8
  • You used print string function. You can of course load individual bytes and print them one at a time. – Jester Nov 23 '18 at 14:19
  • after input (`int 21h` service), the string is stored in memory, in that buffer reserved by `times 8 db "$"`, which did initialize 8 bytes with value 36. So you can access it by any instruction accessing memory, like `mov al,[input+2]` will load value `97` into register `al`. (97 = `'a'` in ASCII encoding). Or `mov ax,[input+3]` will load `ax` with `0x6362` (i.e. `al = 'b'`, and `ah = 'c'`) (for input "abc"), and at address `input+5` there will be value `13` ("enter" or more precisely in DOS "carriage return"). (you can also use stack, although it's hard to imagine what exactly you mean) – Ped7g Nov 23 '18 at 14:40

1 Answers1

0

Yes, of course.
Your string is just a sequence of bytes.

The easier way is to actually name all the part of the structure used by the Int 21h/AH=0ah service:

label db 10,13,"Your characters: $"

input    db 6
str_len  db 0
string:  times 8 db "$"

then:

mov al, BYTE [str_len] can be used to load the string's length in al (any 8-bit register will do).
mov al, BYTE [string + X] will load the (X + 1)th char of the string in al (for X known at assemble time - i.e. static).
mov bx, X + mov al, BYTE [string + bx] will load the (X + 1)th char of the string in al (for X known at runtime - i.e. dynamic).

Margaret Bloom
  • 41,768
  • 5
  • 78
  • 124