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, April 05, 2016, 07:33:50 AM

Previous topic - Next topic

ProtoflareX

I posted a topic similar to this some time ago and received the help I needed to get me started on a project that I was having trouble with. I am currently in a similar situation and need some help getting started with a second project that I have been assigned by my professor. An image of the first of several requirements for the project is pasted below.



My current code is the following:

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


.data
theSINTArray BYTE 25 dup(?)             
prompt BYTE "Please enter a value: ",0

MAX = 10                     ;max chars to read from input
stringIn BYTE MAX+1 DUP (?)  ;room for null

   
.CODE

main PROC

    push    TYPE theSINTArray
    push    LENGTHOF theSINTArray
    push    OFFSET theSINTArray
    call    requestInput
    exit

main ENDP

requestInput PROC

    push    edx
    push    ecx
    mov     edx,OFFSET prompt
    call    WriteString
    mov     edx,OFFSET stringIn
    mov     ecx,MAX                ;buffer size - 1
    call    ReadString
    pop     ecx
    pop     edx
    ret

requestInput ENDP


END     main


The first thing I would like assistance with is altering my current code so that it stores the input signed integers into theSINTArray, like it says to in the requirement. This is where I'm stuck. Is there anybody who can provide assistance on how to do this? As a sidenote, I am using the masm32 assembler (as you probably guessed) as well as Irvine's library.



K_F

With array, you have :

1) A Base pointer that points to the beginning of the array
2) an index which points to any member of the array (you control this)

So You'll be looking at something like

ThisArray      DD     25 DUP (0)   ; An array of 25 Dwords
ThisIndex     DD     0                  ; Index pointer into the array

You'll need a  BASE address of the array..

mov         EDI, OFFSET ThisArray      ; Both these lines give you a Base address
LEA          EDI, ThisArray                  ; but are used in different circumstances

XOR         EBX,EBX                           ;Resets the index pointer
MOV         ThisIndex, EBX


So as you enter values into the array - EAX is usually the workhorse register and you now want to place the values (EAX) onto the array index (EBX)

MOV       [EDI + EBX*4], EAX           ; Have a look at [Index addressing] with regard to the formats (Final Address = Base + Index * Scale)

Don't forget your limit checks on the Index numbers
:biggrin:



'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

ProtoflareX

Thank you for your assistance, K_F. I do not have time to work on the project currently, but I will be using your post for assistance when I work on it over the weekend.