I'm trying out some 6502 assembly language, specifically using Kick Assembler. I have the following routine that just sticks a character on the text screen at a specified x and y, it's taken from the Kick Assembler help topic that illustrates the use of the .lohifill directive for creating tables. What I'm not clear about is the ORA #$04... why are we doing that?

(note charx = 10 and chary = 5 here, comments are mine and not from the help file)


    ldx charx        
    ldy chary
    lda mul40.lo,x  // Access lo byte table
    sta $fe         // second last byte of zero page (unused)
    lda mul40.hi,x  // Access hi byte table
    ora #$04        // hunh?
    sta $ff         // last byte of zero page (unused)
    lda #'x'

    sta ($fe),y     // Draws 'x' at screenpos x,y
                    // Zero Page Indirect Y-Indexed 
                    // $fe = $20
                    // $ff = $07
                    // y = $0f
                    // $20 + $0f = $2f, so lsb of effective address is $2f and carry flag is not set
                    // $07 + $0 (carry flag) = $07 being msb of effective address.
                    // so effective address is $072f which is near bottom of text screen

mul40: .lohifill $100, 40*i    // Generates lo/hi table: 
                               // .byte <0, <40, <80, <120, ....
                               // .byte >0, >40, >80, >120, ....
  • 1
    This code looks like it uses X for the vertical coordinate and Y for the horizontal one… Commented Oct 31, 2023 at 14:03

1 Answer 1


C64 screen memory by default begins at $0400. The ORA #$04 ensures that you are treating location (0, 0) as address $0400, treating the location one to the right of that as $0401, etc.

It has the same effect as performing + $0400 on the computed address because:

  • It's being applied to the high byte.
  • The rest of the computed address is less than $0400 and you can therefore observe that no carry will be generated during the addition.
  • 18
    It may be worth noting that adding 4 to the high byte of the address would require ensuring that the carry flag is clear, but ORA has no such requirement.
    – supercat
    Commented Oct 31, 2023 at 19:34
  • Also presumably for the sole purpose of updating the screen memory the tables only need to handle 25 rows, so mul40: .lohifill $19, 40*i
    – Alan B
    Commented Nov 2, 2023 at 12:15
  • 1
    @supercat Well, there is a clc in the code Commented Nov 4, 2023 at 13:43
  • @HagenvonEitzen: Perhaps the code was originally with ADC, and someone recognized that the code could be optimized to use ORA so as to eliminate the need for the CLC, but nobody actually removed the CLC.
    – supercat
    Commented Nov 4, 2023 at 22:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .