scasb losdb help

hi guys
I want to search a string for a particular letter entered by the user. The string is regiser edx. Sorta like a hangman game. display the letter if found, so overriding the asteriks I had originally in the string. I want to use scasb and losdb since they are already written, don't feel like thinking. I'm doing what the net and my book is telling me to do, but the string is not displaying: I'm moving the offset of edi to edx and calling WriteString.

help is appreciated, thanks

Comments

  • [b][red]This message was edited by ASHLEY4 at 2004-10-31 19:18:3[/red][/b][hr]
    : hi guys
    : I want to search a string for a particular letter entered by the user. The string is regiser edx. Sorta like a hangman game. display the letter if found, so overriding the asteriks I had originally in the string. I want to use scasb and losdb since they are already written, don't feel like thinking. I'm doing what the net and my book is telling me to do, but the string is not displaying: I'm moving the offset of edi to edx and calling WriteString.
    :
    : help is appreciated, thanks
    :
    We need to see your code, like your WriteString function etc.
    So we can see what going on, we are not uri geller ;-)

    \\||////
    @)
    ASHLEY4.
  • : :
    : We need to see your code, like your WriteString function etc.
    : So we can see what going on, we are not uri geller ;-)
    :
    : \\||////
    @)
    : ASHLEY4.
    :
    I don't know how to use the code option so I will only post part of the whole. Here it is:
    mov edx, OFFSET prompt1
    call Writestring
    call Readhex

    pop edx

    mov edi, [edx]


    cld
    mov ecx, eax
    repne scasd
    jnz quit
    dec edi

    cld
    rep stosd


    mov edx, [edi]
    call writestring


    HELP ME!!!!!!!!!!!!!!!!!
  • [b][red]This message was edited by shaolin007 at 2004-11-1 7:26:55[/red][/b][hr]
    : : :
    : : We need to see your code, like your WriteString function etc.
    : : So we can see what going on, we are not uri geller ;-)
    : :
    : : \\||////
    @)
    : : ASHLEY4.
    : :
    : I don't know how to use the code option so I will only post part of the whole. Here it is:
    : mov edx, OFFSET prompt1
    : call Writestring
    : call Readhex
    :
    : pop edx
    :
    : mov edi, [edx]
    :
    :
    : cld
    : mov ecx, eax
    : repne scasd
    : jnz quit
    : dec edi
    :
    : cld
    : rep stosd
    :
    :
    : mov edx, [edi]
    : call writestring
    :
    :
    : HELP ME!!!!!!!!!!!!!!!!!
    :

    [green]
    scasd makes a comparison to the dword from location es:edi with eax.

    so
    [code]

    mov edi, offset string
    xor edi, edi ;start at the beginning of our string
    mov eax, your_value
    cld
    mov ecx, size_of_string

    repne scasd

    cmp ecx, 0
    je no_equal_found



    Equal:
    .
    .
    .

    [/code]
    [/green]



  • :
    : [green]
    : scasd makes a comparison to the dword from location es:edi with eax.
    :
    : so
    : [code]
    :
    : mov edi, offset string
    : xor edi, edi ;start at the beginning of our string
    : mov eax, your_value
    : cld
    : mov ecx, size_of_string
    :
    : repne scasd
    :
    : cmp ecx, 0
    : je no_equal_found
    :
    :
    :
    : Equal:
    : .
    : .
    : .
    :
    : [/code]
    : [/green]
    :
    :


    Now I want to display any letters that scasb found. Would I use losd?

  • : :
    : : [green]
    : : scasd makes a comparison to the dword from location es:edi with eax.
    : :
    : : so
    : : [code]
    : :
    : : mov edi, offset string
    : : xor edi, edi ;start at the beginning of our string
    : : mov eax, your_value
    : : cld
    : : mov ecx, size_of_string
    : :
    : : repne scasd
    : :
    : : cmp ecx, 0
    : : je no_equal_found
    : :
    : :
    : :
    : : Equal:
    : : .
    : : .
    : : .
    : :
    : : [/code]
    : : [/green]
    : :
    : :
    :
    :
    : Now I want to display any letters that scasb found. Would I use losd?
    :
    [green]
    I take it your meaning lodsd? If so, then all that does is load eax with the dword at ds:esi. So you could load your ASCII character or whatever data into that register and use a routine to print it out from there. Can you post your write string function?
    [/green]


  • : : :
    : : : [green]
    : : : scasd makes a comparison to the dword from location es:edi with eax.
    : : :
    : : : so
    : : : [code]
    : : :
    : : : mov edi, offset string
    : : : xor edi, edi ;start at the beginning of our string
    : : : mov eax, your_value
    : : : cld
    : : : mov ecx, size_of_string
    : : :
    : : : repne scasd
    : : :
    : : : cmp ecx, 0
    : : : je no_equal_found
    : : :
    : : :
    : : :
    : : : Equal:
    : : : .
    : : : .
    : : : .
    : : :
    : : : [/code]
    : : : [/green]
    : : :
    : : :
    : :
    : :
    : : Now I want to display any letters that scasb found. Would I use losd?
    : :
    : [green]
    : I take it your meaning lodsd? If so, then all that does is load eax with the dword at ds:esi. So you could load your ASCII character or whatever data into that register and use a routine to print it out from there. Can you post your write string function?
    : [/green]
    :
    :

    Everything I have is already posted in my second post or everything that deals with scasb and losdb.
    :

  • [b][red]This message was edited by shaolin007 at 2004-11-1 14:42:48[/red][/b][hr]
    : : : :
    : : : : [green]
    : : : : scasd makes a comparison to the dword from location es:edi with eax.
    : : : :
    : : : : so
    : : : : [code]
    : : : :
    : : : : mov edi, offset string
    : : : : xor edi, edi ;start at the beginning of our string
    : : : : mov eax, your_value
    : : : : cld
    : : : : mov ecx, size_of_string
    : : : :
    : : : : repne scasd
    : : : :
    : : : : cmp ecx, 0
    : : : : je no_equal_found
    : : : :
    : : : :
    : : : :
    : : : : Equal:
    : : : : .
    : : : : .
    : : : : .
    : : : :
    : : : : [/code]
    : : : : [/green]
    : : : :
    : : : :
    : : :
    : : :
    : : : Now I want to display any letters that scasb found. Would I use losd?
    : : :
    : : [green]
    : : I take it your meaning lodsd? If so, then all that does is load eax with the dword at ds:esi. So you could load your ASCII character or whatever data into that register and use a routine to print it out from there. Can you post your write string function?
    : : [/green]
    : :
    : :
    :
    : Everything I have is already posted in my second post or everything that deals with scasb and losdb.
    : :
    :
    [green]
    Here's a simple example of writing a letter to the screen. I'll let you figure out the rest.
    [/green]
    [code]

    ;NASM-IDE ASM Assistant Assembler Project File
    BITS 32 ;Set code generation to 32 bit mode
    ORG 0x0100 ;Set code start address to 0100h


    SEGMENT .text ;Main code segment

    mov eax, 0b800h
    mov es, eax ;video memory
    xor edi, edi ;location 0,0 upper left part of screen
    xor eax, eax

    mov eax, 0f00h ;ah=15 or bright white 'c'
    mov esi, letter ;offset of letter
    lodsb ;load al with 1 byte from letter
    stosw ;store ax into es:edi

    mov eax, 0 ;pause for any key
    int 16h

    mov eax, 4c00h ;terminate
    int 21h



    SEGMENT .data ;Initialised data segment

    letter db 'c'
    [/code]



  • OK I completely neglected the idea of using scasb because I haven't studied it yet. Instead, I'm traversing through the string using indirect addressing.

    [code]
    TITLE Program 2



    ;Lam Duong

    ;0455-4068

    ;This program .....



    INCLUDE Irvine32.inc

    .data



    word1 byte "elephant", 0

    word2 byte "university", 0

    word3 byte "bobby", 0

    word4 byte "wobble", 0

    word5 byte "mississippi",0

    msg_intro BYTE "this is like hangman ", 0
    msg_prompt1 BYTE "enter a letter and I'll see if it's in one of five words", 0

    msg_charnofound BYTE "you guessed wrong, try again", 0
    msg BYTE "pop worked yea", 0




    pointers dword word1

    dword word2

    dword word3

    dword word4

    dword word5

    nofguesses BYTE 7
    lettercontainer BYTE ?
    .code

    main PROC





    call Randomize
    mov eax, 5

    call RandomRange





    mov esi, OFFSET pointers ;esi = offset to pointers

    mov ecx, eax

    mov ebx, 0

    cmp ecx, 0

    jz MO

    L1:

    add ebx, 4



    loop L1

    MO:

    mov edx, [esi + ebx] ;edx = adress to randomword

    call writestring



    call determinelength








    mov ecx, ebx
    mov edi, offset lettercontainer
    mov ebx, 0
    l2:

    mov BYTE PTR [edi], '*'
    inc ebx
    inc edi ; edi = address to asterick string
    cmp ebx, ecx
    jne l2

    push edx

    mov edx, offset lettercontainer
    call writestring

    pop edx

    call displayletters






    exit

    main ENDP





    determinelength PROC



    ;push ecx

    ;push edx

    mov ecx, 100

    L1:

    mov al, [edx]

    cmp al, 0

    jz BR

    inc edx

    loop L1



    BR:

    mov ebx, 100

    SUB ebx, ecx ;ebx = length of randomword




    ;pop edx
    ;pop ecx


    ret

    determinelength ENDP

    displayletters PROC

    push edx

    ;call Crlf
    ;mov edx, OFFSET msg_prompt1
    ;call Writestring
    ;call Crlf
    call Readchar

    pop edx

    mov ecx, ebx

    L2:

    cmp [edx], eax
    je ifequal

    inc edx
    inc edi
    loop L2
    jmp away


    ifequal:
    mov [edi], eax
    mov edx, [edi]
    call Writestring
    call guessword

    inc edi
    inc edx
    loop L2

    away:

    ret
    displayletters ENDP




    guessword PROC





    ret
    guessword ENDP
    END main
    [/code]


    The program still crashes for some reason. hope someone can help.
  • : OK I completely neglected the idea of using scasb because I haven't studied it yet. Instead, I'm traversing through the string using indirect addressing.
    :
    : [code]
    : TITLE Program 2
    :
    :
    :
    : ;Lam Duong
    :
    : ;0455-4068
    :
    : ;This program .....
    :
    :
    :
    : INCLUDE Irvine32.inc
    :
    : .data
    :
    :
    :
    : word1 byte "elephant", 0
    :
    : word2 byte "university", 0
    :
    : word3 byte "bobby", 0
    :
    : word4 byte "wobble", 0
    :
    : word5 byte "mississippi",0
    :
    : msg_intro BYTE "this is like hangman ", 0
    : msg_prompt1 BYTE "enter a letter and I'll see if it's in one of five words", 0
    :
    : msg_charnofound BYTE "you guessed wrong, try again", 0
    : msg BYTE "pop worked yea", 0
    :
    :
    :
    :
    : pointers dword word1
    :
    : dword word2
    :
    : dword word3
    :
    : dword word4
    :
    : dword word5
    :
    : nofguesses BYTE 7
    : lettercontainer BYTE ?
    : .code
    :
    : main PROC
    :
    :
    :
    :
    :
    : call Randomize
    : mov eax, 5
    :
    : call RandomRange
    :
    :
    :
    :
    :
    : mov esi, OFFSET pointers ;esi = offset to pointers
    :
    : mov ecx, eax
    :
    : mov ebx, 0
    :
    : cmp ecx, 0
    :
    : jz MO
    :
    : L1:
    :
    : add ebx, 4
    :
    :
    :
    : loop L1
    :
    : MO:
    :
    : mov edx, [esi + ebx] ;edx = adress to randomword
    :
    : call writestring
    :
    :
    :
    : call determinelength
    :
    :
    :
    :
    :
    :
    :
    :
    : mov ecx, ebx
    : mov edi, offset lettercontainer
    : mov ebx, 0
    : l2:
    :
    : mov BYTE PTR [edi], '*'
    : inc ebx
    : inc edi ; edi = address to asterick string
    : cmp ebx, ecx
    : jne l2
    :
    : push edx
    :
    : mov edx, offset lettercontainer
    : call writestring
    :
    : pop edx
    :
    : call displayletters
    :
    :
    :
    :
    :
    :
    : exit
    :
    : main ENDP
    :
    :
    :
    :
    :
    : determinelength PROC
    :
    :
    :
    : ;push ecx
    :
    : ;push edx
    :
    : mov ecx, 100
    :
    : L1:
    :
    : mov al, [edx]
    :
    : cmp al, 0
    :
    : jz BR
    :
    : inc edx
    :
    : loop L1
    :
    :
    :
    : BR:
    :
    : mov ebx, 100
    :
    : SUB ebx, ecx ;ebx = length of randomword
    :
    :
    :
    :
    : ;pop edx
    : ;pop ecx
    :
    :
    : ret
    :
    : determinelength ENDP
    :
    : displayletters PROC
    :
    : push edx
    :
    : ;call Crlf
    : ;mov edx, OFFSET msg_prompt1
    : ;call Writestring
    : ;call Crlf
    : call Readchar
    :
    : pop edx
    :
    : mov ecx, ebx
    :
    : L2:
    :
    : cmp [edx], eax
    : je ifequal
    :
    : inc edx
    : inc edi
    : loop L2
    : jmp away
    :
    :
    : ifequal:
    : mov [edi], eax
    : mov edx, [edi]
    : call Writestring
    : call guessword
    :
    : inc edi
    : inc edx
    : loop L2
    :
    : away:
    :
    : ret
    : displayletters ENDP
    :
    :
    :
    :
    : guessword PROC
    :
    :
    :
    :
    :
    : ret
    : guessword ENDP
    : END main
    : [/code]
    :
    :
    : The program still crashes for some reason. hope someone can help.

    [green]
    Have you tried to run it through a debugger and see where it crashes at?
    [/green]

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