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

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: 2/
PostPosted: Sun Sep 22, 2024 1:10 pm 
Offline

Joined: Sat Jun 22, 2024 6:21 am
Posts: 14
Hello, I need a low level word to rshift one place in my figforth (6502) . This for a double
Thanks for any help.


Top
 Profile  
Reply with quote  
 Post subject: Re: 2/
PostPosted: Sun Sep 22, 2024 1:16 pm 
Offline

Joined: Sat Jun 22, 2024 6:21 am
Posts: 14
Sorry I mean d2/ as word for my figforth


Top
 Profile  
Reply with quote  
 Post subject: Re: 2/
PostPosted: Sun Sep 22, 2024 4:02 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
How about:
Code:
   LDA  1,X   ; Get highest byte and
   ASL  A     ; put high bit in C, to
   ROR  1,X   ; preserve it while moving
   ROR  0,X   ; everything else right.
   ROR  3,X
   ROR  2,X
   JMP  NEXT

_________________
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  
 Post subject: Re: 2/
PostPosted: Mon Sep 23, 2024 9:58 am 
Offline

Joined: Sat Jun 22, 2024 6:21 am
Posts: 14
Thanks, can you help me out with d2* ?

Thanks for any help


Top
 Profile  
Reply with quote  
 Post subject: Re: 2/
PostPosted: Mon Sep 23, 2024 4:57 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
powersoft_51 wrote:
Thanks, can you help me out with d2* ?

D2* is even simpler, because you don't need to preserve the sign:
Code:
   ASL  2,X
   ROL  3,X
   ROL  0,X
   ROL  1,X
   JMP  NEXT

_________________
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  
 Post subject: Re: 2/
PostPosted: Wed Sep 25, 2024 8:20 am 
Offline

Joined: Sat Jun 22, 2024 6:21 am
Posts: 14
Thanks for the code d2* and d2/.
Is it possible to do the next two words in low level 6502?

n lshift and n rshift?

Again thanks for any help

Jan.


Top
 Profile  
Reply with quote  
 Post subject: Re: 2/
PostPosted: Wed Sep 25, 2024 8:21 am 
Offline

Joined: Sat Jun 22, 2024 6:21 am
Posts: 14
I mean shifting on the standard word length.


Top
 Profile  
Reply with quote  
 Post subject: Re: 2/
PostPosted: Thu Sep 26, 2024 3:32 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
Quote:
Is it possible to do the next two words in low-level 6502?

Sure.  A tip on "low-level" though, meaning defined in assembly language instead of defined in terms of other Forth words:  The former are called "primitives," or "code definitions," whereas the latter are called "secondaries," or "colon definitions."

Code:

        HEADER "LSHIFT", NOT_IMMEDIATE          ; ( n1 n2 -- n1' )
LSHIFT: PRIMITIVE
        LDY  0,X     ; See how many bit positions we're supposed to go.
 shLb1: BEQ  shLo1   ; If the shift distance is 0, just exit without action.

 shLlp: ASL  2,X     ; Shift the low byte of the number (putting 0 in bit 0),
        ROL  3,X     ; then the high byte, bringing bit 7 into bit 8's position.
        DEY          ; Mark off one more shift done.
        BNE  shLlp   ; If there's at least 1 more shift to do, loop again.

 shLo1: JMP  POP     ; Remove one cell from the stack, and go to NEXT.
 ;---------------

        HEADER "RSHIFT", NOT_IMMEDIATE          ; ( n1 n2 -- n1' )
RSHIFT: PRIMITIVE
        LDY  0,X     ; See how many bit positions we're supposed to go.
        BEQ  shLo1   ; If the shift distance is 0, just exit without action.

 sfRlp: LSR  3,X     ; Shift the high byte of the number (putting 0 in high bit)
        ROR  2,X     ; then low byte, bringing bit 8 in to bit 7's position.
        DEY          ; Mark off one more shift done.
        BNE  sfRlp   ; If there's at least one more shift to do, loop again.

        JMP  POP     ; Remove one cell from the stack, and go to NEXT.
 ;---------------

I don't have these in my '02 Forth, only SHIFT which uses a negative number to mean shift right, so this is a translation from my '816 Forth where I have all three words.  I've been away from this for a while, so I hope I didn't make some dumb mistake.  Hopefully it's compatible with your figForth source and whatever assembler you're using, except that I'm not showing the macro definitions of HEADER and PRIMITIVE which do the dirty work of forming the header and (the less dirty work of) making the word a primitive.

_________________
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  
 Post subject: Re: 2/
PostPosted: Thu Sep 26, 2024 10:19 am 
Offline

Joined: Sat Jun 22, 2024 6:21 am
Posts: 14
Thabks for the quick help.
Have implemented it in my figforth code.
But I think the RSHIFT is not working correct.

10 2 LSHIFT . 40 OK
40 2 RSHIFT . 40 OK

I include my code.
Please can youtake a look.

Cheers,

Jan


Code:
;
; LSHIFT
;
L8800   .BYTE   $86,"LSHIF",$D4
        .WORD   L8721
LSHIFT  .WORD   LSHIFT+2
        LDY     0,X     ; See how many bit positions we're supposed to go.
shLb1:  BEQ     shLo1   ; If the shift distance is 0, just exit without action.

shLlp:  ASL     2,X     ; Shift the low byte of the number (putting 0 in bit 0),
        ROL     3,X     ; then the high byte, bringing bit 7 into bit 8's position.
        DEY             ; Mark off one more shift done.
        BNE     shLlp   ; If there's at least 1 more shift to do, loop again.
shLo1: JMP      POP     ; Remove one cell from the stack, and go to NEXT.
;
; RHIFT
;
L8900   .BYTE   $86,"RSHIF",$D4
   .WORD   L8800
RRSHIFT .WORD   RRSHIFT+1
        LDY     0,X     ; See how many bit positions we're supposed to go.
        BEQ     shLo1   ; If the shift distance is 0, just exit without action.

sfRlp:  LSR     3,X     ; Shift the high byte of the number (putting 0 in high bit)
        ROR     2,X     ; then low byte, bringing bit 8 in to bit 7's position.
        DEY             ; Mark off one more shift done.
        BNE     sfRlp   ; If there's at least one more shift to do, loop again.
        JMP     POP     ; Remove one cell from the stack, and go to NEXT.


Top
 Profile  
Reply with quote  
 Post subject: Re: 2/
PostPosted: Thu Sep 26, 2024 10:27 am 
Offline

Joined: Sat Jun 22, 2024 6:21 am
Posts: 14
Please discard last message, ther was an mistake in the code.
It is working fine.
Thanks


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

All times are UTC


Who is online

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