0

I start newly learning emu8086, trying to code string length calculation and print, below the code

name "Text-Size"
code segment;(Segment code)
assume CS:Code, Ds:Code,SS:Code,ES:Code

org 100h
jmp start
start:
     mov ax, code
     mov ds,ax
     mov ah, 9
     mov dx, offset text
     mov bl,0
     int 21h
     
     count_length:
         mov [dx], al; saving input in string
         inc dx
         inc bl
         cmp dx,ah
         int 21h
         jmp print_lenght:

print_lenght:
    mov dl,bl
    mov ah,2
    add dl,48
    int 21h
ret

text DB 'Hello world',0DH,'$'
code ends

I am getting the error: wrong parameters MOV[dx],al probably it s undefined var [dx]

enter image description here

I am expecting to have String length calculated and printed.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • `mov [dx], al` doesn't work because DX can't be used in 16-bit register indirect addressing like this. You could use BX, SI, and DI (BP as well but that use the SS stack segment as default) .I'd also expect the error to be this line `cmp dx,ah` since you are trying to compare 2 different size registers. – Michael Petch Dec 13 '22 at 10:48
  • More on register indirect addressing an be found here: https://www.ic.unicamp.br/~celio/mc404s2-03/addr_modes/intel_addr.html#HEADING2-35 – Michael Petch Dec 13 '22 at 10:55
  • In 16-bit x86 you can't have `ax`, `cx`, or `dx` inside brackets. This isn't a big deal, all you have to do to fix that error is to use `bx` as your string pointer instead of `dx`. There's a much easier way to do what you're trying to do but since you're new to the language I wouldn't worry about that now. – puppydrum64 Dec 13 '22 at 11:59

0 Answers0