Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #1973

Re: Assembler Help.

From Martin Bazley <martin.bazley@blueyonder.co.uk>
Newsgroups comp.sys.acorn.programmer
Subject Re: Assembler Help.
Message-ID <66288ab952.martin@blueyonder.co.uk> (permalink)
References (8 earlier) <00b34021-c874-4533-b2ad-9524c021663a@fr28g2000vbb.googlegroups.com> <37e16fb452.martin@blueyonder.co.uk> <bff11025-77e6-41ef-b1f1-b43de621118a@e20g2000vbm.googlegroups.com> <e0d28eb452.martin@blueyonder.co.uk> <767aebe7-b606-4ee0-8f1c-15bd88403f16@w8g2000vbx.googlegroups.com>
Organization virginmedia.com
Date 2012-08-03 17:52 +0100

Show all headers | View raw


The following bytes were arranged on 3 Aug 2012 by Gazza :

> OK... Been getting on with a bit more, and I think I have most of the
> keying in completed. There are some sections of code that I'm not sure
> about and some things that I don't know how to do, so have insrted no
> ops (MOV R0,R0) and some comments on what should be happening. As
> usual, any help would be appreciated.

> AND R0,R0,#&FFFFFFFC

May I suggest "BIC R0,R0,#3"?  The BIC instruction (BIt Clear) does the
equivalent of AND NOT, which is useful for the common case of setting
certain bits to 0.

The MVN instruction just does the NOT without the AND.  However, you
should remember that MVN does not work the same way as CMN.  CMN takes
the negative of its second operand, but MVN just takes the inverse.
Therefore, to set R0 to -1, you use "MVN R0,#0".  But to compare R0 with
-1, you use "CMN R0,#1".

On the other hand, looking at the line above:

> ADD R0,R0,#15
> AND R0,R0,#&FFFFFFFC ; This might be the wrong way to interpret this.

Are you trying to align R0 to the next 16-byte boundary?  In that case,
you want:

ADD R0,R0,#15
BIC R0,R0,#15

> AND R2,R3,#3 ; Is R3 MOD 4 = 0?
> CMP R2,#0
> BNE ash_blkbfill_l2 ; If not, skip the check. (Word aligned load)

In general, if you ever use the instruction "CMP Rx,#0" in the middle
of a calculation, you're doing it wrong.

In most cases, including this one, you can save an instruction by using
the S suffix to set the flags:

ANDS R2,R3,#3
BNE ash_blkbfill_l2

The Z flag will be set if the contents of R2 after the AND operation are
0, which is exactly the test you were performing with the CMP
instruction.

Except I see you're not actually using the contents of R2 at all, which
means you're essentially wasting a register there.  If you're using ANDS
without any use for the destination register, you can condense it even
further to:

TST R3,#3
BNE ash_blkbfill_l2

Remember: CMP is the equivalent of SUBS without the result being stored
anywhere, TST is ANDS without a destination register, and TEQ is EORS.

> .ash_blksize
> STMFD SP!,{R1,R3}
> CMP R0,#0
> BLE ash_badblk
> MOV R3,R0
> SUB R3,R3,#4
> LDR R0,[R3],#4
> LDMFD SP!,{R1,R3}
> MOV PC,LR
> .ash_badblk
> CMP R1,#1<<31
> CMNVS R1,#1<<31
> LDMFD SP!,{R1,R3}
> MOV PC,LR

I'm not at all sure what you're trying to do here.  R3=R0, R3-=4,
R0=!R3, R3+=4?  And then you reset R3 back to its old value anyway?  And
you don't seem to be using R1 at all?

Wouldn't it be much simpler to do this:

.ash_blksize
CMP R0,#0
LDRNE R0,[R0,#-4]
CMPEQ R0,#1<<31 ; we know R0=0, so this always sets V
MOV PC,LR

Setting and clearing the V and C flags is a bit of a black art, but
there may well be a single instruction which sets the V flag if and only
if a register is 0.

> MOV R0,R0 ; R0=(R0+R1-1) AND NOT (R1-1)

Well, you're not using R1, so:

SUB R1,R1,#1
ADD R0,R0,R1
BIC R0,R0,R1

Was that really so difficult?

> MOV R0,R0 ; R3=R0 AND NOT R2.

BIC R3,R0,R2

Really?

> MOV R0,R0 ; Combine R3 & R4 to produce (xx.yy)

MOV R0,R4,R3,LSL #8

I repeat: Learning how to manipulate binary numbers is NOT optional.

Here, this is where I learned it from:

http://www.apdl.co.uk/riscworld/volume9/issue3/firstbasic/chap09.htm

-- 
  __<^>__   Red sky in the morning: Shepherd's warning
 / _   _ \  Red sky at night: Shepherd's delight
( ( |_| ) ) Mince and potatoes: Shepherd's pie
 \_>   <_/  ======================= Martin Bazley ==========================

Back to comp.sys.acorn.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Assembler Help. Gazza <usenet@garethlock.com> - 2012-07-10 07:09 -0700
  Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-07-10 08:46 -0700
    Re: Assembler Help. Chris Johnson <chrisjohnson+news@spamcop.net> - 2012-07-10 18:06 +0100
      Re: Assembler Help. jgharston <jgh@arcade.demon.co.uk> - 2012-07-11 11:26 -0700
        Re: Assembler Help. cferris@freeRemoveuk.com.invalid - 2012-07-11 20:05 +0100
          Re: Assembler Help. jgharston <jgh@arcade.demon.co.uk> - 2012-07-11 15:16 -0700
          Re: Assembler Help. Steve Drain <steve@kappa.me.uk> - 2012-07-12 10:25 +0100
            Re: Assembler Help. cferris@freeRemoveuk.com.invalid - 2012-07-13 09:23 +0100
              Re: Assembler Help. Steve Drain <steve@kappa.me.uk> - 2012-07-13 11:16 +0100
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-07-24 05:17 -0700
                Re: Assembler Help. Gavin Wraith <gavin@wra1th.plus.com> - 2012-07-24 14:02 +0100
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-07-24 06:49 -0700
                Re: Assembler Help. Steve Drain <steve@kappa.me.uk> - 2012-07-24 15:03 +0100
                Re: Assembler Help. usenet@garethlock.com - 2012-07-24 08:21 -0700
                Re: Assembler Help. Steve Drain <steve@kappa.me.uk> - 2012-07-24 17:55 +0100
                Re: Assembler Help. Theo Markettos <theom+news@chiark.greenend.org.uk> - 2012-08-03 20:26 +0100
                Re: Assembler Help. cferris@freeRemoveuk.com.invalid - 2012-08-05 08:51 +0100
                Re: Assembler Help. Martin Bazley <martin.bazley@blueyonder.co.uk> - 2012-07-24 20:04 +0100
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-07-24 14:16 -0700
                Re: Assembler Help. Jeremy Nicoll - news posts <jn.nntp.scrap007@wingsandbeaks.org.uk> - 2012-07-24 22:34 +0100
                Re: Assembler Help. Chris Johnson <chrisjohnson+news@spamcop.net> - 2012-07-24 23:56 +0100
                Re: Assembler Help. Martin Bazley <martin.bazley@blueyonder.co.uk> - 2012-07-25 01:42 +0100
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-03 05:54 -0700
                Re: Assembler Help. Martin Bazley <martin.bazley@blueyonder.co.uk> - 2012-08-03 17:52 +0100
                Re: Assembler Help. "Barry Allen (news)" <evanallen@onetel.net.uk.invalid> - 2012-08-04 10:21 +0100
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-04 15:57 -0700
                Re: Assembler Help. cferris@freeRemoveuk.com.invalid - 2012-08-05 08:48 +0100
                Re: Assembler Help. Martin <News03@avisoft.f9.co.uk> - 2012-08-06 10:00 +0100
                Re: Assembler Help. Theo Markettos <theom+news@chiark.greenend.org.uk> - 2012-08-06 13:26 +0100
                Re: Assembler Help. Martin <News03@avisoft.f9.co.uk> - 2012-08-06 23:13 +0100
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-07 08:50 -0700
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-07 15:43 -0700
                Re: Assembler Help. Martin Bazley <martin.bazley@blueyonder.co.uk> - 2012-08-08 00:52 +0100
                Re: Assembler Help. usenet@garethlock.com - 2012-08-08 02:03 -0700
                Re: Assembler Help. jeffrey.a.doggett@gmail.com - 2012-08-08 02:19 -0700
                Re: Assembler Help. druck <news@druck.org.uk> - 2012-08-12 09:05 +0100
                Re: Assembler Help. Frank de Bruijn <zuiderduin@hotmail.com> - 2012-08-08 11:40 +0200
                Re: Assembler Help. Jeremy Nicoll - news posts <jn.nntp.scrap007@wingsandbeaks.org.uk> - 2012-08-08 11:34 +0100
                Re: Assembler Help. Justin Fletcher <gerph@gerph.org> - 2012-08-09 21:19 +0100
                Re: Assembler Help. druck <news@druck.org.uk> - 2012-08-12 09:08 +0100
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-14 05:17 -0700
                Re: Assembler Help. Chris Johnson <chrisjohnson+news@spamcop.net> - 2012-08-14 14:50 +0100
                Re: Assembler Help. Martin Bazley <martin.bazley@blueyonder.co.uk> - 2012-08-14 15:03 +0100
                Re: Assembler Help. Martin Bazley <martin.bazley@blueyonder.co.uk> - 2012-08-14 14:59 +0100
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-15 17:01 -0700
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-21 03:54 -0700
                Re: Assembler Help. Martin <News03@avisoft.f9.co.uk> - 2012-08-21 12:27 +0100
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-21 05:08 -0700
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-21 05:25 -0700
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-21 08:23 -0700
                Re: Assembler Help. druck <news@druck.org.uk> - 2012-08-21 18:19 +0100
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-21 14:20 -0700
                Re: Assembler Help. cferris@freeRemoveuk.com.invalid - 2012-08-22 09:07 +0100
                Re: Assembler Help. Gazza <usenet@garethlock.com> - 2012-08-22 05:28 -0700
                Re: Assembler Help. Steve Fryatt <news@stevefryatt.org.uk> - 2012-08-22 14:47 +0100
                Re: Assembler Help. druck <news@druck.org.uk> - 2012-08-22 23:11 +0100
                Re: Assembler Help. Martin Bazley <martin.bazley@blueyonder.co.uk> - 2012-08-29 18:36 +0100
                Re: Assembler Help. Jeremy Nicoll - news posts <jn.nntp.scrap007@wingsandbeaks.org.uk> - 2012-08-22 09:38 +0100
                Re: Assembler Help. jgh@arcade.demon.co.uk (Jonathan Graham Harston) - 2012-08-08 23:15 +0100
                Re: Assembler Help. Martin Bazley <martin.bazley@blueyonder.co.uk> - 2012-08-09 13:59 +0100
                Re: Assembler Help. Steve Drain <steve@kappa.me.uk> - 2012-08-10 15:50 +0100
  Re: Assembler Help. Frank de Bruijn <zuiderduin@hotmail.com> - 2012-07-11 08:30 +0200
    Re: Assembler Help. cferris@freeRemoveuk.com.invalid - 2012-07-11 09:26 +0100

csiph-web