Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: TiAddict on May 31, 2011, 01:43:16 pm

Title: simple assembly question
Post by: TiAddict on May 31, 2011, 01:43:16 pm
Can someone show me a program that will count 1~1000 really fast?
i tried like this, but it wont work.
Start:
Bcall ClrScrnFull
Bcall HomeUp
Count:
ld hl,(number)
ld de,(check)
or a
push hl
sbc hl,de
ret z
pop hl
inc hl
bcall dispHL
ld (num),hl
jp count
number:
db 0
check:
db 1000
 
And the mimas gives me an "out of range" error when i try to compile. and i changed the db to dw, and it worked, but it wont count.
Please detailed explanation :D
Edit: oh yea i just noticed that when i use sbc, it will make hl equal to negative.. i dont know how to fix that.
Title: Re: simple assembly question
Post by: Ashbad on May 31, 2011, 01:49:30 pm
Code: [Select]
  LD BC,1000
@
  LD HL,BC
  B_CALL(_DispHL)
  DEC BC
  JP PE,{-1@}
@
  RET

iirc that should work decently. :)
Title: Re: simple assembly question
Post by: TiAddict on May 31, 2011, 01:53:09 pm
 :o
it gives me error that LD HL,BC is invalid.
i think i should try like this:
LD H,C
LD L,B
Title: Re: simple assembly question
Post by: Goplat on May 31, 2011, 03:01:53 pm
:o
it gives me error that LD HL,BC is invalid.
i think i should try like this:
LD H,C
LD L,B
Other way around. You want the value in B to go to H and likewise C to L, so: LD H,B and LD L,C.
Title: Re: simple assembly question
Post by: thepenguin77 on May 31, 2011, 03:09:30 pm
bcall(_dispHL) destroys HL. So store HL back into (num) before you call it. For the most part, you should usually assume that a bcall will destroy all your registers.
Title: Re: simple assembly question
Post by: TiAddict on June 01, 2011, 11:48:25 am
thank you! :D
Title: Re: simple assembly question
Post by: Quigibo on June 01, 2011, 11:16:42 pm
Code: (original) [Select]
push hl
sbc hl,de
ret z
pop hl

This could be disastrous!  If you return after you pushed hl, the top of the stack contains the number hl instead of the return address so the program will jump to some random place in memory.  You should only return after the stack is back to where it was before:

Code: (fixed) [Select]
push hl
sbc hl,de
pop hl
ret z
Title: Re: simple assembly question
Post by: TiAddict on June 02, 2011, 01:32:17 pm
oh. Thanks Quigibo :D. and can someone show me a code to convert program to sting? (program name in str0, converts to string 1)