0
votes
1       ORG $0020   start of RAM (data)
2   AT1 RMB 2    
3   Space   RMB 1       
4   Length  RMB 1   
5   Count   RMB 1    
6   Ptr RMB 2   
7       ORG $E000   start of ROM (program)
8   START   LDX AT1
9       STX Ptr
10      LDAA    Length
11      STAA    Count
12      LDAB    Space
13  LOOP    TST Count
14      BEQ STOP
15      LDX Ptr
16      LDAA    0,X
17      ABX 
18      STAA    0,X
19      DEC Count
20      LDX Ptr
21      INX
22      STX Ptr
23  BRA LOOP
24  STOP

1) Show a scenario if a 6-element table is copied from address 007f to 009d (you may arbitrarily enter the values of the 6 elements).

2) Revise the program so the TST Count on line 13 will not be needed. (i.e., the BEQ branch instruction on line 14 will examine the right status of program execution to determine the branch condition.)

3) Revise the program so the “Ptr RMB 2” on line 6 will not be used. Instead, Register X points to the element in Table 1, and Register Y points to the element in Table 2.

Hey All, I'm stumped on this question...For the third one, my specific question has to do with the Tables...Does X point to Space and Y point to Length? I have no clue what table is being referred to...

For the second one, does that mean that i completely remove the TST line along with the rest of the loop at line 23? What does it mean to examine the "right status" of the program?

Any help would be very nice...Thanks.

1

1 Answers

1
votes

Regarding (2): Certain instructions (including all LOAD and STORE instructions) modify the Condition Code Register (CCR) according to the result of the operation. So, if you place your conditional branch after such instructions, an explicit TST instruction becomes redundant.

Regarding (3): This is a copy routine. You're copying from a source location (beginning at $7F) to a destination location (beginning at $9D). You can think of these as arrays or tables. So, you have a source table and a destination table.

And here's a possible implementation after all modifications:

                    org       $0020               ;start of RAM (data)

;AT1                rmb       2
;Space              rmb       1
;Length             rmb       1
;Count              rmb       1

                    org       $E000               ;start of ROM (program)

Start               ldab      #6                  ;ldaa Length (affects CCR[Z] bit)
                                                  ;staa Count (affects CCR[Z] bit)
                    beq       Done                ;(only needed if length is unknown, redundant when fixed at 6)

                    ldx       #$7F                ;ldx AT1 (X is source pointer)
                    ldy       #$9D                ;ldy AT1 (Y is destination pointer)
                                                  ;ldab Space
                                                  ;aby
Loop                ldaa      ,x                  ;load source byte
                    staa      ,y                  ;save to destination
                    inx                           ;increment source pointer
                    iny                           ;increment destination pointer
                    decb                          ;dec Count (affects CCR[Z] bit)
                    bne       Loop                ;repeat until Count reaches zero

Done                bra       *                   ;spin here forever (halt)

                    org       $FFFE
                    dw        Start

[I bet next your instructor is going to ask you to convert this into a general purpose subroutine where you pass source pointer (X), destination pointer (Y), and length (B) as parameters.]