Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: squidgetx on November 08, 2010, 03:30:55 pm

Title: Writing to bits
Post by: squidgetx on November 08, 2010, 03:30:55 pm
Whats the smallest way of writing bits? (I don't care if it's Axe or Asm(HEX) type of thing)

So far the only thing I've come up with is
Code: [Select]
{Pointer}±e^(7-Bit#)→{Pointer}Use + for writing 1 to the bit, or - for writing 0 to the bit. The only problem is that writing 0 or 1 to a bit that already contains 0 or 1 respectively, will mess everything up.

Does anyone have any ideas?
Title: Re: Writing to bits
Post by: nemo on November 08, 2010, 03:35:56 pm
{Pointer} xor %0000 0100

will write the third bit to one. just replace the 1 with whichever bit you're trying to write, and convert the binary into a decmal number. remember, if you're writing a bit to a two-byte area, you need to use the plot-style token instead of xor.
Title: Re: Writing to bits
Post by: Hot_Dog on November 08, 2010, 03:38:53 pm
{Pointer} xor %0000 0100

will write the third bit to one. just replace the 1 with whichever bit you're trying to write, and convert the binary into a decmal number. remember, if you're writing a bit to a two-byte area, you need to use the plot-style token instead of xor.

Actually, xor will flip the 3rd bit back and forth.  If the 3rd bit equals zero, xor will make the 3rd bit equal to 1.  If it's 1, xor will make the 3rd bit equal to zero.

Try using {Pointer} and %11111011 to make the 3rd bit equal to zero, for example.  Try using {Pointer} or %00000100 to make the 3rd bit equal to one.
Title: Re: Writing to bits
Post by: squidgetx on November 08, 2010, 03:41:04 pm
Thanks both of you!

This makes things a lot easier
Title: Re: Writing to bits
Post by: nemo on November 08, 2010, 03:42:01 pm
{Pointer} xor %0000 0100

will write the third bit to one. just replace the 1 with whichever bit you're trying to write, and convert the binary into a decmal number. remember, if you're writing a bit to a two-byte area, you need to use the plot-style token instead of xor.

Actually, xor will flip the 3rd bit back and forth.  If the 3rd bit equals zero, xor will make the 3rd bit equal to 1.  If it's 1, xor will make the 3rd bit equal to zero.

Try using {Pointer} and %11111011 to make the 3rd bit equal to zero, for example.  Try using {Pointer} or %00000100 to make the 3rd bit equal to one.


oops. i forgot about that. of course, or will work too.
Title: Re: Writing to bits
Post by: Hot_Dog on November 08, 2010, 03:44:03 pm
Out of curosity, are you wanting to make a particular bit one or zero, or does the bit you want to edit change every time that section of code executes?
Title: Re: Writing to bits
Post by: Runer112 on November 08, 2010, 03:47:58 pm
General form: {Pointer}Asm(CBXX)→{Pointer}, where XX is a byte from the following table. In this table, I call bit 0 the least significant bit and bit 7 the most significant bit.

RESET   SET
BIT 0     85C5
BIT 18DCD
BIT 295D5
BIT 39DDD
BIT 4A5E5
BIT 5ADED
BIT 6B5F5
BIT 7BDFD
Title: Re: Writing to bits
Post by: squidgetx on November 08, 2010, 03:51:15 pm
Runer: Thanks, but I need a routine that will take the pointer and bit # as arguments, so I think Hot_Dog's {Pointer} or %00000100 will be sufficient :)

Hot_Dog; I'm using the bits as flags to show whether the player has completed a certain task or not, so I guess they need to be constant.

So I'm going to go with, if you were going to write it as a subroutine with r1 being the pointer and r2 being the bit number (in Axe's way, with 0 being the most significant), the best way to do this is {r1} or e^(7-r2)→{r1}

Or is it more efficient to write it out every time? (no subroutine calling) just tested it, I think subroutine is better (9 bytes per call I think) and I think the code is ~41 bytes
Title: Re: Writing to bits
Post by: Runer112 on November 08, 2010, 05:45:48 pm
Here's the most optimized way, using standard subroutine calls, to either set or reset a bit of a pointed to byte, with bit 0 being the most significant bit. Input would be in the form of sub(SET/RES,bit,pointer).

Code: [Select]
Lbl SET
{} or sub(BIT)
Lbl SR2
→{r₂}
Return
Lbl RES
{} and (sub(BIT) xor ᴇFF)
Goto SR2
Lbl BIT
e^(7-r₁)
Return
Title: Re: Writing to bits
Post by: squidgetx on November 08, 2010, 05:48:42 pm
Oh cool, thanks. So I'm guessing that the lack of an argument inside the {} is because it is taking HL as its argument, which is 'pointer' because when you store pointer to r2 it is stored to HL....like ans....kk i'm learning XD

Does every Axe operation leave stuff in HL?
Title: Re: Writing to bits
Post by: Runer112 on November 08, 2010, 05:52:55 pm
Oh cool, thanks. So I'm guessing that the lack of an argument inside the {} is because it is taking HL as its argument, which is 'pointer' because when you store pointer to r2 it is stored to HL....like ans....kk i'm learning XD

Does every Axe operation leave stuff in HL?

Every loading or mathematical operation will put the result in hl. As I mentioned to someone a while ago in a different thread, the hl register is like the "Ans of Axe." All loading operations put the value into hl, and all mathematical operations put the operands into hl and de, calculate, and put the result back into hl. The nice thing about this method is that complex strings of operations can be handled easily. If parentheses or curly brackets are reached, the current value of hl can just be pushed onto the stack for later, and any operations in the parentheses or curly brackets can then be handled using hl. Every time the "depth" of the operation is increased, hl just needs to be pushed, and every time the "depth" decreases, hl can be popped right back.

Note: Just in case anyone reading this doesn't know what pushing and popping are, they are methods of saving and restoring data (respectively). Pushing loads a value onto the top of a stack of values, like a stack of physical objects. Popping takes the top value on the stack and retrieves that. Using this method, you can push multiple values onto the stack and retrieve them in the opposite order that you put them there, allowing things like parentheses to be handled very well. It's explained quite well here (http://future_history.freehostia.com/Files/Resources/ASM/ASMin28Days/lesson/day06.html).
Title: Re: Writing to bits
Post by: DJ Omnimaga on November 09, 2010, 01:48:42 am
Thanks for explaining push/pop. I always wondered what it did, but knew it involved the stack. That might help me a bit when learning ASM.
Title: Re: Writing to bits
Post by: Binder News on November 09, 2010, 03:00:42 pm
Wait!? DJ, you don't know ASM!?!? I've only been at it 2 weeks and I have almost completely remade Hexpipc (again, but this time it's only 500 bytes). Seriously though, I thought you (being the founder of this forum) would know ASM.
Title: Re: Writing to bits
Post by: Builderboy on November 09, 2010, 03:38:54 pm
I think the language you know doesn't have any relation to how well you program or how fun you can make your games :) In fact many of the other Admins have little or no asm experience (myself included) and yet ive seen them make incredible games as well ^^
Title: Re: Writing to bits
Post by: ztrumpet on November 09, 2010, 03:45:13 pm
Wait!? DJ, you don't know ASM!?!? I've only been at it 2 weeks and I have almost completely remade Hexpipc (again, but this time it's only 500 bytes). Seriously though, I thought you (being the founder of this forum) would know ASM.
Let's see, the Admins experience in calc languages (from what I've noticed):
Builderboy: Basic - Excellent   Axe - Excellent   Asm - Beginner
DJ Omnimaga: Basic - Excellent   Axe - Medium   Asm - Beginner
Eeems: Basic - Medium   Axe - Medium   Asm - Medium
Hot_Dog: Basic - Medium   Axe - Beginner   Asm - Excellent
ztrumpet: Basic - Excellent   Axe - Excellent   Asm - Beginner

As you can see, not all of the admins know all the languages. :)
Title: Re: Writing to bits
Post by: DJ Omnimaga on November 09, 2010, 05:20:45 pm
Wait!? DJ, you don't know ASM!?!? I've only been at it 2 weeks and I have almost completely remade Hexpipc (again, but this time it's only 500 bytes). Seriously though, I thought you (being the founder of this forum) would know ASM.
ASM is a totally different matter than BASIC. I coded BASIC for 9 years and Axe for 6 months. I attempted ASM 3 times, so far, with ASM in 28 days, to no avail. The way the tutorial is written is just not for me. I am planning a 4th attempt with Hot Dog's tutorials, though, now that I learned some memory stuff with Axe.

Also being founder of a forum doesn't mean I automatically know every language. Omnimaga started solely as a TI-BASIC group, after all. Axe just arrived later, and many people switched. Then came Hot Dog's tutorials, which made it easier for people to learn ASM. I think most ticalc.org staff barely programmed at all.
Title: Re: Writing to bits
Post by: Binder News on November 13, 2010, 09:47:54 pm
Okay. I just always got the impression that you knew ASM. By the way, where can I find Hot Dog's tutorials (link please)? As a side question, what programming languages do you know (calc or otherwise)?
Title: Re: Writing to bits
Post by: DJ Omnimaga on November 14, 2010, 04:31:38 am
Yeah I actually started TI-BASIC around 2001 and stuck with it until 2009 then moved to Axe. I just never could understand ASM. Hopefully maybe Hot Dog's tutorials will change that, though.

Here are his tutorials, by the way: http://www.omnimaga.org/index.php?action=downloads;sa=view;down=594

As for myself, I know TI-BASIC for the TI-81 and 83+ (I did a bit for other calcs but not much) and Axe language. I did VB6 in 2002-03 but I pretty much forgot the few things I learned. That's pretty much it. I was active a lot in BASIC programming around 2001-05 then I coded on and off afterward, while running Omnimaga.
Title: Re: Writing to bits
Post by: Binder News on November 15, 2010, 09:34:27 pm
Interesting. I do GNU C++, Java, BASIC, Axe, GML, and some ASM.