Author Topic: Is it possible to execute asm within Axe/Is there a bit rotation asm program?  (Read 9843 times)

0 Members and 1 Guest are viewing this topic.

Offline SamTebbs33

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
Hi!

I would like to apply a bitwise left rotation to the each of the two bytes of a number and found that there was a command in asm that does this.

Is it possible to execute this command (RLC) from within the Axe syntax? If not, is there an asm program that I can execute to do this?

If none of the above are possible, does anyone have any knowledge of a routine that applies a left rotation to the first 8 bits ad then the last 8 bits of a two byte number?

Thanks!

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
To awnser the first part of your question:
Quote from: Readme
Asm(HEX): Native assembly code written in hexadecimal is inserted at the current position.

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Shifting left is literally *2. I can't see any point to using rotation instructions since you don't have control on the carry flag anyway.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Shifting left always inserts zeros, while rotating left inserts the same bit that was removed on the other side.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
-.- Yes, and this removed bit goes in the carry flag.
I can't see any point to using rotation instructions since you don't have control on the carry flag anyway.

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
-.- Yes, and this removed bit goes in the carry flag.
I can't see any point to using rotation instructions since you don't have control on the carry flag anyway.
Aren't you thinking of RR/RL? Those instructions are a 9-bit shift/rotate, the 9th bit being the carry flag.
The instruction mentioned in the OP is RLC, which while it does do stuff with the carry flag, it does not by any means use it for anything. It is an 8-bit rotation and the bit that leaves appears immediately on the other side.

Now, extending this idea into 16 bits is a bit ... trickier, but can be accomplished with a short ASM routine, none of which ever leaves the routine, so the whole issue about carry is moot.

Code: [Select]
;Left rotate HL circular, cheap method
 ld a,L
 add hl,hl
 rla
 ld L,a

;Right rotate HL circular

 ld a,h
 rr h
 rr L
 rra
 ld h,a
It's up to you to convert that to hex, tho.

EDIT: Problem with the first routine after the next post was posted. It should've been an RLA.
« Last Edit: January 22, 2014, 01:57:15 pm by Iambian »
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Hum actually you're right. Here's the first routine : Asm(7D291F6F) ; and the second one : Asm(7CCB1CCB1D1F67).

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
EDIT: Mat isn't here to edit his post. There was a problem in what I posted before and the converted first routine should have actually used RLA instead of RRA. The corrected routine is thus: Asm(7D29176F)

Many apologies
« Last Edit: January 22, 2014, 02:00:48 pm by Iambian »
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
I'm still not sure whether he wants each byte to be rotated independently or not. It's not really clear. Should the entire 16-bit number be rotated, or just within each byte?
« Last Edit: January 22, 2014, 02:10:42 pm by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
If individually, the answer becomes fairly trivial. That would be an RLC/RRC ... something on each byte. As a combined unit, you'll have to have a loop of RL/RR's traversing the area that needs to be rotated with the very first byte of it being saved someplace so when the loop ends, you can rotate the trailing bit into that and reload that as the first bit to simulate a complete rotation.
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
The right rotate can be simplified as:
Code: [Select]
ld a,l
rra
rr h
rr l
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline SamTebbs33

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
Thanks for the input guys. @calc84maniac Sorry for not being clear, I would like to rotate each byte left and then add them together. So for example, using 1011011010010110, I'd like to rotate 0000000010010110 (255 and 1011011010010110), then rotate 1011011000000000 (65280 and 1011011010010110) and then add them together.

Is Asm(7D291F6F) still the correct routine for a left rotation?

Since I haven't learnt about asm yet (I'm planning to), what would I input to the routine and how?

Thanks!
« Last Edit: January 22, 2014, 04:30:13 pm by SamTebbs33 »

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
The routine for a 16-bit left rotation is:Asm(7D29176F)
The routine for a 16-bit right rotation is: Asm(7D1FCB1CCB1D) (courtesy of calc84maniac)

By "add them together", do you mean the arithmetic operation "add" or the combining of the two binary strings (concatenate) ? From what you're saying, you want each to be rotated individually in the absence of each other? If that's the case, then you'll want something completely different than what we've supplied.

You'll want the individual opcodes for RLC L / RRC L / RLC H / RRC H. For further information, try looking at this opcode reference: http://www.ticalc.org/pub/text/z80/opcodes.txt

What is it that you're trying to accomplish?
« Last Edit: January 22, 2014, 04:25:21 pm by Iambian »
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline SamTebbs33

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile

By "add them together", do you mean the arithmetic operation "add" or the combining of the two binary strings (concatenate) ? From what you're saying, you want each to be rotated individually in the absence of each other? If that's the case, then you'll want something completely different than what we've supplied.

What is it that you're trying to accomplish?

Yes, that's what I would like to do I'd like to rotate the first 8 bits of the two byte number by 1 bit and then rotate the last 8 bits of the two byte number (adding zeros for the first 8 bits) and then add (+) the two rotations together.

What I'm doing is making a remake of an old game from the 80's. This game used procedural generation to generate 8 galaxies and it got the generations seeds for each one by rotating each starting seed by one bit, on the 8th rotation it would return to the fist seed, hence sending you back t the first galaxy.
For clarification, the first value of 1 of the 3 seeds is 231114 and the first rotation will set it to 46228.

I have some axe code that works on my calculator (below), but it doesn't function the same in SC3 on Cemetech.net

Code: [Select]
.A
23114->A. Seed 1
584->B.Seed 2
46931->C.Seed 3

For(E,0,8)
ClrHome
A->D
sub(ROT).D is input, W is output
W->A
B->D
sub(ROT)
W->B
C->D
sub(ROT)
W->C
Disp A>Dec,[i],B>Dec,[i],C>Dec
Pause 10400
End
Return

Lbl ROT
(D and 255)->U.Getting the first 8 bits
(D and 65280)->V.Getting the last 8 bits
(2*U) or (U/e^(7))->W
(2*V) or (V/e^(15))+W->W
Return
« Last Edit: January 23, 2014, 02:46:47 am by SamTebbs33 »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
(D and 255)->U.Getting the first 8 bits
(D and 65280)->V.Getting the last 8 bits
I fear those don't work since "and" is a 8-bit operation IIRC. To do a 16-bit operation you need the "." (which is somewhere in Catalog, not the "." you'd put between 3.14). But since you want to take the 8 first bits and the 8 last bits, you can also do {°D} and {°D+1}.

I have some axe code that works on my calculator (below), but it doesn't function the same in SC3 on Cemetech.net
That doesn't really surprise me. SC3 is pretty new and SC2 didn't support Axe. I suggest you to use TokenIDE instead.
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s