News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Table

Started by ecube, July 16, 2009, 11:08:57 PM

Previous topic - Next topic

ecube

I have a list of numbers I need to compare another number against, how do I put them in a table, loop through n compare? or whats the easiest way to do this?

dedndave

what kind of numbers ?
what form are they in now ? (paper/file/binary/floats/ascii/etc)
if possible post the list, or part of it

ecube

numbers like

484823
321211
333
2912

they're not float, all regular dwords

dedndave

well - if they are in a program (generated or in memory), it shouldn't be too difficult to compare them
if they are on paper, it may depend on how many values are in the list
you say you want to compare them to a single value ?
do you want to know the difference for each number in the list - or just want to know if one or more a equal ?
you want to sort them ?
if this is a word problem, you aren't giving us enough information to find a solution

ecube

I just want a predefined table or a way to have the numbers in a list n be able to loop through each one, what I do after that I can handle myself.

ecube

maybe a simple

value dd 3838
        dd 3123
        dd 5

will work, I tried multiplying this by 4 to get to the next value with no luck

dedndave


        .data

Values  dd 3838
        dd 3123
        dd 5
        dd ?
        dd ?
        dd ?

        .code
.
.
.
        mov     esi,offset Values
        mov     edi,offset Values+12
        mov     ecx,3

Loop00: lodsd
        shl     eax,2
        stosd
        loop    Loop00
.
.
.

LODSD gets a dword into EAX from [ESI], then adds 4 to the ESI register
STOSD stores a dword from EAX to [EDI], then adds 4 to the EDI register
that is if the direction flag is cleared (it usually is)
if you set the direction flag, LODSD and STOSD decrement the index registers
see also SCAS, CMPS, MOVS, REP, CLD, STD
all of these instructions can work with bytes, words, or dwords (LODSB, LODSW, LODSD)

ecube


ecube

when I try


testproc proto :DWORD
.data?
table dd 1234
        dd 2341
        dd 3

buff db 255 dup(?)
.code
start:
invoke testproc,offset table
invoke ExitProcess,0

testproc proc iVal:DWORD
mov esi,iVal
invoke dwtoa,esi,addr buff
ret
testproc endp


end start

it doesn't give the right result? i've tried

mov esi,[iVal+4]

mov ecx,[iVal]
mov eax,4
mul ecx


aswell and still no right result

hutch--

cube,

You can normally do this with tables.


.data
  table dd 1234, 5678,9012,3456
         dd etc ....


Use "OFFSET table" for the start address then just increment the address by 4 for each read.

If you want to use dynamically allocated memory just plonk the return address into a variable then write the data sequentially to it (from a file or similar) then read it back in whatever order you like from its start address + item count * 4.


Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

also good to know....

        mov     esi,offset SomeLabel

works for labels or other addresses that the assembler is aware of at assembly time

if it is a local variable or otherwise addressed via registers...

        lea     esi,LocalVariable

or

        lea     esi,[ebx+4]    ;calculates the equiv address of ebx+4 and places it in esi

NightWare

testproc proc iVal:DWORD
mov esi,iVal
mov eax,dword ptr [esi]
invoke dwtoa,eax,addr buff
ret
testproc endp

you want the value, not the address, no ?

ecube

the dword ptr fixed it, thankyou gentlemen.  :U

Slugsnack

if you want a faster method you can always try some ADTs like.. binary tree would be good for that one

ecube

Slugsnack can you elaborate on what a binary tree is and why its faster? I mean we're loopin through dwords, how can you move any faster? I've always been curious how databases operate so fast, but been strugglin to find an answer.