0
votes

In the past few days i've done some tests for an OS, but i can't understand why this code doesn't work: my function gets in input the string address(in BX) and the string length (in CX). If i put a numerical value (i.e. 10) in CX it works, if I put [len] in CX it doesn't work.

bits 16
org 0x7c00


mov bx, string
mov cx, [len]
call print

jmp $

; bx = string address, cx = string lenght
print:
    xor si, si
._loop:
    mov al, [bx+si]
    mov ah, 0x0e
    int 0x10
    inc si
    cmp si, cx
    jl ._loop

    ret

string db "Hello world!"
len equ $-string

times 510-($-$$) db 0
dw 0xaa55
1
Doesn't [len] mean - value at address of len? - Pawel Veselov
Indeed it does. And since len is an equ for an immediate, rather than an address, the OP should be using mov cx, len - Michael
Yea i've just realized that len is not a memory location but a constant - Mattia F.
The mov instruction uses the data segment and the call instruction push the return address to the stack. Missing a definition of the data segment und missing a definition of the stack segment and the stack-pointer. - Dirk Wolfgang Glomp

1 Answers

-1
votes

You Should Test This Code:

mov si,mystr1
call print_string
print_string:
pusha
@repeat:
lodsb
cmp al,0x00
je @done
mov ah,0x0E
int 10h
jmp @repeat
@done:
popa
ret
mystr1 db 'Hello World!',0