Re: get cl number of bytes




----- Original Message -----
From: "Benjamin David Lunt" <spamtrap@xxxxxxxxxx>
Newsgroups: comp.lang.asm.x86
Sent: Friday, September 15, 2006 4:26 PM
Subject: get cl number of bytes

"Benjamin David Lunt" <spamtrap@xxxxxxxxxx> wrote in message
news:b0EOg.691$ya1.165@xxxxxxxxxxxxxxxx

Hi,

I have come across this a number of times and have always
come up with a different version. It is the simple idea
that you need to copy/move/retrieve ecx bytes a dword
at a time.

However, if ecx is not a multiple of size dword, you have
to 'and ecx,3' and get cl number of bytes on the tail end.

There seems to be multiple ways:
(assuming edi -> next location, and we want eax to contain
the cl number of bytes.)

xor eax,eax
and cl,3
jz short none
@@: shl eax,8
mov al,[edi]
inc edi
loop @b

However, now eax contains cl bytes in Big Endian order, so
a byte swap instruction is needed.

Another way could be:

and cl,3
jz short none
mov eax,[edi]
cmp cl,3
jne short @f
and eax,00FFFFFFh
jmp short done
@@: cmp cl,2
.
.
.

This makes for a lot of code and jumps.

I am currently using:

and cl,3
jz short none
shl cl,3
mov edx,-1
shl edx,cl
not edx
mov eax,[edi]
and eax,edx

If the processor would actually shift 32 bits, I could
dispense with the jump :-)

Maybe I am missing something here, but isn't there an easier,
least amount of code way of doing this?

Please note I am not using anything more than a 386.


Since I'm not too familiar with the various special instructions or 386
tricks, my basic attempt would be this:

and cl,3 ; get low bits
xor cl,3 ; invert so 0,1,2,3 is 3,2,1,0
shl cl,3 ; multiply by eight
mov edx,0x00FFFFFF ; setup mask
shr edx,cl ; right shift mask by 24,16,8,0 for 0,1,2,3
mov eax,[edi]
and eax,edx


Rod Pemberton

PS. In regards to our prior conversations, I was using open newservers to
post to a.o.d. and I haven't been able to post there for a while... I sent
the following on our prior thread there, but it didn't propagate very well:

Good news: The moved A20 code works on the "difficult" machine.

Bad news 1: Your bootloader seems to access two words (4 bytes) beyond the
512 bytes loaded to 7c00h. It appears you're saving si,di for something to
do with the harddisk. Unfortunately, if those valuse aren't zeroed, floppy
loads fail. This means that you've
1) used them in the floppy calculations for CHS
2) assumed they will be zero for floppies.
I stumbled across this because a utility which reboots A: from DOS only
cleared 512 bytes instead of the 516 your bootloader needs.

Bad news 2: Your install program on occassion goes into what I'll call
"quad speed mode," whereby it moves the floppy heads four times quickly
(instead of one time slowly - normal) but increments the track counter by
one. It then fails on track 11... I don't know what causes this (and still
don't). It seems to run properly if rerun.


Rod Pemberton

.



Relevant Pages

  • PutPixel v2.0
    ... keep using the SHL opcode, which performs an extremely fast power of ... Now, for use with a specific resolution, the best, fastest code would ... cells di mov \ buffer address to EDI ... The Y*320 calculation is performed by a pair of SHL (bit shift left) ...
    (comp.lang.forth)
  • Re: A little help needed with debug and int 0x13
    ... >little bootloader to load the program into memory and run it. ... >either not reading from the floppy correctly, ... > mov ax, 0x0201 ... cylinder 0, head 0, sector 1. ...
    (comp.lang.asm.x86)
  • Re: Shift in Parallel?
    ... right shift instruction that they can overhead with x86 CPU time. ... mov bl,bit6 ... lea eax, ... shl al,1 ...
    (comp.lang.asm.x86)
  • Re: COMPARE HLL/ASM
    ... MOV eax 0 ... shl al,4 |or al ah ... SHR eax,4 ...
    (alt.lang.asm)
  • Re: talking to CTK 571 synthesizer
    ... memory area and write it to the floppy in prescribed places. ... The routine wout is also from lilo and writes the contents ... mov ax,#0xa000 ...
    (comp.sys.ibm.pc.hardware.misc)