aboutsummaryrefslogtreecommitdiffstats
path: root/atk16_asm/builtin_asm/std_mem.atk16
blob: 4c6a45556ce5e17ea199e6aa55acb3619ca06e75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@label memset
  ; sets a specified number of words in memory to a specified value
  ; parameters:             RA = offset (offset in memory to start at)
  ;                         RB = n (number of words to set)
  ;                         RC = val (value to set the words to)
  ; returns:                void
  stack_stash RD RE
  ldi 0 RD                  ; RD := i (counter), initially 0
@label memset_loop
  subi RB RD RE             ; RE := n – i (unused value)
  bri zero memset_done      ; exit the loop

  add RA RD RE              ; RE := RA + i (address of the word to set)
  str RC RE                 ; set the word at address RE to value in RC

  inc RD                    ; i := i + 1
@label memset_done
  stack_restore RD RE
  return