You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

[TI-84+CE] ICE Compiler

b/Software Downloads Started by PT_, March 25, 2016, 08:14:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

u/Dream of Omnimaga May 20, 2016, 06:05:47 AM
Yeah my main worry about a non-ASM OS would be the extremely large size. :P But of course if your language is designed to work well on the CE then the size wouldn't be that bad. I think I'll stick to making games, though. :P
u/PT_ May 21, 2016, 09:23:15 AM
Hey guys, I'm struggling with a code snippet in ASM for representing the BASIC "xor". The output should in register A and is 1 if A xor B is true, and 0 if false. Of course, it's not super hard, but my code is yet 18 bytes and 80cc, and I'm 99% sure it can be shorter/faster. Can anyone give it a try? Thanks! :)

My code:
ld a, (address_A)
sub a, 1
sbc a, a
inc a
ld b, a
ld a, (address_B)
sub a, 1
sbc a, a
inc a
xor b


Note: Just one simple "xor (hl)" or so doesn't work :(
u/Dream of Omnimaga May 25, 2016, 08:07:41 PM
* DJ Omnimaga wonders if @Cumred_Snektron might be able to help since he's also working on a language? I can't help, though
u/Snektron May 26, 2016, 12:30:46 AM
@PT_  what about

ld a, (Address_A)
cp (Address_B)
ld a, 0
jp nz, _
inc a
_:
u/JWinslow23 May 26, 2016, 03:13:51 AM
I know nothing about z80 asm, but can't you just do an xor, but convert a nonzero output to 1? Like maybe:

Load (HL) with (A xor B)
Is (HL) != 0 ?
If so, then Load (HL) with 1
Return (HL)


That's just pseudocode (I don't know asm), but I'm thinking that should work.
u/MateoConLechuga May 26, 2016, 04:42:43 AM
The best that I can do is by having varB directly after varA, saving 2 bytes.

ld hl,varA
ld a, (hl)
sub a,1
sbc a,a
inc hl
ld b,a
ld a, (hl)
add a,-1
sbc a,a
xor a,b
inc a
Last Edit: May 26, 2016, 04:53:49 AM by MateoConLechuga
u/PT_ May 26, 2016, 07:12:16 AM
My answer to all of you is no ;) For Cumred and Ivoah: what if A=1 and B=2? Xor would give 3 which is false. Mateo: A and B was only as an example, it can be any variable I (the user) want. It is useful though in some cases.
Last Edit: May 26, 2016, 07:14:27 AM by PT_
u/Snektron May 26, 2016, 07:25:00 AM
If A = 1 and B = 2 woul;d give you


ld a, (Address_A)
cp (Address_B) ; 1 - 2 = -1, so nz
ld a, 0
jp nz, _
inc a     ; set a to 1
_:
; outcome: a = 1


Is that not what you want? else im not entirely sure what you want
u/PT_ May 26, 2016, 08:05:08 AM
In your case: what if both A and B are 1? Then cp a, b will be zero, en thus (according to you) the outcome is 1, while it should be 0.  But if A and B > 0 but not equal, the output is 0, which is right. So your code fails if A=B
u/Snektron May 26, 2016, 08:14:57 AM
Eh, i think i used the wrong flag, jp nz, _  should be jp z, _. (It was late yesterday)
now if A != B cp 0 will reset z (so nz) and it will not jump past inc a, so the end result is 1 in a. If A == B then cp 0 will set Z, jumping past inc and the outcome would be a = 0.
u/JWinslow23 May 27, 2016, 01:47:32 AM
Quote from: PT_ on May 26, 2016, 07:12:16 AM
My answer to all of you is no ;) For Cumred and Ivoah: what if A=1 and B=2? Xor would give 3 which is false. Mateo: A and B was only as an example, it can be any variable I (the user) want. It is useful though in some cases.
Well, then can't you just turn each input into a 1 or 0 and do it like that? Like (pseudocode):
Is A != 0?
If so, then load A with 1
Is B != 0?
If so, then load B with 1
Load (HL) with (A xor B)
Return (HL)
Last Edit: May 27, 2016, 01:49:05 AM by JWinslow23
u/MateoConLechuga May 27, 2016, 03:11:31 AM
Quote from: PT_ on May 26, 2016, 07:12:16 AM
My answer to all of you is no ;) For Cumred and Ivoah: what if A=1 and B=2? Xor would give 3 which is false. Mateo: A and B was only as an example, it can be any variable I (the user) want. It is useful though in some cases.
Well, fine, the best I can save is just 1 byte then :P

ld a, (varA)
sub a,1
sbc a,a
ld b,a
ld a, (varB)
add a,-1
sbc a,a
xor a,b
inc a
u/Snektron May 27, 2016, 08:52:44 AM
I think you can save another one by replacing add a, -1 with dec a ;)
Unless that add is intended to set the carry flag at the same time which it probably is
u/PT_ May 28, 2016, 08:29:16 AM
I'm very happy to say that parsing a mathematical expression is almost done! :)
It now 'chains' operators, i.e. A*B+3, instead of the seperate routines for A*B and A+3 for example. Out of the 14 booleans/operators (+ - * / or xor and -> => <= > < = !=) I've finished 10. I only need >= <= > < to do, and after that, I'm ready with parsing such string (yet without functions). I haven't implemented auto-opt yet, but I will definitely do. Here is an example of what it can do:
String = A+4*B/(1-C)+3
Output = ld a, ($D05301)    ; B
add a, a
add a, a
push af
ld a, 1
ld hl, $D05302  ; C
sub a, (hl)
pop hl
ld l, 1
mlt hl
call _DivHLByA
ld a, l
ld hl, $D05300     ; A
add a, (hl)
add a, 3
ret
The only good optimization I see is replacing the "push af" with "ld h, a" and remove the "pop hl".
u/MateoConLechuga May 28, 2016, 09:11:27 PM
Quote from: PT_ on May 28, 2016, 08:29:16 AM
I'm very happy to say that parsing a mathematical expression is almost done! :)
It now 'chains' operators, i.e. A*B+3, instead of the seperate routines for A*B and A+3 for example. Out of the 14 booleans/operators (+ - * / or xor and -> => <= > < = !=) I've finished 10. I only need >= <= > < to do, and after that, I'm ready with parsing such string (yet without functions). I haven't implemented auto-opt yet, but I will definitely do. Here is an example of what it can do:
String = A+4*B/(1-C)+3
Output = ld a, ($D05301)    ; B
add a, a
add a, a
push af
ld a, 1
ld hl, $D05302  ; C
sub a, (hl)
pop hl
ld l, 1
mlt hl
call _DivHLByA
ld a, l
ld hl, $D05300     ; A
add a, (hl)
add a, 3
ret
The only good optimization I see is replacing the "push af" with "ld h, a" and remove the "pop hl".

ld ix,$D05300
ld a,(ix+1)    ; B
add a, a
add a, a
sbc hl,hl
ld l,a
ld a,1
sub a,(ix+2) ; C
call _Div16By8 ; this changed names in the latest equate file
ld a, l
add a,(ix) ; A
add a,3
ret

Optimized by using an offset pointer sort of like a stack frame used in C. Probably not applicable, but meh, it's an idea.
Last Edit: May 28, 2016, 09:15:29 PM by MateoConLechuga
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal