A computer components & hardware forum. HardwareBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » HardwareBanter forum » Processors » Intel
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

3 strings operations: zip.



 
 
Thread Tools Display Modes
  #1  
Old November 25th 08, 02:19 AM posted to comp.lang.asm.x86,alt.os.assembly,alt.lang.asm,comp.sys.intel
HiSt
external usenet poster
 
Posts: 1
Default 3 strings operations: zip.

Hello!


I am programming 8086 assembler.

I would like to know which is the
standard way of operating 3 strings,
since there were only 2 segment
registers available (DS and ES).

The problem was trying to implement
a "zip" function of 2 strings of Bytes.
string A: a0,a1,a2, ...
string B: b0,b1,b2, ...
Calling string C=zip(A,B) interlaces
the Bytes of both strings to:
string C: a0,b0,a1,b1,a2,b2,a3,b3, ...

The easiest would be to have three
[segmentffset] pointers; 2 to each
sources and 1 to the destination string.
Example:

mov cx,sizeOfStrings
zip:
mov al,[ds:si]
mov ah,[es:di]
mov [fs:ei],ax
inc si
inc di
add ei,2
loopnz zip

We miss 1 segmentffset registers
for a C=A+B operation.



Greetings,
Herman Samso )

  #2  
Old November 25th 08, 05:06 AM posted to comp.lang.asm.x86,alt.os.assembly,alt.lang.asm,comp.sys.intel
Tim Roberts
external usenet poster
 
Posts: 2
Default 3 strings operations: zip.

HiSt wrote:

I am programming 8086 assembler.

I would like to know which is the
standard way of operating 3 strings,
since there were only 2 segment
registers available (DS and ES).

The problem was trying to implement
a "zip" function of 2 strings of Bytes.
string A: a0,a1,a2, ...
string B: b0,b1,b2, ...
Calling string C=zip(A,B) interlaces
the Bytes of both strings to:
string C: a0,b0,a1,b1,a2,b2,a3,b3, ...
...
We miss 1 segmentffset registers
for a C=A+B operation.


You're right, there is no good solution. And, loading a segment register
is a very expensive operation. So, you end up getting more creative. For
example, in this case, you'd copy string A to string C, skipping bytes in
between. Then, you'd go back and fill in string B.
--
Tim Roberts,
Providenza & Boekelheide, Inc.

  #3  
Old November 25th 08, 01:25 PM posted to comp.lang.asm.x86,alt.os.assembly,alt.lang.asm,comp.sys.intel
lavron
external usenet poster
 
Posts: 1
Default 3 strings operations: zip.

On Nov 24, 9:19*pm, HiSt wrote:
Hello!

I am programming 8086 assembler.

I would like to know which is the
standard way of operating 3 strings,
since there were only 2 segment
registers available (DS and ES).

The problem was trying to implement
a "zip" function of 2 strings of Bytes.
string A: a0,a1,a2, ...
string B: b0,b1,b2, ...
Calling string C=zip(A,B) interlaces
the Bytes of both strings to:
string C: a0,b0,a1,b1,a2,b2,a3,b3, ...

The easiest would be to have three
[segmentffset] pointers; 2 to each
sources and 1 to the destination string.
Example:

* mov cx,sizeOfStrings
zip:
* mov al,[ds:si]
* mov ah,[es:di]
* mov [fs:ei],ax
* inc si
* inc di
* add ei,2
* loopnz zip

We miss 1 segmentffset registers
for a C=A+B operation.

Greetings,
Herman Samso )



Is there any reason why the three strings must reside in three
different segments? If all three reside in the same segment there is
no need to manipulate the segment registers after their
initialization, and only the [E]SI and [E]DI general registers need to
be taken care of.

  #4  
Old November 25th 08, 02:29 PM posted to alt.os.assembly,alt.lang.asm,comp.sys.intel
Tom Lake
external usenet poster
 
Posts: 418
Default 3 strings operations: zip.


Is there any reason why the three strings must reside in three
different segments? If all three reside in the same segment there is
no need to manipulate the segment registers after their
initialization, and only the [E]SI and [E]DI general registers need to
be taken care of.


Aren't you limited to 64K string length that way?

Tom Lake
  #5  
Old November 25th 08, 07:13 PM posted to comp.lang.asm.x86,alt.os.assembly,alt.lang.asm,comp.sys.intel
Terje Mathisen[_2_]
external usenet poster
 
Posts: 1
Default 3 strings operations: zip.

lavron wrote:
On Nov 24, 9:19 pm, HiSt wrote:
Hello!

I am programming 8086 assembler.

I would like to know which is the
standard way of operating 3 strings,
since there were only 2 segment
registers available (DS and ES).

The problem was trying to implement
a "zip" function of 2 strings of Bytes.
string A: a0,a1,a2, ...
string B: b0,b1,b2, ...
Calling string C=zip(A,B) interlaces
the Bytes of both strings to:
string C: a0,b0,a1,b1,a2,b2,a3,b3, ...

The easiest would be to have three
[segmentffset] pointers; 2 to each
sources and 1 to the destination string.
Example:

mov cx,sizeOfStrings
zip:
mov al,[ds:si]
mov ah,[es:di]
mov [fs:ei],ax
inc si
inc di
add ei,2
loopnz zip

We miss 1 segmentffset registers
for a C=A+B operation.

Greetings,
Herman Samso )



Is there any reason why the three strings must reside in three
different segments? If all three reside in the same segment there is
no need to manipulate the segment registers after their
initialization, and only the [E]SI and [E]DI general registers need to
be taken care of.


Even if the interface specifies individual segments for each of the
three operands, it could still make a lot of sense to check if two of
them are identical, and if so use the much faster code that becomes
available.

Otherwise you fall back on copying with interleaving, i.e. go through
the destination twice.

A third option is to set aside a short buffer (256-4096 bytes) in the
stack segment and use that as a the target for the interleave, then copy
each finished block to the real destination.

next_block:
lds si,[a]
les di,[b]
sub di,si
sub di,2

mov cx,256 ; 1 K stack buffer
sub [size], cx
jb do_tail_end
pairs:
lodsw ax,[si] ; a0,a1
mov dx,[di+si] ; b0,b1
xchg ah,dl ; a0,b0 a1,b1
mov [bp],ax
mov [bp+2],dx
add bp,4
loop pairs

mov word ptr [a],si
push ss
pop ds
les di,[target]
mov cx,512
rep movsw
jmp next_block

(There are some issues still, like all parameters need to be in
static/code-based memory. Fixing this means taking care to save/restore
BP between each block.)

A final option would be check if one of the operands happens to be
located in the stack segment, and if so use that as the relevant segment!

Terje

--
-
"almost all programming can be viewed as an exercise in caching"

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A.M.D. to Split Into Two Operations Jan Panteltje General 57 October 18th 08 03:50 PM
The Information Operations Roadmap Guy Homebuilt PC's 0 February 23rd 06 02:34 AM
problems with Ultra DMA operations Eug Storage (alternative) 2 June 13th 05 01:31 PM
problems with Ultra DMA operations Eug Storage & Hardrives 0 June 1st 05 07:17 AM
Kyocera and Control Strings? David Printers 0 November 20th 03 08:25 AM


All times are GMT +1. The time now is 06:19 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 HardwareBanter.
The comments are property of their posters.