News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

x86 assembly language newbie requesting help on a project.

Started by ProtoflareX, February 28, 2016, 09:52:25 AM

Previous topic - Next topic

ProtoflareX

#15
Quote from: dedndave on February 29, 2016, 01:09:31 PM
that looks ok - did you try to run the program ?

Kip Irvine's library isn't very modular
so, everything gets pulled in, resulting in larger than needed EXE's
so, 9 KB might be ok

Your code did work successfully, dedndave; I just made foolish mistake that caused me to think it didn't. Anyway, I am now attempting to solve the requirement in bullet point 2, which says: "Your program must have a procedure that accepts the address of a string and returns through EAX the length of the string". If I am correct, after the code below has finished executing, the address of the String typed in by the user is stored in EDX, right? If that is correct, then does that mean that I need to write a procedure that "USES" EDX in order to fulfill the requirement in the second bullet?

INCLUDE c:\irvine\irvine32.inc
INCLUDELIB c:\irvine\irvine32.lib
INCLUDELIB c:\masm32\lib\user32.lib
INCLUDELIB c:\masm32\lib\kernel32.lib

.data
theStringArray BYTE 256 dup(?)             
prompt BYTE "Please input a String",0

.CODE

main PROC

    mov     edx,offset theStringArray
    mov     ecx,sizeof theStringArray
    call    requestInput
    exit

main ENDP

requestInput PROC

    push    edx
    push    ecx
    mov     edx,offset prompt
    call    WriteString
    pop     ecx
    pop     edx
    call    ReadString
    ret

requestInput ENDP


getStringLength PROC USES edx

    ;temporarily empty

getStringLength ENDP

END     main

jj2007

Quote from: ProtoflareX on March 01, 2016, 06:39:34 AMdoes that mean that I need to write a procedure that "USES" EDX

Logic is OK. I can't guarantee, though, that the address is in edx because I don't have the Irvine library.

One instruction you will need is cmp byte ptr [edx], 0

\Masm32\help\opcodes.chm has details on cmp.

dedndave

Kip Irvine's library has a function called Get_length
it isn't the greatest code in the world, but the library source does show you how it works
it is invoked with an argument - not quite what the assignment asks for

as for EDX, i think WriteString preserves all registers, so EDX will remain unaltered

ProtoflareX

Quote from: dedndave on March 02, 2016, 01:13:22 AM
Kip Irvine's library has a function called Get_length
it isn't the greatest code in the world, but the library source does show you how it works
it is invoked with an argument - not quite what the assignment asks for

as for EDX, i think WriteString preserves all registers, so EDX will remain unaltered

In the time since my last post, I found out that Irvine's library also has an StrLength function that I'm pretty sure is exactly what the second bullet requires. It is pasted below. I think my current goal is to see if it is possible to alter the StrLength function in order to accomplish the third bullet's task which is: "Your program must have a procedure that accepts the address of a string and returns through EAX the amount of "words" the string contains. For the purposes of this project, consider a "word" to be any non-whitespace characters that are bounded by whitespace, or by the beginning or ending of the string".

StrLength PROC
;
; OBSOLETE???
; Returns the length of a null-terminated string.
; Receives: EDX points to the string.
; Returns: EAX = string length.
; Last update: 6/9/05
;---------------------------------------------------------
    push edx
    mov eax,0             ; holds character count

L1: cmp BYTE PTR [edx],0   ; end of string?
    je L2                  ; yes: quit
    inc edx                  ; no: point to next
    inc eax                  ; add 1 to count
    jmp L1

L2: pop edx
    ret
StrLength ENDP

ProtoflareX

#19
Currently, I have bullets 1-4 completed, but I'm stuck once again on bullet 5, which says the following: "Your program must have a main procedure that calls the input method, calls the other three methods
mentioned above, and reports the findings of those three methods. See the Sample Run" (I put a link to a picture of the Sample Run below). There isn't anything difficult about calling functions, but I have no idea how to display output, or put values from registers into the output message for that matter. Can anybody provide hints / tips on how to do this?

Picture of Sample Run: http://puu.sh/nsOat/92e5fe92c1.png

Current code below:

INCLUDE c:\irvine\irvine32.inc
INCLUDELIB c:\irvine\irvine32.lib
INCLUDELIB c:\masm32\lib\user32.lib
INCLUDELIB c:\masm32\lib\kernel32.lib

.data
theStringArray BYTE 256 dup(?)             
prompt BYTE "Please enter a String: ",0

.CODE

main PROC

    mov     edx,offset theStringArray
    mov     ecx,sizeof theStringArray
    call    requestInput
    call    getStringLength           
    call    getNumWords             
    call    getNumVowels             
    exit

main ENDP

requestInput PROC

    push    edx
    push    ecx
    mov     edx,offset prompt
    call      WriteString
    pop     ecx
    pop     edx
    call      ReadString
    ret

requestInput ENDP


getStringLength PROC

    push edx
    mov eax,0               

L1: cmp BYTE PTR [edx],0      
    je L2                
    inc edx                  
    inc eax                  
    jmp L1

L2: pop edx
    ret

getStringLength ENDP


getNumWords PROC

    push    edx
    mov eax,0                 

L1: cmp BYTE PTR [edx],0       
      je L3                  
      cmp BYTE PTR [edx]," "     
      je       L2
      inc     edx                   
      jmp    L1                   

L2: inc edx                
      inc eax                
      jmp L1

L3: pop edx
      ret

getNumWords ENDP


getNumVowels PROC

    push edx
    mov eax,0                 

L1: cmp BYTE PTR [edx],0      
      je L3                  
      cmp BYTE PTR [edx],"a"
      je       L2
      cmp BYTE PTR [edx],"A"
      je       L2
      cmp BYTE PTR [edx],"e"
      je       L2
      cmp BYTE PTR [edx],"E"
      je       L2
      cmp BYTE PTR [edx],"i"
      je       L2
      cmp BYTE PTR [edx],"I"
      je       L2
      cmp BYTE PTR [edx],"o"
      je       L2
      cmp BYTE PTR [edx],"O"
      je       L2
      cmp BYTE PTR [edx],"u"
      je       L2
      cmp BYTE PTR [edx],"U"
      je       L2
      inc edx                  ; no: point to next
      jmp L1

L2: inc edx                  
      inc eax                  
      jmp L1

L3: pop edx
      ret

getNumVowels ENDP

END     main