Re: LZ: Basics


[Prev][Next][Index][Thread]

Re: LZ: Basics



At 12:34 12/21/96 -0400, you wrote:
>OK, I am kind of new at this programming zshell stuff.  I have a basic
>question.  Lets say that I was trying to write a program that would ask
>the user for two numbers and then it would add them.  My question is how
>do I input the numbers to be added?
>
>Thanks,
>Dennis
>
This is the way I would do it:

Loop:
        call GET_KEY            ;Key code of last key pressed
        cp $21                  ;compare is with keycode of zerokey
        JUMP_Z(ZeroKey)         ;jump to ZeroKey if equal
        cp $22                  
        JUMP_Z(OneKey)
        cp $1A
        JUMP_Z(TwoKey)
        cp $12
        JUMP_Z(ThreeKey)
        cp $23
        JUMP_Z(FourKey)
        cp $1B
        JUMP_Z(FiveKey)
        cp $13
        JUMP_Z(SixKey)
        cp $24
        JUMP_Z(SevenKey)
        cp $1C
        JUMP_Z(EightKey)
        cp $14
        JUMP_Z(NineKey)
        cp $09
        JUMP_Z(Add)
        JUMP_(Loop)

ZeroKey:
        ld a,0                  ;load zero into a
        push af                 ;push a onto stack
        JUMP_(Loop)
OneKey:
        ld a,1
        push af
        JUMP_(Loop)
TwoKey:
        ld a,2
        push af
        JUMP_(Loop)
ThreeKey:
        ld a,3
        push af
        JUMP_(Loop)
FourKey:
        ld a,4
        push af
        JUMP_(Loop)
FiveKey:
        ld a,5
        push af
        JUMP_(Loop)
SixKey:
        ld a,6
        push af
        JUMP_(Loop)
SevenKey:
        ld a,7
        push af
        JUMP_(Loop)
EightKey:
        ld a,8
        push af
        JUMP_(Loop)
NineKey:
        ld a,9
        push af
        JUMP_(Loop)
Add:
        pop af                  ;Get first number from stack
        pop bc                  ;Get second number from stack
        add a,b                 ;add them

This isn't complete, but I think it shows the basic way to input.  I'm not
sure if this is the best way it can be done, but I hope it helps.
Nathan Adams
nathana@goodnet.com
"It is better to remain silent and be thought a fool,
than to speak out and remove all doubt."


Follow-Ups: