aeTIos wrote:
Aha. so the result of the operation is stored to a? or am I wrong?
(Basically, ld a,0 would work too then, if I'm right)
I think that's how it works... But I'm not sure, since I haven't really written anything in Z80 asm yet.
ld a,0 is different because it doesn't touch flags. For example, to do the same thing with ld a,0, you would do
Code:
 ld a,0
 or a
xor a is faster because it is one instruction, does not require reading RAM to get the number (read: reading the instruction after $3E, which is ld), and because it is smaller in terms of code size. You should (most of the time) choose the smaller instructions for ASM stuff. For instance, or a instead of cp 0, or using the shift instructions instead of a long routine when dividing by powers of two.
Normally you don't mind trashing the flags when you zero out a, so it's smaller by one byte to do "xor a" instead of "ld a,0". Similarly, you can use "or a" instead of "cp 0" to save a byte.
I don't feel like posting this in Calcman's ASM topic (because it's his topic, not mine), so I post it here.
a few days ago, I posted some code in Calcman's topic. Here's Kerm's reply:
KermMartian wrote:
aeTIos wrote:
But my code was okay?
Not so much, sorry. :)
Code:
ld a,4
ld hl,(appbackupscreen+x)   ; x can be anything from 0 to 765 (I think)
ld l,(hl)
ld a,l
Should be something like:


Code:
ld a,4
ld (appbackupscreen+x),a

or, better:

Code:
ld a,4
ld (tankY),a
(see above about equates and such. Calcman, you generally wouldn't want to store to BASIC variable R, for example, unless you were explicitly trying to interface with BASIC code.


Of course my code was wrong. I was confused with reading and writing. The code I posted was a destroyed reading code I made a few days before I posted that.
Am I right if I say that to read, it is this code?:

Code:

ld hl, appbackupscreen+x      ;Kerm: I know that I can better use defines :P
ld l,(hl)

Can anyone confirm if this code is actually right?
Yes, that does read (appBackupScreen+x) into L. If you use A it's smaller as LD A,(appBackupScreen+x).
Thanks!
Yep, I figured out that you can also store to A.
I also have a note scrounged away in my source code in case I forget: you can replace any 8 bit register with (hl). There are a few instructions where this doesn't work, but most of the time you can rely on it. Just thought I would share Smile
That's correct, thanks for mentioning that, _player. And yes, aeTIos, you can do that, but please please please OH PLEASE use ALL of the time-saving, stress-saving tools that modern assembly programming offers you, like defining offsets of memory addresses with their own names. Smile

@JosJuice, you really should!
KermMartian wrote:
That's correct, thanks for mentioning that, _player. And yes, aeTIos, you can do that, but please please please OH PLEASE use ALL of the time-saving, stress-saving tools that modern assembly programming offers you, like defining offsets of memory addresses with their own names. Smile


At least he's not doing %1001100001110010+x?
How do you make a program not to run at full speed (like as with Pause number in Axe?
I know it has to do with Halt, but I can't get it to wait one second for example. (1 sec= ~1700 ticks, so in Axe would that be Pause 1700 (6mHz)
It has nothing to do with halt. As I answered earlier in the thread:

KermMartian wrote:
aeTIos wrote:
I have the SDK and a question: How can I make the calc running in ~15Hz mode? (Like the Axe "Full")
You use Port $20:

http://wikiti.brandonw.net/?title=83Plus:Ports:20


Code:
xor a ;same as ld a,0, but smaller
out ($20),a ;set 6MHz mode

ld a,1
out ($20),a ;set 15MHz mode
Ideally, you should make sure that's your running on a 15MHz-capable calculator first.


If you do ei \ halt, then your program will pause until the next interrupt occurs, but that's not often the best way to pause, if that's what you're trying to do.
aeTIos wrote:
How do you make a program not to run at full speed (like as with Pause number in Axe?
I know it has to do with Halt, but I can't get it to wait one second for example. (1 sec= ~1700 ticks, so in Axe would that be Pause 1700 (6mHz)


If you wan't Axe's Pause command, it actually does something like this:


Code:
    LD C,PAUSE_NUMBER
PauseLoop:
    DJNZ $
    DEC C
    JR NZ,PauseLoop


You can probably understand what it does, but a quick rundown in case:

C is initialized to PAUSE_NUMBER depending on how long you want to pause. 1 is a pause of about 1/1800 second.

DJNZ $ executes over and over until B is zero. No need to initialize B because it starts at zero by the start of the next pass anyway.

Then it decrements C and sees if it's zero. If not, go back to the DJNZ $.

That's only one way to pause the program, of course. You can literally repeat just about any command enough times to get it to pause however long you want. DJNZ $ is a good choice in Axe because it takes a long time to execute, so you can pause for a very long time with it.
Indeed, you can waste time with that, but that's generally not a good idea. CPU cycles are precious, so depending on the reason that you're pausing, you can do things during the pause, or wait for a quick-escape key (even a so-called "teacher") key, etc.
I have a question:
I have this code for moving an 'I' around on the homescreen, but it doesnt work well. what is wrong with it?

Code:

...(insert header here)
Xpos .equ AppBackUpScreen
Ypos .equ Xpos+1
ld A,0
ld (Xpos),A
ld (Ypos),A
Loop:
B_CALL _GetCSC
cp 1
Call Z,Yinc
cp 2
Call Z,Xdec
cp 3
Call Z,Xinc
cp 4
Call Z,Ydec
cp 15
jp Z,Quit
ld A,(Xpos)
ld  (CurCol),A
ld A,(Ypos)
ld (CurRow),A
ld HL,Itx
B_CALL _PutS
jp Loop
Xdec:
ld A,(Xpos)
cp 0
Call NZ,Adec
ld (Xpos),A
ret
Xinc:
ld A,(Xpos)
cp 15
Call NZ,Ainc
ld (Xpos),A
ret
Ydec:
ld A,(Ypos)
cp 0
Call NZ,Adec
ld (Ypos),A
ret
Yinc:
ld A,(Ypos)
cp 7
Call NZ,Ainc
ld (Ypos),A
ret
Adec:
Dec A
ret
Ainc:
Inc A
ret
Itx:                           ;"I text"
.db "I",0
Quit:
ret

I think that I am learning good atm, if you see those bigger codes that I write. But I think that you can optimize a bit too, can someone post optimized code with comments (please, the comments are very important for me)
Maybe your getcsc, you need sk(number)
no, sk(mnemonic) are .equ's for the getcsc codes Wink I got used to using numbers when I learned Axe so...
for example, skClear == 15.
Okay, if you are comfortable with mnemonics.
Wouldn't you use jr (or jp) instead of call? IIRC, call is for memory addresses, jr for labels in-program. Also, use XOR A instead of LD A,0.
technomonkey76 wrote:
Wouldn't you use jr (or jp) instead of call? IIRC, call is for memory addresses, jr for labels in-program. Also, use XOR A instead of LD A,0.

You can use CALL, JP, or JR in your program. CALL pushes PC to the stack, and jumps to the location that you specify. When the code at that location exits, PC is popped off the stack. CALL is used mostly for executing code as a subroutine.

Calcman, you can replace "cp 0" with "or a".
souvik1997 wrote:
technomonkey76 wrote:
Wouldn't you use jr (or jp) instead of call? IIRC, call is for memory addresses, jr for labels in-program. Also, use XOR A instead of LD A,0.

You can use CALL, JP, or JR in your program. CALL pushes PC to the stack, and jumps to the location that you specify. When the code at that location exits, PC is popped off the stack. CALL is used mostly for executing code as a subroutine.

Calcman, you can replace "cp 0" with "or a".


Ah, okay. Now, instead of using the Quit label, doesn't ret work with the z flag? And, Ainc/Adec wouldn't work, right? He'd need to set it up so that it would go back to 7 or 15 for Adec and 0 for Ainc (xor A), correct?
  
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
» Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
» View previous topic :: View next topic  
Page 2 of 8
» 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