-2

I am trying to learn SPARC and trying to create an array of size 4,000 bytes. Inside of this array I need to calculate an offset to place values in the correct location in that array. I think I know how to size the array, (just use .skip?) and I know how to calculate my offset, but can anyone tell me how to place the values into the correct byte? Thanks everyone. EDIT: I originally said bits, meant to say bytes.

billatron
  • 45
  • 10

1 Answers1

0

Use read-modify-write and the proper bitwise operations (AND to clear a bit, OR to set a bit). If memory is not an issue, you could of course use one byte for each bit too.

Update: sample code illustrating how to clear a bit in the array. Setting a bit is similar, except instead of using andn it would use or.

! clear bit index %o0 in "array"
clrbit:
    mov %o0, %o1
    srl %o0, 3, %o0     ! byte offset
    and %o1, 7, %o1     ! bit offset
    set array, %o2      ! array base
    add %o2, %o0, %o0   ! byte address
    set 1, %o3          ! bit mask
    sll %o3, %o1, %o1   ! 1 << bit offset
    ldub [%o0], %o3     ! load byte
    andn %o3, %o1, %o3  ! mask off bit to clear
    stb %o3, [%o0]      ! write back
    retl
    nop

Oh, I see question has been updated to bytes instead of bits. Well, that's easier. Assuming index in %o0, data to write in %o1:

set array, %o2      ! array base address
add %o2, %o0, %o2   ! add byte offset
stb %o1, [%o2]      ! write byte
Jester
  • 56,577
  • 4
  • 81
  • 125
  • Suppose I wanted to clear data in byte 5... how would I go about this? and 5,"\n",5 gives an error... Your help is much appreciated – billatron Nov 17 '12 at 04:23