flat assembler
Message board for the users of flat assembler.
Index
> DOS > Shortest access to two-dimensional array? Goto page 1, 2 Next |
Author |
|
bitRAKE 04 Jun 2008, 19:32
; 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 mov eax, [array + ecx*4] _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
04 Jun 2008, 19:32 |
|
revolution 05 Jun 2008, 03:48
Ass-u-me 32bit code.
Ass-u-me DS segment. Ass-u-me Intel syntax. Ass-u-me reading the value only. |
|||
05 Jun 2008, 03:48 |
|
bitRAKE 05 Jun 2008, 05:58
revolution wrote: Ass-u-me reading the value only. Write value, too. (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 _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup Last edited by bitRAKE on 05 Jun 2008, 06:27; edited 1 time in total |
|||
05 Jun 2008, 05:58 |
|
sinsi 05 Jun 2008, 06:15
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') |
|||
05 Jun 2008, 06:15 |
|
bitRAKE 05 Jun 2008, 06:37
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)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
05 Jun 2008, 06:37 |
|
sinsi 05 Jun 2008, 06:47
"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... ("Shortest access" - does this mean a byte, or a bit, or a qubit) |
|||
05 Jun 2008, 06:47 |
|
revolution 05 Jun 2008, 06:54
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. |
|||
05 Jun 2008, 06:54 |
|
revolution 05 Jun 2008, 06:59
sinsi wrote: - I would ass-u-me the least amount of typing, ... The least amount of thinking would be to buy an off-the-shelf program that already does what you need. |
|||
05 Jun 2008, 06:59 |
|
sinsi 05 Jun 2008, 07:11
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. Well, it's not working yet...(although I would hesitate in calling this forum a "BB" ) |
|||
05 Jun 2008, 07:11 |
|
FASMresearcher 05 Jun 2008, 09:16
bitRAKE wrote:
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 ... 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. |
|||
05 Jun 2008, 09:16 |
|
bitRAKE 05 Jun 2008, 18:14
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)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
05 Jun 2008, 18:14 |
|
DOS386 05 Jun 2008, 23:22
FASMresearcher wrote: is it possible to use in FASM unix AT\T , GAS ? IIRC NO > 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 ; 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 |
|||
05 Jun 2008, 23:22 |
|
bitRAKE 05 Jun 2008, 23:34
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) _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
05 Jun 2008, 23:34 |
|
FASMresearcher 06 Jun 2008, 10:28
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. |
|||
06 Jun 2008, 10:28 |
|
FASMresearcher 06 Jun 2008, 11:00
DOS386 wrote:
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 I must inscribe to have opportunity for using it? |
|||
06 Jun 2008, 11:00 |
|
FASMresearcher 06 Jun 2008, 12:40
bitRAKE wrote: Assume array data at start of DS segment: Wow! Thanks a lot! You hit the mark! I searched for the such kind of solution, exactly . Thanks! |
|||
06 Jun 2008, 12:40 |
|
bitRAKE 07 Jun 2008, 04:19
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)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
07 Jun 2008, 04:19 |
|
FASMresearcher 07 Jun 2008, 21:13
Your remarks of course very apropos too . 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 ! Thanks for link. I did not investigate this site earlier. |
|||
07 Jun 2008, 21:13 |
|
eek 08 Jun 2008, 20:26
Just use BASIC.
No one ever gets stuck with BASIC. |
|||
08 Jun 2008, 20:26 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.