gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > forgive me for being an IDIOT

#7917 - superx10 - Sat Jun 28, 2003 5:34 pm

alright, i read stuff on here about how to make functions in a .S file and how to do inline asm (like http://forum.gbadev.org/viewtopic.php?t=1430 ) and i've tried both but I cant seem to get it to work.. a couple of times i've started to say |= (_) ( |< it and code entirely in c again.. but then when i realized how slow it would be i've gone back to trying to get this to work

i mean, i dont want to code in pure asm either..
_________________
"Two wolves are fighting. One wolf is all evil, hate, jealousy and discontent, and the other good, love, happiness and is content." "Sounds like a tough battle. Who wins?" said the old man. “The one I feed”

#7919 - tepples - Sat Jun 28, 2003 6:00 pm

Here's a sample .s file, taken straight from TOD.

Code:
@ fixed fastfmul(fixed x, fixed y)
@ Multiply two 16.16 fixed-point numbers.

.ARM
.ALIGN
.GLOBL  fastfmul

fastfmul:
  smull r1,r2,r0,r1
  mov r0,r2,LSL#16
  orr r0,r0,r1,LSR#16
  bx lr


@ int dv(int num, int den)
@ Divide two signed integers.

.THUMB
.THUMB_FUNC
.ALIGN
.GLOBL  dv

dv:
  cmp r1, #0
  beq 0f
  swi 6
  bx lr
0:
  ldr r0, =0x7fffffff
  bx lr


@ int fracmul(signed int x, signed int frac)
@ Multiply by a 0.32 fractional number between -0.5 and 0.5.
@ Used for fast division by a constant.

.ARM
.ALIGN
.GLOBL  fracmul

fracmul:
  smull r1,r2,r0,r1
  mov r0, r2
  bx lr


@ int fracumul(unsigned int x, unsigned int frac)
@ Multiply by a 0.32 fractional number between 0 and 1.
@ Used for fast division by a constant.

.ARM
.ALIGN
.GLOBL  fracumul

fracumul:
  umull r1,r2,r0,r1
  mov r0, r2
  bx lr


@ void gblz_unpack(const void *src, void *dst)
@ Unpack GB LZSS format data.

.THUMB
.THUMB_FUNC
.ALIGN
.GLOBL  _gblz_unpack

_gblz_unpack:
  swi 0x11  @ LZ77UnCompWRAM
  bx lr

Save this as something.S and then compile it with 'gcc' as if it were a C program. The 'gcc' driver will know what to do.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.