# Day 20 - Using Divide And Sqrt

```

```

## Divide

```

Let's get straight to the point shall we? Here's some commented code:

lda r0,=20  ; r0 = 20
lda r1,=5   ; r1 = 5
swi 0x60000  ; r0 = r0/r1
; Also:
; r1 = r0 Mod (%) r1
; r2 = Abs(r0/r1)

Here's a small code file, assemble and run it:

;;--- CODE START ---;;

; we don't need any headers since we aren't going
; to make any pretty output or use any defines

@textarea 0x3000000
g @dcd 0  ; a 32bit "variable" called g.
@endarea

lda r0,=20  ; these lines of
lda r1,=5   ; code divide 20
swi 0x60000 ; by 5.

sta r0,[r3] ; store result of division (should be 4
; in g which is at 0x3000000.

infin  ; infinite loop
b infin

;;--- END OF CODE ---;;

Assemble and Run in VisualBoy Advance. Open the Memory Viewer and goto "0x3000000 - IRAM".
You should see a '4' in the first 32bits at 0x3000000. 20/5 = 4, happy now?

Sqrt

Sqrt stands for SQuare RooT if you didn't know, ;). Sqrt is function number
8. So to modify the previous code file to use Square Root, do three things:

1) Change it so it load r0 with 81.
2) Either comment "lda r1,=5" out or leave it, it doesn't matter as
r1 isn't used as input to Square Root.
3) Change "swi 0x60000" to "swi 0x80000"

Test it using the same method that I described ealier.

Day In Review

Using Divide and Sqrt are rather important as there isn't any actual Divide
or Sqrt instruction.

Go Code!,
-Mike H a.k.a GbaGuy

Intro - Day 21

```

Patater GBAGuy Mirror
Contact