flat assembler
Message board for the users of flat assembler.

Index > DOS > Shortest access to two-dimensional array?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher
Hi All!
I attempted to obtain access to the single element of two-dimensional array 256x256, through registers using a minimum lines of code.
But I did not find such variants. Sad Rolling Eyes
What the way I must use to resolve this tasks Question
Post 04 Jun 2008, 17:10
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2942
Location: vpcmipstrm
bitRAKE
; assume x in CL
; assume y in CH
; assume upper word of ECX is zero
; assume array items are dword in size
; assume item needed in EAX
; assume everything because question was so vague Wink
mov eax, [array + ecx*4]

_________________
¯\(°_o)/¯ unlicense.org
Post 04 Jun 2008, 19:32
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17476
Location: In your JS exploiting you and your system
revolution
Ass-u-me 32bit code.
Ass-u-me DS segment.
Ass-u-me Intel syntax.
Ass-u-me reading the value only.
Post 05 Jun 2008, 03:48
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2942
Location: vpcmipstrm
bitRAKE
revolution wrote:
Ass-u-me reading the value only.
mov [array + ecx*4],eax

Write value, too. Laughing

(I did miss that this question is in the DOS section - 16-bit code is likely).
Code:
x rw 1 ; assume 0-255
y rw 1 ; assume 0-255

ITEM.bytes = 7
ITEM.row.paragraphs = 256/16 * ITEM.bytes

; assume DS is source segment
push ds
pop dx
imul ax,[y],ITEM.row.paragraphs
imul si,[x],ITEM.bytes
add dx,ax
push dx
pop ds
mov cx,ITEM.bytes
; assume destination address ES:DI setup
rep movsb    
...I'm just guessing at the above code.

_________________
¯\(°_o)/¯ unlicense.org


Last edited by bitRAKE on 05 Jun 2008, 06:27; edited 1 time in total
Post 05 Jun 2008, 05:58
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 701
Location: Adelaide
sinsi
How about:
- assume nothing
- 256*256=65536=64K
- in the DOS forum
- no 32-bit regs
- no nice SIB addressing
?

(nice to have some vague code tho')
Post 05 Jun 2008, 06:15
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2942
Location: vpcmipstrm
bitRAKE
The title is "Shortest access to two-dimensional array?" which requires a great deal more information, imho. We might assume he means shortest in time (everyone wants it faster), but it could be shortest in code length - fewest bytes? Lines of code can be mis-leading with a macro assembler - does he mean fewest instructions?

_________________
¯\(°_o)/¯ unlicense.org
Post 05 Jun 2008, 06:37
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 701
Location: Adelaide
sinsi
"using a minimum lines of code"
- I would ass-u-me the least amount of typing, in which case he's better off with C (or even basic), but a 657-line macro would do I guess... Very Happy

("Shortest access" - does this mean a byte, or a bit, or a qubit)
Post 05 Jun 2008, 06:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17476
Location: In your JS exploiting you and your system
revolution
There are so many assumptions already in this thread. bitRAKE assumed the OP is a "he". sinsi assumed no 32-bit allowed. revolution assumed we can all read English. Just shows it is impossible to avoid assumptions so don't bother trying.

The OP is very vague. A simple question that can have far too many permutations requires either, clarification from the OP, or, a myriad of assumptions from the repliers.

But I think that the A to the Q should be able to be gleaned from what has already been posted above. If the OP requires further input then please clarify precisely what you need to achieve.
Post 05 Jun 2008, 06:54
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17476
Location: In your JS exploiting you and your system
revolution
sinsi wrote:
- I would ass-u-me the least amount of typing, ...
The least amount of typing would easily be to post a Q on a BB and sit back and wait for someone else to type the answer for you. Evil or Very Mad

The least amount of thinking would be to buy an off-the-shelf program that already does what you need. Twisted Evil
Post 05 Jun 2008, 06:59
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 701
Location: Adelaide
sinsi
revolution wrote:
The least amount of typing would easily be to post a Q on a BB and sit back and wait for someone else to type the answer for you. Evil or Very Mad

Well, it's not working yet...(although I would hesitate in calling this forum a "BB" Laughing )
Post 05 Jun 2008, 07:11
View user's profile Send private message Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher
bitRAKE wrote:

...I'm just guessing at the above code.

Excuse me, I forgot give more detail... The large part of your guesses is correct.
16-bit code (use16)
DS-segment uses to array storage.
Items size equals to byte.
I implied the minimal size of the executable file.
Intel syntax too (is it possible to use in FASM unix syntax?).
About size of table I just mistaked yesterday Rolling Eyes ...
I generate four tables with dimension 16x16.
But I need minimize executable size to have an additional space in the segment so I will probably use additional tables...

But your sample is not compiled.
Post 05 Jun 2008, 09:16
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2942
Location: vpcmipstrm
bitRAKE
Please state where the indexes are located: memory and/or register? Also, what is the usage count for this snippet of code (roughly)? With a 4x16x16 structure it would be better to have (4x16)x16 rather than 4x(16x16) -- is that possible?

AAM/AAD can be used to unpack/pack indices from AX.

_________________
¯\(°_o)/¯ unlicense.org
Post 05 Jun 2008, 18:14
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
FASMresearcher wrote:
is it possible to use in FASM unix


AT\T , GAS ? IIRC NO Razz

> I generate four tables with dimension 16x16.

Code:
; ass-u-me FASM
; ass-u-me DOS 16-bit RM code (but DOS allows 32-bit as well)
; ass-u-me 8086 compatible code, MOVNTQ is not allowed Very Happy
; assume x in BL
; assume y in BH
; assume array items are byte in size
; assume read item needed in AL
; assume everything because question was so vague
...
; ass-u-me 256*256 table
mov al, [qqarray + bx]
...
; ass-u-me 16*16 table
shl  bh,4
or   bl,bh
mov  bh,0
mov  al, [qqarray + bx]
...
qqarray: db 5,6,7,3,5,67,24,5,155,255,0,9,7,2,6,4,3,5,67,3,5,67,77
...
    

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 05 Jun 2008, 23:22
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2942
Location: vpcmipstrm
bitRAKE
Assume array data at start of DS segment:
Code:
; AL = x [0,15]
; AH = y [0,15]
;      z [0,3]
aad 16
; (optional) mov ah,[z]
xchg ax,si
lodsb
; AL = item at (x,y)    
Four bytes. Wink

_________________
¯\(°_o)/¯ unlicense.org
Post 05 Jun 2008, 23:34
View user's profile Send private message Visit poster's website Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher
bitRAKE wrote:
Please state where the indexes are located: memory and/or register? Also, what is the usage count for this snippet of code (roughly)? With a 4x16x16 structure it would be better to have (4x16)x16 rather than 4x(16x16) -- is that possible?


Indexes have to be located in the registers (in the first procedure.) and temporarily saved into the memory (we can suppose I,J variables) to use the same values in the other procedures.
Yes, 4x16x16 is possible (moreover, preferably).
The additional tables must have a possibility to bite off the largeest piece of the segment, up to the end of the segment.
Post 06 Jun 2008, 10:28
View user's profile Send private message Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher
DOS386 wrote:

AT\T , GAS ? IIRC NO Razz

I had in mind AT/T syntax (DOS inaccessible).
But executable should be compatible with DOS. May be gas-like...
If this is possible, what incantations Laughing I must inscribe to have opportunity for using it?
Post 06 Jun 2008, 11:00
View user's profile Send private message Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher
bitRAKE wrote:
Assume array data at start of DS segment:
Code:
; AL = x [0,15]
; AH = y [0,15]
;      z [0,3]
aad 16
; (optional) mov ah,[z]
xchg ax,si
lodsb
; AL = item at (x,y)    
Four bytes. Wink

Wow! Thanks a lot! You hit the mark! I searched for the such kind of solution, exactly . Thanks! Very Happy Very Happy Very Happy Very Happy
Post 06 Jun 2008, 12:40
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2942
Location: vpcmipstrm
bitRAKE
If per chance DS cannot pointer to start of array data then an offset can be added to AX (which can be combined with loading AH with [z]).

label yx word
x rb 1
y rb 1
label zd word
d rb 1 ; offset to start of array data from DS
z rb 1

mov ax,[yx]
aad 16
add ax,[zd]
xchg ax,si
lodsb

There are some amazing 16-bit coders in the demoscene, or read through the Hugi Size Coding compos for some real eye openers.

_________________
¯\(°_o)/¯ unlicense.org
Post 07 Jun 2008, 04:19
View user's profile Send private message Visit poster's website Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher
Your remarks of course very apropos too Very Happy . Great thanks!
My task implies the absence DOS. The Real mode. Only BIOS interrupts are available. I use DOS only for debugging.
Certainly this heavy burden, but not heavier than our planet Smile !
Thanks for link. I did not investigate this site earlier.
Post 07 Jun 2008, 21:13
View user's profile Send private message Reply with quote
eek



Joined: 21 Oct 2006
Posts: 24
eek
Just use BASIC.
No one ever gets stuck with BASIC. Laughing
Post 08 Jun 2008, 20:26
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.