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

0 Members and 1 Guest are viewing this topic.

#### SamTebbs33

• LV1 Newcomer (Next: 20)
• Posts: 16
• Rating: +0/-0
##### Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« on: January 22, 2014, 11:51:59 am »
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!

#### Sorunome

• Fox Fox Fox Fox Fox Fox Fox!
• Support Staff
• LV13 Extreme Addict (Next: 9001)
• Posts: 7918
• Rating: +374/-13
• Derpy Hooves
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #1 on: January 22, 2014, 11:54:03 am »
To awnser the first part of your question:
Asm(HEX): Native assembly code written in hexadecimal is inserted at the current position.
 THE GAMEAlso, check out my websiteIf OmnomIRC is screwed up, blame me!Click here to give me an internet!

#### Matrefeytontias

• Axe roxxor (kinda)
• LV10 31337 u53r (Next: 2000)
• Posts: 1982
• Rating: +310/-12
• Axe roxxor
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #2 on: January 22, 2014, 01:17:14 pm »
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.

#### fb39ca4

• LV10 31337 u53r (Next: 2000)
• Posts: 1749
• Rating: +60/-3
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #3 on: January 22, 2014, 01:40:54 pm »
Shifting left always inserts zeros, while rotating left inserts the same bit that was removed on the other side.

#### Matrefeytontias

• Axe roxxor (kinda)
• LV10 31337 u53r (Next: 2000)
• Posts: 1982
• Rating: +310/-12
• Axe roxxor
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #4 on: January 22, 2014, 01:42:05 pm »
-.- 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.

#### Iambian

• Coder Of Tomorrow
• Posts: 739
• Rating: +216/-3
• Cherry Flavoured Nommer of Fishies
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #5 on: January 22, 2014, 01:51:46 pm »
-.- 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,aIt'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? ...

#### Matrefeytontias

• Axe roxxor (kinda)
• LV10 31337 u53r (Next: 2000)
• Posts: 1982
• Rating: +310/-12
• Axe roxxor
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #6 on: January 22, 2014, 01:54:09 pm »
Hum actually you're right. Here's the first routine : Asm(7D291F6F) ; and the second one : Asm(7CCB1CCB1D1F67).

#### Iambian

• Coder Of Tomorrow
• Posts: 739
• Rating: +216/-3
• Cherry Flavoured Nommer of Fishies
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #7 on: January 22, 2014, 01:59:58 pm »
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? ...

#### calc84maniac

• eZ80 Guru
• Coder Of Tomorrow
• LV11 Super Veteran (Next: 3000)
• Posts: 2898
• Rating: +467/-17
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #8 on: January 22, 2014, 02:10:31 pm »
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

#### Iambian

• Coder Of Tomorrow
• Posts: 739
• Rating: +216/-3
• Cherry Flavoured Nommer of Fishies
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #9 on: January 22, 2014, 02:13:19 pm »
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? ...

#### calc84maniac

• eZ80 Guru
• Coder Of Tomorrow
• LV11 Super Veteran (Next: 3000)
• Posts: 2898
• Rating: +467/-17
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #10 on: January 22, 2014, 02:15:47 pm »
The right rotate can be simplified as:
Code: [Select]
ld a,lrrarr hrr l
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

#### SamTebbs33

• LV1 Newcomer (Next: 20)
• Posts: 16
• Rating: +0/-0
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #11 on: January 22, 2014, 04:10:32 pm »
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 »

#### Iambian

• Coder Of Tomorrow
• Posts: 739
• Rating: +216/-3
• Cherry Flavoured Nommer of Fishies
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #12 on: January 22, 2014, 04:22:20 pm »
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? ...

#### SamTebbs33

• LV1 Newcomer (Next: 20)
• Posts: 16
• Rating: +0/-0
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #13 on: January 23, 2014, 02:45:52 am »

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]
.A23114->A. Seed 1584->B.Seed 246931->C.Seed 3For(E,0,8)ClrHomeA->Dsub(ROT).D is input, W is outputW->AB->Dsub(ROT)W->BC->Dsub(ROT)W->CDisp A>Dec,[i],B>Dec,[i],C>DecPause 10400EndReturnLbl 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->WReturn
« Last Edit: January 23, 2014, 02:46:47 am by SamTebbs33 »

#### Hayleia

• Programming Absol
• Coder Of Tomorrow
• LV12 Extreme Poster (Next: 5000)
• Posts: 3367
• Rating: +393/-7
##### Re: Is it possible to execute asm within Axe/Is there a bit rotation asm program?
« Reply #14 on: January 23, 2014, 10:16:18 am »
(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.