6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 1:22 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Mar 04, 2004 11:55 am 
Offline

Joined: Thu Mar 04, 2004 11:39 am
Posts: 1
hi,
i have problem with the indirect indexed adressing on a zero-page.
like i understood my documentation, the following code should work, but it don't. my problem is that i never get the value of the TAB_VEC.
what did i wrong?

i'm using the "6502 Macroassembler & Simulator" from Michal Kowalski.

in the first listfield contains the number of values to check. the routine checks if values are even or odd. if even, x-register gets increment. at the end, the value of the x-register is pushed on the stack.

+++++++++++++++++

.ORG $00

CLD
LDY #0
LDA (TAB_VEC),Y
TAY
LDX #0

LOOP CLC
LDA (TAB_VEC),Y
ROR
BCS NO_COUNT
INX

NO_COUNT: DEY
BNE LOOP
TXA
PHA

.ORG $50

TAB_VEC: .byte 8
.byte 1
.byte 2
.byte 3
.byte 4
.byte 5
.byte 6
.byte 7
.byte 8

RTS

+++++++++++++++++

thx for help, ai295


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Mar 04, 2004 12:53 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
In indirect indexed addressing the memory location in the instruction (e.g. TAB_VEC in your code) must be a zero page location where a 16 bit address is stored. The processor reads this address and adds the Y register to it to identify the actual address of the data to be accessed.

In your code TAB_VEC assembles to be the address of the start of your data table rather than the address of a zero page pointer to the data. In fact if you had written LDA TAB_VEC,Y (e.g. indexed addressing) then it would have worked.

I've adjusted to the code to make it use indirect indexed addressing and indicated a couple of other small things (like not putting the program itself on zero page). Here is the reworked source.
Code:
    .ORG $00

; TAB_VEC will be a 16 bit pointer to where the data actually
; is held

TAB_VEC .DS 2

; We'll move the code to a more reasonable starting address

    .ORG $200
   
    .START $200

    LDA #<DATA  ;Point TAB_VEC at the test data
    LDX #>DATA
    STA TAB_VEC+0
    STX TAB_VEC+1

    CLD
    LDY #0
    LDA (TAB_VEC),Y
    TAY
    LDX #0

LOOP    CLC         ;<-- Not necessary ROR will set/clear C
    LDA (TAB_VEC),Y
    ROR
    BCS NO_COUNT
    INX

NO_COUNT:
    DEY
    BNE LOOP
    TXA         ;Leave result in A
    ;PHA

    BRK     ;Stop the emulator
   
; Place the test data somewhere else in the memory

    .ORG $500

DATA:   .byte 8
    .byte 1
    .byte 2
    .byte 3     
    .byte 4
    .byte 5
    .byte 6
    .byte 7
    .byte 8

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 26 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: