Re: get cl number of bytes
- From: "Rod Pemberton" <spamtrap@xxxxxxxxxx>
- Date: Sat, 16 Sep 2006 03:20:02 -0400
----- 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
.
- References:
- get cl number of bytes
- From: Benjamin David Lunt
- get cl number of bytes
- Prev by Date: Re: Hex to ascii
- Next by Date: Re: get cl number of bytes
- Previous by thread: get cl number of bytes
- Next by thread: Re: get cl number of bytes
- Index(es):
Relevant Pages
|
|