Author Topic: arm7 asm  (Read 6561 times)

0 Members and 2 Guests are viewing this topic.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
arm7 asm
« on: May 22, 2007 »
ive been tinkering around in arm7 asm lately as i never got round to learning it before and i was just wondering if anyone knew a way of creating an array in asmbler i think i need to create a table but im not sure how..

i need this array as a backbuffer for graphics mode 3 on the gba so i can do some double buffering.

all the good resources seem to have disapered  :(
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: arm7 asm
« Reply #1 on: May 22, 2007 »
Which assembler program are you using?  gas?

Something like
Code: [Select]
arrayname:
    .res.b    size
maybe.

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: arm7 asm
« Reply #2 on: May 22, 2007 »
im using gold road.

http://www.gbadev.org/tools.php?showinfo=192

it lets you write in pure asm for the game boy.
ive had a little look around an i see people doing stuff like this to hold there gfx and sin and cos tables.

Code: [Select]
tab
    @dcd  $00000000,$01000000,$00800000,$00555555
    @dcd  $00400000,$00333333,$002aaaaa,$00249249
    @dcd  $00200000,$001c71c7,$00199999,$001745d1
    @dcd  $00155555,$0013b13b,$00124924,$00111111
    @dcd  $00100000,$000f0f0f,$000e38e3,$000d7943
    @dcd  $000ccc0c,$000c30c3,$000ba2e8,$000b2164
    @dcd  $000aaaaa,$000a3d70,$0009d89d,$00097b42
    @dcd  $00092492,$0008d3dc,$00088888,$00084210
    @dcd  $00080000,$0007c1f0,$00078787,$00075075
    @dcd  $00071c71,$0006eb3e,$0006bca1,$00069069
    @dcd  $00066666,$00063e70,$00061861,$0005f417
    @dcd  $0005d174,$0005b05b,$000590b2,$00057262
    @dcd  $00055555,$00053978,$00051eb8,$00050505
    @dcd  $0004ec4e,$0004d487,$0004bda1,$0004a790
    @dcd  $00049249,$00047dc1,$000469ee,$000456c7
    @dcd  $00044444,$0004325c,$00042108,$00041041
    @dcd  $00040000,$0003f03f,$0003e0f8,$0003d226
    @dcd  $0003c3c3,$0003b5cc,$0003a83a,$00039b0a
    @dcd  $00038e38,$000381c0,$0003759f,$000369d0
    @dcd  $00035e50,$0003531d,$00034834,$00033d91

then in the registers they do something like
Code: [Select]
mov  r1,tab
ldr  r8,[r1,r0,lsl #2]

but that seemd like a long road for a short cut.

and prosuming i loaded my tab into r1 how would i go about accessing each ellement.
« Last Edit: May 22, 2007 by ninogenio »
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: arm7 asm
« Reply #3 on: May 22, 2007 »
Basic arithmetic load the address in r1, then to obtain the offset you need to know ...

 1) the size of each item (byte, word, double word)
 2) the specific item you want to access
 3) final address = first address + arrayitem*size (size is one for byte 2 for word etc)

But this is slow so you want to avoid random access for intensive loops instead set up r1 to point to the first item in the array and simply increase it by the appropriate ammount for each iteration of the loop. Of course you may have to access multidimensional arrays or even a portion of a multidimensional array such as part of a map. So find the offset of the first item on each line and put that in r1 after that its all sequencial again.

Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: arm7 asm
« Reply #4 on: May 23, 2007 »
cheers rain!

so will i have to create a dcd table the size and width of the array? ohh and one more thing im going to have to be able to write values to the array something in not to sure if you can do with dcd.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: arm7 asm
« Reply #5 on: May 23, 2007 »
No, there'll be a way to reserve an empty space without defining it all as zeros.  Just there's no documentation with that assembler so noone can help you!

<edit - snipped a completely wrong suggestion>

Code: [Select]
mov  r1,tab
ldr  r8,[r1,r0,lsl #2]
Might look like a lot, it does the same as
Code: [Select]
lea ecx,[tab+eax*4]
I bet the intel instruction is actually longer than the 2 or 3 arm ones (I think mov is a pseudo-op that is really 2 instructions).  The reason you can't do it in 1 instruction in ARM is because all the instructions are only 32bits wide (RISC) so it's impossible to encode the 32bit offset in a single instruction.

Jim
« Last Edit: May 23, 2007 by Jim »
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: arm7 asm
« Reply #6 on: May 23, 2007 »
cheers jim!

actually im thinking if i droped the the location of emty ram that i knew would have enough space into a register wouldnt it be possible to just poke and peek into that area to get in effect an array.

btw after having looked at some gas examples goldroad is virtually the same with just a slightly diffrenty format.
« Last Edit: May 23, 2007 by ninogenio »
Challenge Trophies Won:

Offline blasty

  • ZX 81
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
Re: arm7 asm
« Reply #7 on: June 13, 2007 »
I bet the intel instruction is actually longer than the 2 or 3 arm ones (I think mov is a pseudo-op that is really 2 instructions).  The reason you can't do it in 1 instruction in ARM is because all the instructions are only 32bits wide (RISC) so it's impossible to encode the 32bit offset in a single instruction.

Jim

That's not entirely true, You can do stuff like: mov r1, #0x40000000 perfectly fine in ARM. When the assembler encodes the instructions to the 32bit words, some operands are stored as (operand / 4). Offcourse this doesnt work for odd (number not divideable by 4) operands, where it has to store it in it's entirety. (I think it uses some bit in the opcode to let the CPU know the operand is divided by four or not, not 100% sure about this.)


PS. this was my first post! \o/

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: arm7 asm
« Reply #8 on: June 14, 2007 »
Hi Blasty!  Welcome to the forum.

You're right, some 32bit constants can be made from the limited (is it 12bit?) range of immediate values using the optional shifts.
ARM's documentation is a mess.
http://www.arm.com/documentation/Instruction_Set/index.html

Jim
Challenge Trophies Won: