I'm learning to program in Assembly in hex on calc. It all makes sense, with an exception. the djnz command (its hex code is 10). djnz loads the B register in hex, and my question is, how do you loop backward in the program?

in basic suedo code,
x = 1
b = 2
x + 1
display x
djnz -2

This would add one to x, display x, move back (because of the negative) two rows, decrement B- and go again, and stopping when b = 0

I hope I'm explaining this thoroughly enough, but my basic question, how can I display a negative for djnz? I read something about a signed hexadecimal, but what exactly is that?

Thank you in advance,
Blackhawk
What do you mean you're learning to program assembly in hex? Assembly instructions are mnemonics for machine code in order to make it more human readable. Hexadecimal opcodes are not that in shape or form.

Please also refrain from typing words with arbitrary capitalization. "hex" is neither an acronym nor a proper noun. Similarly, "assembly" is not a proper noun in this context, and "for" is also not an acronym.

If you want to understand negative number representation, you should read up on two's complement.
Elf prince,

Im looking at two's complement stuff now and I think this is the right track! Thank you!

(And to clarify a bit, programming z-80 assembly on the calculator by using the hexedicemal equivalents of each of command... A quick intro: http://m.youtube.com/watch?v=LGdl4cwZ6iw
I wouldn't recommend that. You can write assembly "normally" (ie, with opcode mnemonics, comments, labels, and all that good stuff) on-calculator with the Mimas assembler. If you have access to a computer, you're even better off using an assembler like Brass and an emulator like jsTIfied or PindurTI or WabbitEmu so that you can sanely debug.
And when you don't have a cable (100% of the TI-82 stats come with no cable), you can only do hex if you want to move from TI-Basic.
Bingo! I don't have a cable, for one- (I ordered one of amazon for a penny, but I'm impatient :p)

I also like the portability, Being able to pick up my friend's calc and make the cursor disappear in 6 lines of code.

Its alot of memorizing, but Its not horrific for someone with plenty of time!

However I do write on WabbitEmu, to make sure stuff works and doesn't crash.
The jump that DJNZ performs is a relative jump, like the JR instructions. Jumping forward, as you may have found is easy to compute, but remember it can only jump up to 7F bytes forward. Jumping back one byte would be 10FF, but that jumps to the "FF". 10FE jumps back to the "10". An example routine using DJNZ would be:

Code:

16006A0608
2930011910FA
C9

The first line sets register D to 0, stores D to L (so L is now 0) and sets B=8. Then the loop "add hl,hl" then 3001 is a relative jump forward 1 byte (skipping the 19) if the c flag is reset (nc). Then the 10FA jumps back to the 29.

That routine multiplies H times E storing back to HL.
EDIT:
Also, something that I find useful when computing addresses and jumps is the fact that 16 characters fit on a line in the OS program editor. This means two full lines is 10h bytes, which is easy to add to an address.
THANK YOU XEDA!!! YOU ARE A TRUE SCHOLAR AMONGST US TO HAVE FIGURED THAT OUT!!!! SAINT AMONG MEN!


Extremely thankful,
Blackhawk
Haha, thanks Razz I started assembly with programming in hex (and as much as others might not like the programming slang, it is a lot easier to just say hex and few programmers are going to assume you are referring to base 6). I also have been trying to add a bunch to Z80 Heaven, so I am glad that it is being useful to you!
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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 vote in polls in this forum

 

Advertisement