Danjovic Posted March 30, 2022 Share Posted March 30, 2022 (edited) This function will set a bit within an array of elements, from msbit to lsbit. Examples: ; array = 00 00 00 00 00 00 00 ... ; ; a = 0 ; after run... ; array = 80 00 00 00 00 00 00 ... ; ; again, now with a = 1 ; after run... ; array = c0 00 00 00 00 00 00 ... ; ; again, now with a = 8 ; after run... ; array = c0 80 00 00 00 00 00 ... ; ; again, now with a = 7 ; after run... ; array = c1 80 00 00 00 00 00 ... ; Here's the code: define _a $d7 ; address of first element of array lda #8 ; nth bit of array elements setnthbit: ldx #0 a1: sec ; divide by 8, x = quocient, a = reminder-8 sbc #8 bcc a2 inx jmp a1 a2: clc ; rotate the mask 'a' times adc #9 ; 8 + 1 due to compensate first dey tay ; y is the counter used to rotate the mask lda #$80 ; mask = 1000.0000 a3: dey ; mask rotate loop beq a4 lsr jmp a3 a4: ora _a,x ; set the nth bit sta _a,x rts Edited March 30, 2022 by Danjovic corrected instruction (bcc a2 instead of bmi a2) 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.