6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 14, 2024 6:56 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Rotate in figforth
PostPosted: Thu Sep 05, 2024 10:13 am 
Offline

Joined: Sat Jun 22, 2024 6:21 am
Posts: 14
I am working with figforth.
I have 12 words on the stack w1..w12. I have construct an assembly routine to rotate 4 words as a block.
( w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 FROT w5 w6 w7 w8 w9 w10 w11 w12 w1 w2 w3 w4 )
But it seems not to work, and I can't figure it out why it is not working.

Please need some help to get it running.
Thanks in advance.
Jan


Code:
ASSEMBLER HEX
CODE FROT ( F1 F2 F3 --- F2 F3 F1 )
    XSAVE STX, # 8 LDY,
    BEGIN, 0 ,X LDA, PHA, INX, DEY,
    0= UNTIL, XSAVE LDX, # 10 LDY,
    BEGIN, 8 ,X LDA, 0 ,X STA, INX,
    DEY, 0= UNTIL, XSAVE LDX, # 8 LDY,
    BEGIN, PLA, 17 ,X STA, DEX, DEY,
    0= UNTIL, XSAVE LDX, NEXT JMP,
END-CODE



Code:
                            * = $3571
3571   86 B5                STX $B5
3573   A0 08                LDY #$08
3575   B5 00      L3575     LDA $00,X
3577   48                   PHA
3578   E8                   INX
3579   88                   DEY
357A   D0 F9                BNE L3575
357C   A6 B5                LDX $B5
357E   A0 10                LDY #$10
3580   B5 08      L3580     LDA $08,X
3582   95 00                STA $00,X
3584   E8                   INX
3585   88                   DEY
3586   D0 F8                BNE L3580
3588   A6 B5                LDX $B5
358A   A0 08                LDY #$08
358C   68         L358C     PLA
358D   95 0F                STA $0F,X
358F   CA                   DEX
3590   88                   DEY
3591   D0 F9                BNE L358C
3593   A6 B5                LDX $B5
3595   4C 46 04             JMP $0446
                            .END

;auto-generated symbols and labels
 L3575      $3575
 L3580      $3580
 L358C      $358C


Top
 Profile  
Reply with quote  
 Post subject: Re: Rotate in figforth
PostPosted: Thu Sep 05, 2024 9:00 pm 
Offline

Joined: Fri Apr 15, 2016 1:03 am
Posts: 139
What goes wrong?

Maybe try a test case like:
Code:
1112 1314 1516 1718
2122 2324 2526 2728
3132 3334 3536 3738
FRot
. . . .
. . . .
. . . .


Top
 Profile  
Reply with quote  
 Post subject: Re: Rotate in figforth
PostPosted: Fri Sep 06, 2024 3:55 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
leepivonka has given you some good advice. Run a test case with easily recognizable values on stack. Then see if the result matches expectations. If not, do you see any of the recognizable values appearing elsewhere on stack than where you expected?

-- Jeff

Quote:
( w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 FROT w5 w6 w7 w8 w9 w10 w11 w12 w1 w2 w3 w4 )
ps- a further hint. Your code begins (see below) by copying w9 w10 w11 w12 to temporary storage elsewhere. Is it really w9 w10 w11 w12 that require this treatment?

Code:
CODE FROT ( F1 F2 F3 --- F2 F3 F1 )
    XSAVE STX, # 8 LDY,
    BEGIN, 0 ,X LDA, PHA, INX, DEY,
    0= UNTIL,
[...]

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
 Post subject: Re: Rotate in figforth
PostPosted: Fri Sep 06, 2024 4:27 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8540
Location: Southern California
If each FP stack cell is 8 bytes, it looks like your STA  $0F,X near the end needs to be STA  $17,X instead.

Using my structure macros, I might write it like:
Code:
    STX  $B5

       FOR_Y   8, DOWN_TO, 0   ; FOR_Y assembles LDY #8, & records branch addr.
          LDA  0,X             ; Push 8 data-stack bytes to return stack,
          PHA                  ; starting w/ lo addr of data stack, #0 to 7.
          INX                  ; (Highest addr gets pushed last.)
       NEXT_Y                  ; Because of the "DOWN_TO 0" above, NEXT_Y
                               ; will assemble DEY, BNE.

       LDX     $B5
       FOR_Y   16, DOWN_TO, 0
          LDA  8,X             ; Bring 16 data-stack bytes down by 8 bytes
          STA  0,X             ; to lower addr's, #8 to 23, down to #0 to 15.
          INX
       NEXT_Y


       LDX     $B5
       FOR_Y   8, DOWN_TO, 0
          PLA                  ; Pull 8 bytes back off return stack, and
          STA  23,X            ; put them in the range of #23 down to 16.
          DEX
       NEXT_Y

    LDX  $B5
    JMP  $0446
; -------------

However, since you apparently want 4-byte FP cells, not 8-byte ones, it would be:
Code:
    STX $B5

       FOR_Y   4, DOWN_TO, 0
          LDA  0,X             ; Push 4 data-stack bytes to return stack,
          PHA                  ; starting w/ lo addr of data stack, #0 to 3.
          INX                  ; (Highest addr gets pushed last.)
       NEXT_Y


       LDX     $B5
       FOR_Y   8, DOWN_TO, 0
          LDA  4,X             ; Bring 8 data-stack bytes down by 4 bytes
          STA  0,X             ; to lower addr's, 4 to 11, down to 0 to 7.
          INX
       NEXT_Y


       LDX     $B5
       FOR_Y   4, DOWN_TO, 0
          PLA                  ; Pull 4 bytes back off return stack, and
          STA  11,X            ; put them in the range of #11 down to 8.
          DEX
       NEXT_Y

    LDX  $B5
    JMP  $0446
; -------------

(It might still need debugging.)

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 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: