small problem with 8086 coding

I just have a sall proble with this function. It gives the correct length for any input apart from if you dont enter anything then it gives the answer 1 when it should be 0. can anyone help.?

short StrLen(const char *Str)
{

asm{
mov di,Str // put content of str in the di register
xor ax,ax // clear ax
}

Read:

asm{
inc ax // increase the ax register
inc di // increase the di register
mov bx,ds:[di] // read address of string
cmp bx,""
je nodata
cmp bx,0 // check for end of string marker
jne Read // if not end of string marker jump to the label Read
}
nodata:

return _AX; // return with length of string in ax

don't think im far off correct! please someone just finsih it off for me.
thanks,
*Ribbleton_

Comments

  • It's because you're INCrement the counter before you check if the current value is the end of string.

    just increment it after you verify that you're not at end of string.
    Your value will then return the true length of the string (add 1 if you want to return the length plus the NULL at the end)

    -jeff!


    : I just have a sall proble with this function. It gives the correct length for any input apart from if you dont enter anything then it gives the answer 1 when it should be 0. can anyone help.?
    :
    : short StrLen(const char *Str)
    : {
    :
    : asm{
    : mov di,Str // put content of str in the di register
    : xor ax,ax // clear ax
    : }
    :
    : Read:
    :
    : asm{
    : inc ax // increase the ax register
    : inc di // increase the di register
    : mov bx,ds:[di] // read address of string
    : cmp bx,""
    : je nodata
    : cmp bx,0 // check for end of string marker
    : jne Read // if not end of string marker jump to the label Read
    : }
    : nodata:
    :
    : return _AX; // return with length of string in ax
    :
    : don't think im far off correct! please someone just finsih it off for me.
    : thanks,
    : *Ribbleton_
    :
    :

  • : It's because you're INCrement the counter before you check if the current value is the end of string.
    :
    : just increment it after you verify that you're not at end of string.
    : Your value will then return the true length of the string (add 1 if you want to return the length plus the NULL at the end)
    :
    : -jeff!
    :
    :
    : : I just have a sall proble with this function. It gives the correct length for any input apart from if you dont enter anything then it gives the answer 1 when it should be 0. can anyone help.?
    : :
    : : short StrLen(const char *Str)
    : : {
    : :
    : : asm{
    : : mov di,Str // put content of str in the di register
    : : xor ax,ax // clear ax
    : : }
    : :
    : : Read:
    : :
    : : asm{
    : : inc ax // increase the ax register
    : : inc di // increase the di register
    : : mov bx,ds:[di] // read address of string
    : : cmp bx,""
    : : je nodata
    : : cmp bx,0 // check for end of string marker
    : : jne Read // if not end of string marker jump to the label Read
    : : }
    : : nodata:
    : :
    : : return _AX; // return with length of string in ax
    : :
    : : don't think im far off correct! please someone just finsih it off for me.
    : : thanks,
    : : *Ribbleton_
    : :
    : :
    :
    :

    Could you please show me where i could put the change!

  • Ok then so i have been told i increment before checking for end of string marker. I have tried but i can only get it to crash the computer! anyone please finish it off!

    #include "ASS1.h"
    #include

    short StrLen(const char *Str)
    {
    asm{
    mov di,Str // put content of str in the di register
    xor ax,ax // clear ax
    // dec ax
    }
    Read:
    asm{
    inc ax // increase the ax register
    inc di // increase the di register
    mov bx,ds:[di] // read address of string
    cmp bx,0 // check for end of string marker
    jne Read // if not end of string marker jump to the label Read
    }
    return _AX; // return with length of string in ax
    }

    *Ribbleton_
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories