Author Topic: simple assembly question  (Read 2887 times)

0 Members and 1 Guest are viewing this topic.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
simple assembly question
« 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.
« Last Edit: May 31, 2011, 01:47:30 pm by TiAddict »

Ashbad

  • Guest
Re: simple assembly question
« Reply #1 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. :)

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: simple assembly question
« Reply #2 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
« Last Edit: May 31, 2011, 01:55:04 pm by TiAddict »

Offline Goplat

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 289
  • Rating: +82/-0
    • View Profile
Re: simple assembly question
« Reply #3 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.
« Last Edit: May 31, 2011, 03:02:16 pm by Goplat »
Numquam te deseram; numquam te deficiam; numquam circa curram et te desolabo
Numquam te plorare faciam; numquam valedicam; numquam mendacium dicam et te vulnerabo

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: simple assembly question
« Reply #4 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.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: simple assembly question
« Reply #5 on: June 01, 2011, 11:48:25 am »
thank you! :D

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: simple assembly question
« Reply #6 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
« Last Edit: June 01, 2011, 11:17:48 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: simple assembly question
« Reply #7 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)