Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

You're already carrying the sphere!


programming / alt.lang.asm / loop cx

SubjectAuthor
* loop cxT. Ment
+* Re: loop cxHerbert Kleebauer
|`- Re: loop cxT. Ment
+* Re: loop cxJJ
|`- Re: loop cxT. Ment
`* Re: loop cxwolfgang kern
 `- Re: loop cxT. Ment

1
Subject: loop cx
From: T. Ment
Newsgroups: alt.lang.asm
Organization: A noiseless patient Spider
Date: Mon, 24 Feb 2020 17:30 UTC
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: t.m...@protocol.invalid (T. Ment)
Newsgroups: alt.lang.asm
Subject: loop cx
Date: Mon, 24 Feb 2020 17:30:24 +0000
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <j8185f177pu2rfhjr69e4gpuknf215stti@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="56f5c5d49f1c9db523add63a595ea2e4";
logging-data="313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9Qh1WE0BlE29lo4it/eThptZRmryQPiQ="
Cancel-Lock: sha1:y0bvjdXvxDypTqZUIANp04eodNg=
X-Newsreader: Forte Agent 1.93/32.576 English (American)
View all headers
Say you have

xor cx, cx ; set cx=0
a1: nop ; body of loop
nop
loop a1


Does the body of the loop run 64k times, or 64k-1?

It was not obvious to me, I had to analyze it. Anyone want to guess, or
already know?




Subject: Re: loop cx
From: Herbert Kleebauer
Newsgroups: alt.lang.asm
Organization: Aioe.org NNTP Server
Date: Mon, 24 Feb 2020 18:35 UTC
References: 1
Path: i2pn2.org!i2pn.org!aioe.org!.POSTED.S8T8eQ/93aYmotZlmUxnHA.user.gioia.aioe.org!not-for-mail
From: kle...@unibwm.de (Herbert Kleebauer)
Newsgroups: alt.lang.asm
Subject: Re: loop cx
Date: Mon, 24 Feb 2020 19:35:44 +0100
Organization: Aioe.org NNTP Server
Lines: 25
Message-ID: <r3151v$r6j$1@gioia.aioe.org>
References: <j8185f177pu2rfhjr69e4gpuknf215stti@4ax.com>
NNTP-Posting-Host: S8T8eQ/93aYmotZlmUxnHA.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101
Thunderbird/68.5.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
View all headers
On 24.02.2020 18:30, T. Ment wrote:
Say you have

xor cx, cx ; set cx=0
a1: nop ; body of loop
nop
loop a1


Does the body of the loop run 64k times, or 64k-1?



Why didn't you read the manual?

LOOP (Loop While ECX Not Zero) is a conditional transfer that automatically
decrements the ECX register before testing ECX for the branch condition. If
ECX is non-zero, the program branches to the target label specified in the
instruction. The LOOP instruction causes the repetition of a code section
until the operation of the LOOP instruction decrements ECX to a value of
zero. If LOOP finds ECX=0, control transfers to the instruction immediately
following the LOOP instruction. If the value of ECX is initially zero, then
the LOOP executes 2^(32) times.




Subject: Re: loop cx
From: JJ
Newsgroups: alt.lang.asm
Organization: albasani.net
Date: Mon, 24 Feb 2020 18:39 UTC
References: 1
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!news.albasani.net!.POSTED!not-for-mail
From: jj4pub...@vfemail.net (JJ)
Newsgroups: alt.lang.asm
Subject: Re: loop cx
Date: Tue, 25 Feb 2020 01:39:16 +0700
Organization: albasani.net
Lines: 23
Message-ID: <1r8v73g4nqv3q.s3y1ksylw96n.dlg@40tude.net>
References: <j8185f177pu2rfhjr69e4gpuknf215stti@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.albasani.net IeuS7xKDcoSxCECnf2cKJXjlfXH6u5frV3nkBKoeUn+3NBL9ml+nRXlPM9hBCBcheHwWocYEoeCJD7vKAm47Kw==
NNTP-Posting-Date: Mon, 24 Feb 2020 18:39:14 +0000 (UTC)
Injection-Info: news.albasani.net; logging-data="dYJMUxITC+gmCikE60K+I2fO+EG8w5hj6L+dpbT+4Z9M7u1FS15iNfs1McFFd1xskQ4pYIZCnTyp6cHcAnQ5Aysioxe0269IlApYQcRc72lG2C+V1cS1L1zBUJqVystg"; mail-complaints-to="abuse@albasani.net"
User-Agent: 40tude_Dialog/2.0.15.84
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
Cancel-Lock: sha1:ZxXGryHMiG2QwfYyZ9BX5mWxobU=
View all headers
On Mon, 24 Feb 2020 17:30:24 +0000, T. Ment wrote:
Say you have

xor cx, cx ; set cx=0
a1: nop ; body of loop
nop
loop a1

Does the body of the loop run 64k times, or 64k-1?

It was not obvious to me, I had to analyze it. Anyone want to guess, or
already know?

`loop` won't loop when CX is one prior the execution, so that'll be 65535.
But because the body is executed before the first `loop` instruction
execution, add it by one, so it's 65536. Otherwise with code like below,
it'll be only 65535.

xor cx, cx ; set cx=0
        jmp a2
a1: nop ; body of loop
nop
a2: loop a1


Subject: Re: loop cx
From: T. Ment
Newsgroups: alt.lang.asm
Organization: A noiseless patient Spider
Date: Mon, 24 Feb 2020 18:59 UTC
References: 1 2
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: t.m...@protocol.invalid (T. Ment)
Newsgroups: alt.lang.asm
Subject: Re: loop cx
Date: Mon, 24 Feb 2020 18:59:13 +0000
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <i1785fhl0e7r44h4slp9h7gqs996lil27l@4ax.com>
References: <j8185f177pu2rfhjr69e4gpuknf215stti@4ax.com> <r3151v$r6j$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="56f5c5d49f1c9db523add63a595ea2e4";
logging-data="2350"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lxtnffS/6YPPILKXJc0+r59rYUhwpUww="
Cancel-Lock: sha1:1pnzcA7bWQekh9UZIk9GWXWZaI8=
X-Newsreader: Forte Agent 1.93/32.576 English (American)
View all headers
On Mon, 24 Feb 2020 19:35:44 +0100, Herbert Kleebauer wrote:

Why didn't you read the manual?

You can't trust everything printed in a manual. Except the Bible.




Subject: Re: loop cx
From: T. Ment
Newsgroups: alt.lang.asm
Organization: A noiseless patient Spider
Date: Mon, 24 Feb 2020 19:16 UTC
References: 1 2
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: t.m...@protocol.invalid (T. Ment)
Newsgroups: alt.lang.asm
Subject: Re: loop cx
Date: Mon, 24 Feb 2020 19:16:05 +0000
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <j8785f1q6o8b2td8uqcr02clb2t05pr9nk@4ax.com>
References: <j8185f177pu2rfhjr69e4gpuknf215stti@4ax.com> <1r8v73g4nqv3q.s3y1ksylw96n.dlg@40tude.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="56f5c5d49f1c9db523add63a595ea2e4";
logging-data="9226"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8hlR3sHt0WX1WKhDx16F4sBlwWSV79pE="
Cancel-Lock: sha1:Mz80vWJhOBaL7k8lux5MriGPvX4=
X-Newsreader: Forte Agent 1.93/32.576 English (American)
View all headers
On Tue, 25 Feb 2020 01:39:16 +0700, JJ wrote:

`loop` won't loop when CX is one prior the execution

Right. You can see that with a debugger. That proves cx is decremented
before it's tested.

Thus the initial value of cx is how many times the BODY will run. If you
set cx = 65535, that will be 64k-1. To get one more iteration (64k), add
1, which rolls cx over to 0. Thus 0 is equivalent to 64k for purposes of
the loop instruction.

I can remember the proof. Just reading it in a manual, I'll forget that
in a few weeks. It may seem trivial, but the wrong answer can produce an
off by one error, depending on what you are trying to do.




Subject: Re: loop cx
From: wolfgang kern
Newsgroups: alt.lang.asm
Organization: KESYS-development
Date: Thu, 27 Feb 2020 09:30 UTC
References: 1
Path: i2pn2.org!i2pn.org!aioe.org!.POSTED.6PzWnnDFJJxIKVn72M75wQ.user.gioia.aioe.org!not-for-mail
From: nowh...@never.at (wolfgang kern)
Newsgroups: alt.lang.asm
Subject: Re: loop cx
Date: Thu, 27 Feb 2020 10:30:24 +0100
Organization: KESYS-development
Lines: 18
Message-ID: <r382j2$kjl$1@gioia.aioe.org>
References: <j8185f177pu2rfhjr69e4gpuknf215stti@4ax.com>
Reply-To: nowhere@never.at
NNTP-Posting-Host: 6PzWnnDFJJxIKVn72M75wQ.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:66.0) Gecko/20100101
Thunderbird/66.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
View all headers
On 24.02.2020 18:30, T. Ment wrote:
Say you have

xor cx, cx ; set cx=0
a1: nop ; body of loop
nop
loop a1


Does the body of the loop run 64k times, or 64k-1?

It was not obvious to me, I had to analyze it. Anyone want to guess, or
already know?

LOOP with cx=0 iterates 65536
REP  with cx=0 falls through
__
wolfgang


Subject: Re: loop cx
From: T. Ment
Newsgroups: alt.lang.asm
Organization: A noiseless patient Spider
Date: Thu, 27 Feb 2020 13:58 UTC
References: 1 2
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: t.m...@protocol.invalid (T. Ment)
Newsgroups: alt.lang.asm
Subject: Re: loop cx
Date: Thu, 27 Feb 2020 13:58:44 +0000
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <qkif5f55baobuvncj3d5nn9ek186la0280@4ax.com>
References: <j8185f177pu2rfhjr69e4gpuknf215stti@4ax.com> <r382j2$kjl$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="0c4cccc6306a3ce3e1e67388a2291699";
logging-data="16344"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+KFjRAXOrpe8LxLgGPsZxx3Q/xA57r8A8="
Cancel-Lock: sha1:f/UdZzRpnpb3DgdY8sRYE9c1T6I=
X-Newsreader: Forte Agent 1.93/32.576 English (American)
View all headers
On Thu, 27 Feb 2020 10:30:24 +0100, wolfgang kern wrote:

LOOP with cx=0 iterates 65536
REP  with cx=0 falls through

I didn't think of that. Good to know the difference.




1
rocksolid light 0.7.2
clearneti2ptor